php composer.json脚本,返回'事件返回错误代码2',为什么?[已关闭]

cyvaqqii  于 2023-02-07  发布在  PHP
关注(0)|答案(1)|浏览(130)

12个月前关闭。
Improve this question
我正在学习 composer ,当创建这个脚本,它返回'事件返回错误代码2'。虽然脚本执行正确,解析正确,结果是预期的,我仍然得到一个延迟和错误代码有关的脚本。什么可能导致它,我应该如何修复它?

//src

 <?php

    echo 'hello world';

 ?>
//composer.json
    "require-dev": {
        "phpunit/phpunit": "^9.5",
        "squizlabs/php_codesniffer": "^3.6",
        "phan/phan": "^5.3"
    },
    "scripts": {
        "cs" : "phpcs --standard=PSR12 src/"
    },
//running

PS D:\xamp\htdocs\fonts\ambiente\buscador-cursos-alura> composer cs       
> phpcs --standard=PSR12 src/

FILE: ...:\xamp\htdocs\fonts\ambiente\buscador-cursos-alura\src\teste.php
----------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 1 | ERROR | [x] End of line character is invalid; expected "\n" but
   |       |     found "\r\n"
 5 | ERROR | [x] Expected 1 newline at end of file; 0 found
 5 | ERROR | [x] A closing tag is not permitted at the end of a PHP
   |       |     file
----------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 102ms; Memory: 8MB

Script phpcs --standard=PSR12 src/ handling the cs event returned with error code 2
crcmnpdw

crcmnpdw1#

第一次警告

End of line character is invalid; expected "\n" but found "\r\n"
你的行尾应该是LF而不是CRLF,这里有一篇文章解释了这两者的区别。如果你使用VSCode,你可以改变右下角的行尾,默认情况下它使用CRLF。如果你不使用VSCode,你需要谷歌一下如何改变你的IDE的行尾。

第二次警告

Expected 1 newline at end of file; 0 found
PSR12编码标准要求在PHP文件的末尾有一个空行。

第三次警告

A closing tag is not permitted at the end of a PHP file
PSR12编码标准规定,应该省略文件末尾的PHP结束标记。

<?php
    echo 'hello world';

相关问题