deadem / notepad-pp-linter

Notepad++ Linter. Realtime code check against any checkstyle-compatible linter: jshint, eslint, jscs, phpcs, csslint etc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[phpcs] Linter: Invalid output format. Only checkstyle-compatible output allowed.

tolki5 opened this issue · comments

commented

Hello,

Linter keeps returning the following error “Linter: Invalid output format. Only checkstyle-compatible output allowed.” Even though running the command in cmd produces valid XML.

Here is example of XML returned in cmd:

<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="3.7.2">
<file name="D:\Dokumenty\php\film-arena\index.php">
 <error line="13" column="5" severity="error" message="Line indented incorrectly; expected 0 spaces, found 4" source="Generic.WhiteSpace.ScopeIndent.IncorrectExact"/>
 <error line="13" column="5" severity="error" message="Expected 1 space(s) after IF keyword; 0 found" source="Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword"/>
</file>
</checkstyle>

Here’s my installation info:
Notepad++ v8.5.1 (64-bit)
Build time : Mar 21 2023 - 19:16:10
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line : "C:\Users\Tolki\Desktop\x-men-kalkulace.txt"
Admin mode : ON
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Pro (64-bit)
OS Version : 21H2
OS Build : 19044.2728
Current ANSI codepage : 1250
Plugins :
Linter (0.1)
mimeTools (2.9)
NppConverter (4.5)
NppExec (0.8.2)
NppExport (0.4)

My linter configuration is:

<?xml version="1.0" encoding="UTF-8" ?>
<NotepadPlus>
  <linter extension=".php" command="C:\Users\Tolki\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\bin\phpcs.bat --report=checkstyle"/>
</NotepadPlus>

Thank you for support!

commented

Hello! Unpack the archive and try to target the a.bat file in the command attribute. What output will be produced by the notepad++?
a.zip

commented

Hi there,

thank you for your support! I tried and it's works. Two errors are marked.

I tried a lower version of phpcs, specifically this one: https://github.com/squizlabs/PHP_CodeSniffer/tree/2.9 and its works.

So is the problem in the fact that the report from phpcs is structured differently in the higher version?

commented

Not so likely...
Try to change the content of a.bat to

@echo off
C:\Users\Tolki\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\bin\phpcs.bat --report=checkstyle C:\path-to\php-file\with-errors.php

And run it from command line?
And then open php-file from the notepad++?

commented

Run in cmd:
<?xml version="1.0" encoding="UTF-8"?> <checkstyle version="3.7.2"> <file name="D:\Dokumenty\php\film-arena\prace\01a\index.php"> <error line="1" column="1" severity="error" message="End of line character is invalid; expected &quot;\n&quot; but found &quot;\r\n&quot;" source="Generic.Files.LineEndings.InvalidEOLChar"/> <error line="2" column="1" severity="error" message="You must use &quot;/**&quot; style comments for a file comment" source="PEAR.Commenting.FileComment.WrongStyle"/></file> </checkstyle>

In notepad++ works too. I do not understand.

commented

Try to replace "C:\path-to\php-file\with-errors.php" in the a.bat to "%1"

Looks like it is a execute permissions issue.

commented

I changed and got the message again:

Linter: Invalid output format. Only checkstyle-compactible output allowed.

I checked the permissions and everything should be fine. I'm really confused :-(

commented

One more point. I tried to use another phpcs:

https://github.com/php-parallel-lint/PHP-Parallel-Lint

In cmd i got this result:
<?xml version="1.0" encoding="UTF-8"?> <checkstyle> <file name="D:\Dokumenty\php\film-arena\prace\01a\index.php"> <error line="310" severity="ERROR" message="Parse error: syntax error, unexpected '}' in D:\Dokumenty\php\film-arena\prace\01a\index.php on line 310" source="Syntax Error" /> </file> </checkstyle>

In setting for notepad++ this:
<?xml version="1.0" encoding="UTF-8" ?> <NotepadPlus> <linter extension=".php" command="C:\Users\Tolki\AppData\Roaming\Composer\vendor\bin\parallel-lint.bat --checkstyle"/> </NotepadPlus>

When opening a file with a syntax error, notepad++ closes immediately. I tried repeatedly.

I've had this start too since updating to latest eslint. (And the nightmare of updating npm to latest version).

When I run the command in a command prompt I get

<?xml version="1.0" encoding="utf-8"?><checkstyle version="4.3"><file name="C:\Users\blahblah.js"><error line="53" column="1" severity="error" message="All &apos;var&apos; declarations must be at the top of the function scope. (vars-on-top)" source="eslint.rules.vars-on-top" /><error line="53" column="1" severity="error" message="Unexpected var, use let or const instead. (no-var)" source="eslint.rules.no-var" /></file></checkstyle>

But all I see in notepad is 'Linter: linter.xml load error. Check file format'

jshint is working fine

and today this has started working fine and I'm not sure what I did to change it.

commented
<?xml version="1.0" encoding="UTF-8" ?>
<NotepadPlus>
  <linter extension=".php" command="C:\Users\Tolki\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\bin\phpcs.bat --report=checkstyle"/>
</NotepadPlus>

Hi @tolki5 . I think its a PATH or parameter problem. First, make sure you have the full path to php.exe in your system PATH variable. Second, don't use phpcs.bat and use the following linter.xml:

<?xml version="1.0" encoding="utf-8" ?>
<NotepadPlus>
	<linter extension=".php" command='php.exe "X\phpcs.phar" --report=checkstyle'/>
</NotepadPlus>

Replace X with fullpath to phpcs.phar file. Don't use environment variables in X. I don't know why the variables are not expanded. If the path does not contain spaces, it is not necessary to use the double quotes.

commented

The problem with my last solution... is that it doesn't work! :( The bat file takes a temporary file as a parameter (if you are editing the file c:\path\to\file\index.php, the script receives c:\path\to\file\index.php.temp.linter.file.tmp as the parameter) which has 0 bytes.
To fix this problem, I had to create a BAT script (I place it in c:\phpcs.bat) with the following content:

@echo off
set F=%1
set F=%F:.temp.linter.file.tmp=%
php.exe "X\phpcs.phar" --report=checkstyle "%F%"

Like before, replace X with fullpath to phpcs.phar file.
The linter.xml file should be:

<?xml version="1.0" encoding="utf-8" ?>
<NotepadPlus>
	<linter extension=".php" command='c:\phpcs.bat'/>
</NotepadPlus>