Skip to content

--no-patch option returns error code 1 on composer script #1270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gmponos opened this issue Jan 13, 2017 · 5 comments
Closed

--no-patch option returns error code 1 on composer script #1270

gmponos opened this issue Jan 13, 2017 · 5 comments

Comments

@gmponos
Copy link
Contributor

gmponos commented Jan 13, 2017

Inside my composer I have added the following command/script

{
...
    "scripts": {
        "phpcbf": [
            "php vendor/bin/phpcbf mypath1 --standard=ruleset1.xml --extensions=php --no-patch",
            "php vendor/bin/phpcbf mypath2 --standard=ruleset2.xml --extensions=php --no-patch"
        ],
    }
...
}

When I execute

composer phpcbf I get

Script php vendor/bin/phpcbf mypath1 --standard=ruleset1.xml --extensions=php --no-patch handling the phpcbf event returned with error code 1

As a result the second script is never executed. If I remove the --no-patch option the second script is executed.

Version: 2.7.1

@gmponos gmponos changed the title --no-patch option returns status code 1 on composer script --no-patch option returns error code 1 on composer script Jan 13, 2017
@aik099
Copy link
Contributor

aik099 commented Jan 13, 2017

According to #666 you need to add --runtime-set ignore_warnings_on_exit 1 to when running phpcbf and then it will always return 0.

If I'm not mistaken the error code tells, that something was fixed.

@gmponos gmponos closed this as completed Jan 13, 2017
@gmponos
Copy link
Contributor Author

gmponos commented Jan 13, 2017

Sorry I closed it without testing it.
The problem continues.

Script php vendor/bin/phpcbf path --standard=ruleset1.xml --extensions=php --no-patch --runtime-set ignore_warnings_on_exit 1 handling the phpcbf event returned with error code 1

@gmponos gmponos reopened this Jan 13, 2017
@gmponos
Copy link
Contributor Author

gmponos commented Jan 13, 2017

Furthermore no file is fixed.

@gsherwood
Copy link
Member

When using the --no-patch option, PHPCS doesn't know if any errors were actually fixed because there is no patch file to look at, so it has always return 1 (see https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/CLI.php#L230).

This isn't that useful because it means you can't actually check the return value of PHPCS. But also, patching using diff was a waste of time, so it was removed in 3.0a1. The 3.0 version no longer has a --no-patch option because it never uses patch and diff - it only overwrites files like --no-patch does.

I changed the return value in 3.0 to return the number of errors found, which is a little better but, on reflection, still not good. 3.0 has a concept of "total number of fixed errors" so I think I can probably get the return value working a bit better in there. I've already changed the return values of PHPCS in 3.0, so I don't think there is a problem changing PHPCBF a bit more as well.

But I don't want to mess with return values in the 2.x version, especially given I don't think they will be accurate. So for now, you'll need to ignore the return value.

I'll try and fix up the 3.0 version and commit that as a fix for this issue, but you'll need to upgrade to 3.0 before you can accurately check the return value of PHPCBF.

@gsherwood
Copy link
Member

I've changed the PHPCBF exit codes to this:

  • Exit code 0 is now used to indicate that no fixable errors were found, and so nothing was fixed
  • Exit code 1 is now used to indicate that all fixable errors were fixed correctly
  • Exit code 2 is now used to indicate that PHPCBF failed to fix some of the fixable errors it found
  • Exit code 3 is now used for general script execution errors

Those mirror what the current 2.x version tries to do when using patch and diff, but it is hopefully a bit more accurate. And it's obviously a big improvement over both the --no-patch 2.x version and the 3.0.0RC2 version.

Do those exit codes look sane to you?

@gmponos gmponos closed this as completed Jan 16, 2017
@gmponos gmponos reopened this Jan 16, 2017
Ovsyanka added a commit to Ovsyanka/chronos that referenced this issue Apr 4, 2017
I didn't found the way to describe --no-patch option in xml config, so i put it in composer.json.

The bad thing is `composer phpcbf` always returns exit code 1:

`Script phpcbf --no-patch handling the phpcbf event returned with error code 1`

It is because When using the `--no-patch` option, PHPCS doesn't know if any errors were actually fixed because there is no patch file to look at, so it has always return `1` [src](squizlabs/PHP_CodeSniffer#1270 (comment)), so you should just ignore that error.

In the PHPCS 3 --no-patch will be removed.
Ovsyanka added a commit to Ovsyanka/chronos that referenced this issue Apr 4, 2017
Seems like when you using xml config there is `--no-patch` option by default.

Because that the `composer phpcbf` will always returns exit code 1:

`Script phpcbf --no-patch handling the phpcbf event returned with error code 1`

It is because when using the `--no-patch` option, PHPCS doesn't know if any errors were actually fixed because there is no patch file to look at, so it has always return `1` [src](squizlabs/PHP_CodeSniffer#1270 (comment)), so you should just ignore that error.

In the PHPCS 3 --no-patch will be removed.
Ovsyanka added a commit to Ovsyanka/chronos that referenced this issue Apr 4, 2017
Seems like when you using xml config there is `--no-patch` option by default.

Because that the `composer phpcbf` will always returns exit code 1:

`Script phpcbf --no-patch handling the phpcbf event returned with error code 1`

It is because when using the `--no-patch` option, PHPCS doesn't know if any errors were actually fixed because there is no patch file to look at, so it has always return `1` [src](squizlabs/PHP_CodeSniffer#1270 (comment)), so you should just ignore that error.

In the PHPCS 3 --no-patch will be removed.
Ovsyanka added a commit to Ovsyanka/chronos that referenced this issue Apr 4, 2017
Seems like when you using xml config there is `--no-patch` option by default.

Because that the `composer phpcbf` will always returns exit code 1:

`Script phpcbf --no-patch handling the phpcbf event returned with error code 1`

It is because when using the `--no-patch` option, PHPCS doesn't know if any errors were actually fixed because there is no patch file to look at, so it has always return `1` [src](squizlabs/PHP_CodeSniffer#1270 (comment)), so you should just ignore that error.

In the PHPCS 3 --no-patch will be removed.
Ovsyanka added a commit to Ovsyanka/chronos that referenced this issue Apr 4, 2017
Seems like when you using xml config there is `--no-patch` option by default.

Because that the `composer phpcbf` will always returns exit code 1:

`Script phpcbf --no-patch handling the phpcbf event returned with error code 1`

It is because when using the `--no-patch` option, PHPCS doesn't know if any errors were actually fixed because there is no patch file to look at, so it has always return `1` [src](squizlabs/PHP_CodeSniffer#1270 (comment)), so you should just ignore that error.

In the PHPCS 3 --no-patch will be removed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants