deadem / notepad-pp-linter

Notepad++ Linter. Realtime code check against any checkstyle-compatible linter: jshint, eslint, jscs, phpcs, csslint etc
MIT License
35 stars 7 forks source link

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

Closed tolki5 closed 1 year ago

tolki5 commented 1 year ago

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!

deadem commented 1 year ago

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

tolki5 commented 1 year ago

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?

deadem commented 1 year ago

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++?

tolki5 commented 1 year ago

Run in cmd: `<?xml version="1.0" encoding="UTF-8"?>

` In notepad++ works too. I do not understand.
deadem commented 1 year ago

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.

tolki5 commented 1 year ago

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 :-(

tolki5 commented 1 year ago

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"?>

` In setting for notepad++ this: ` ` When opening a file with a syntax error, notepad++ closes immediately. I tried repeatedly.
ThosRTanner commented 1 year ago

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

ThosRTanner commented 1 year ago

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

xaviermdq commented 1 year ago
<?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.

xaviermdq commented 1 year ago

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>