Flycheck: Give original filename to phpcs

Created on 24 Mar 2016  路  7Comments  路  Source: flycheck/flycheck

As explained here, using file path instead of STDIN allows phpcs to infer which rules should be excluded.

bug

All 7 comments

Please summarise the discussion in the issue you've referenced as far as it's relevant to Flycheck and elaborate why we need to drop standard input for phpcs. Ideally, try to produce a minimal example where phpcs behaves different as expected with Flycheck.

There are phpcs rules that _depends_ on the file location.
As an example take this excerpt from CakePHP code sniffer (taked from here):

<rule ref="Squiz.NamingConventions.ValidFunctionName">
  <exclude-pattern>*/src/*</exclude-pattern>
  <exclude-pattern>*/tests/*</exclude-pattern>
</rule>

it tells to phpcs to exclude that rule when the path of the file being checked match the patterns.
So, if you are checking files under src/ (which are almost all in a cakephp project and most other frameworks) and you call phpcs with file path it won't apply that rule, and you'll see less errors.
If you call phpcs with STDIN it can't know where the file is, so it applies _all_ the rules, resulting in an incorrect list of errors.
I hope it to be understandable, my english is really bad.

@choma Other syntax checkers (e.g. rubocop, eslint, etc.) solve this by accepting the name of the file as argument. Is that no option for phpcs?

I copy my comment on flycheck issue, so you can find it easily:

As I understand from this issue, and what I can understand from this code, you have to add phpcs_input_file: [file path] as the first line of content.
I've just tested it and it works great!

@choma phpcs 2.6 will provide an option --stdin-path which allows us to set the path, see https://github.com/squizlabs/PHP_CodeSniffer/issues/934#issuecomment-203161356

When phpcs 2.6 is released will use this option to fix this issue.

phpcs 2.6 is out now, I'll update the syntax checker definition soon. Note that this will implicitly drop support for any older phpcs release.

@choma I've updated phpcs accordingly, the issue should be fixed now.

Thanks for reporting it, and for your help with finding a proper solution! 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ngoldbaum picture ngoldbaum  路  5Comments

mrlee23 picture mrlee23  路  5Comments

ahungry picture ahungry  路  3Comments

itkach picture itkach  路  3Comments

yuyang0 picture yuyang0  路  7Comments