I want to add PHP CodeSniffer to VScode.
Within VScode I am getting the error ‘phpcs: The phpcs report contains invalid json’
However when I run the following command in the terminal:
phpcs --standard="WordPress-Core" -q --report=json --encoding=UTF-8 dropdowns.php
PHP Codesniffer works as expected with the following terminal output:
{"totals":{"errors":34,"warnings":17,"fixable":50},"files":{"/Users/michelle/Local Sites/hdpiano2/app/public/wp-content/themes/hdpiano/inc/dropdowns.php":{"errors":34,"warnings":17,"messages":[{"message":"Array double arrow not aligned correctly; expected 10 space(s) between "'id'" and double arrow, but found 1.","source":"WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned","severity":5,"fixable":true,"type":"WARNING","line":15,"column":14},{"message":"Array double arrow not aligned correctly; expected 4 space(s) between "'taxonomy'" and double arrow, but found 1.","source":"WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned","severity":5,"fixable":true,"type":"WARNING","line":17,"column":20},{"message":"Array double arrow not aligned correctly; expected 5 space(s) between "'orderby'" and double arrow, but found 1.","source":"WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned","severity":5,"fixable":true,"type":"WARNING","line":18,"column":19},{"message":"Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":34,"column":15},{"message":"Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":35,"column":18},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":36,"column":26},{"message":"Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":44,"column":19},{"message":"Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":84,"column":14},{"message":"Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":111,"column":13},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":130,"column":16},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":131,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":135,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":139,"column":9},{"message":"Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":144,"column":13},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":165,"column":16},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":166,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":170,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":174,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":178,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":182,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":186,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":190,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":194,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":198,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":202,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":211,"column":22},{"message":"Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":217,"column":13},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":236,"column":16},{"message":"Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":260,"column":13},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":279,"column":16},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":280,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":284,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":288,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":292,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":296,"column":9},{"message":"Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":301,"column":13},{"message":"Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":303,"column":11},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":316,"column":16},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":317,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":321,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":325,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":329,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":333,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":337,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":341,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":345,"column":9},{"message":"Short array syntax is not allowed","source":"Generic.Arrays.DisallowShortArraySyntax.Found","severity":5,"fixable":true,"type":"ERROR","line":349,"column":9},{"message":"Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":354,"column":13},{"message":"Found precision alignment of 1 spaces.","source":"WordPress.WhiteSpace.PrecisionAlignment.Found","severity":5,"fixable":false,"type":"WARNING","line":396,"column":1},{"message":"Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":460,"column":14},{"message":"Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space","source":"Generic.Formatting.MultipleStatementAlignment.NotSameWarning","severity":5,"fixable":true,"type":"WARNING","line":461,"column":14}]}}}
There is no invalid JSON in the output and I am unsure how to proceed to get this working.
Advertisement
Answer
In this case I had the wrong executable path for phpcs. Running which phpcs
in the terminal gave me the correct path.