Skip to content

Long sniff codes can cause PHP warnings in source report when showing error codes #694

@GaryJones

Description

@GaryJones

When running a source report, as part of grunt phpcs, I'm getting the report generated at https://gist.github.com/GaryJones/156f24e88c71ab453937

Warning: str_repeat(): Second argument has to be greater than or equal to 0 in .../phpcs/CodeSniffer/Reports/Source.php on line 201

This appears to happen with multiple (but not all) sniffs from WordPress, Squiz and Generic standards, all in use by the WordPress standard.

It only happens with Source reports. Full, Summary and Info reports are all fine. If I run phpcs directly, not with grunt, then the errors do not appear, but there's very little in the grunt-phpcs code to suggest why these errors are appearing.

phpcs: 2.3.4
grunt-phpcs: 0.4.0
grunt: 0.4.5

Here's my phpcs.xml:

<?xml version="1.0"?> <ruleset name="Gary Jones"> <description>The code standard for Gamajo theme.</description> <file>theme/.</file> <arg name="extensions" value="php"/> <arg name="report-full" value="logs/phpcs-full.log"/> <arg name="report-summary" value="logs/phpcs-summary.log"/> <arg name="report-source" value="logs/phpcs-source.log"/> <arg name="report-info" value="logs/phpcs-info.log"/> <arg value="sp"/> <exclude-pattern>vendor/.</exclude-pattern> <rule ref="WordPress.XSS.EscapeOutput"> <properties> <property type="array" name="customAutoEscapedFunctions" value="genesis_attr"/> </properties> </rule> <rule ref="WordPress"> <exclude name="WordPress.VIP"/> <!--<exclude name="WordPress.Files.FileName.UnderscoresNotAllowed"/>--> </rule> </ruleset>

Using load-grunt-config, my phpcs.js is:

module.exports = { options: { // Assumes 'phpcs' is accessible in the global system. // If not, set 'bin: /path/to/bin/phpcs' // ignoreExitCode: true, standard: 'phpcs.xml' }, src: [ '<%= paths.theme %>**/*.php' ] } };

It also happened with:

module.exports = { options: { // Assumes 'phpcs' is accessible in the global system. // If not, set 'bin: /path/to/bin/phpcs' // ignoreExitCode: true, standard: 'phpcs.xml' }, full: { options: { reportFile: '<%= paths.logs %>phpcs-full.log' }, src: [ '<%= paths.theme %>**/*.php' ] } };

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions