CodeSniffer Inspect Code only shows 1 warning

Answered

I'm new to PHPStorm but very impressed so far; I've managed to get PHP CodeSniffer up and running (see below screenshot) and highlighting sniffs in the editor is working well and shows all issues (at least up to the 100 allowed!).

But when I perform "Inspect Code" on the source (shown in the screenshot running on a single simple file) there is only ever a single CodeSniffer warning (always the first issue). Other inspections seem to be working fine and returning hundreds of warnings across large code bases.

I've spent a while trying to plough through the settings but can't find a reason for this. Can anyone enlighten me?

Lee

11 comments
Comment actions Permalink

Sorry, just realised that in the above screenshot the inspection was run before removing a comment. This is how it should look!

0
Comment actions Permalink

Apologies, what the issue is? Should there be more PHPCS warnings for given file? 

Could you please illustrate this (e.g. a screenshot of phpcs run against that file in terminal)?

0
Comment actions Permalink

Sure, each of the yellow highlighted lines in the previous screenshot should trigger at least one CS warning. As requested, I've run phpcs in the terminal against the same file:

Shouldn't the code inspection be listing all 12 of these violations?

0
Comment actions Permalink

Is the coding standard at Preferences | Editor | Inspections > PHP | PHP Code Sniffer validation set correctly?

0
Comment actions Permalink

Yes, as you can see from the screenshot below, I have the coding standard set to PEAR as per the example above. Looking at a larger file in my project I get the "phpcs: Too many messages per file..." warning at the top of the editor but running Code | Inspect Code... on that same file again just gives me a warning for the first CodeSniffer violation.

 

Note that before I had these settings, I spent some time playing with the CodeSniffer settings:

  • I tried different coding standards (including a custom standard of my own).
  • I also set up my own colour coded severity just for CodeSniffer.

I cannot say for sure, but I think before I experimented I was getting a full list of violations in the Inspect Code results. But as you see from the above screenshot, I have returned the standard Warning severity and returned to the PEAR coding standard.

I have also tried with the "show warnings as..." checkbox turned on and the "show sniff name" box on and off.

Whatever I try, I am still only getting the first violation listed in Inspect Code... despite many lines in the code being highlighted with violations (and many colour stripes in the scrollbar). Are there any other settings I should be looking at?

0
Comment actions Permalink

(Quite possibly I will be completely wrong her as I do not run CodeSniffer so cannot verify it myself .. but still)

How many Inspection Profiles do you have?

When you run "Code | Inspect Code" --- can you please double check what "Profile" is selected there? Maybe you are running using wrong/different profile that is configured differently...

Anything related in the idea.log (Help | Show Log in...)?

0
Comment actions Permalink

Thank you for your theory. The Inspection Profiles list Project Default (selected) and IDE Default. Switching to IDE default doesn't include the CodeSniffer checks at all. There are no other inspection profiles.

I looked at idea.log and running Inspect Code just added these two lines:

2017-05-24 13:06:39,671 [2004113]   INFO - ex.GlobalInspectionContextImpl - Code inspection started 
2017-05-24 13:06:40,974 [2005416] INFO - ex.GlobalInspectionContextImpl - Code inspection finished
0
Comment actions Permalink

That's rather strange behavior.

Could you please try to configure the same PHPCS inspection for any other project and check if it would report more errors there? Just want to make sure this isn't a project-related glitch.

0
Comment actions Permalink

It does seem to be related to the project. I created a very simple new project with just one PHP file and a single class and ran Inspect Code with (as far as I know) the same CodeSniffer settings. This time all highlighted violations were reported in the Inspection Results pane.

0
Comment actions Permalink

Could you run File > Invalidate Caches > Invalidate and Restart and check if this will help the initial project?

0
Comment actions Permalink

I suspect that probably would have worked, but I'm afraid there's no way to know now. The old project sources included a symlink which I removed when I set up the reconfigured project (so as to avoid a circular reference). The old project was then reindexed before and after I recreated the symlink which I imagine also invalidated much of the previous cache.

Anyway, I am now happy as both old and new projects both return the correct number of CodeSniffer results when I use Inspect Code.

Many thanks to everyone who gave suggestions.

1

Please sign in to leave a comment.