phpro / grumphp

A PHP code-quality tool
MIT License
4.11k stars 429 forks source link

Validating all lines of file instead of changes made to commit #1081

Closed himanshukbhardiya closed 1 year ago

himanshukbhardiya commented 1 year ago
Q A
Version 1.15.0
Bug? yes/no
New feature? no
Question? yes
Documentation? yes

My configuration

# grumphp.yml
# Please add a copy of your grumphp.yml file.
grumphp:
    tasks:
        phpcs:
            standard:
                - 'PSR12'
            warning_severity: 0
            error_severity: 5
        phpmd:
            whitelist_patterns: []
            exclude: []
            report_format: text
            ruleset: ['unusedcode']
            triggered_by: ['php']
        git_blacklist:
            keywords:
                - "die("
                - "var_dump("
                - "print_r("
            triggered_by: [php]
            regexp_type: G

Steps to reproduce:

I updated php file and added it for commit. after that i did git diff --staged which shows correct diff

--- a/product_info.php
+++ b/product_info.php
@@ -11,6 +11,7 @@
 /**
  * include common
  */
+echo 213;
 require_once("lib/common.php");

But when i commited using below command, git commit -m "commit test" it shows error on the lines which is not touched/modified.

phpcs
=====

FILE: product_info.php
----------------------------------------------------------------------
FOUND 100 ERRORS AFFECTING 81 LINES
----------------------------------------------------------------------
  111 | ERROR | [x] Expected 1 space(s) after IF keyword; 0 found
      |       |     (Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword)
  185 | ERROR | [x] Spaces must be used to indent lines; tabs are not
      |       |     allowed
      |       |     (Generic.WhiteSpace.DisallowTabIndent.TabsUsed)
  186 | ERROR | [x] Spaces must be used to indent lines; tabs are not
      |       |     allowed
      |       |     (Generic.WhiteSpace.DisallowTabIndent.TabsUsed)
  202 | ERROR | [x] Spaces must be used to indent lines; tabs are not
      |       |     allowed
      |       |     (Generic.WhiteSpace.DisallowTabIndent.TabsUsed)
  202 | ERROR | [x] Whitespace found at end of line
      |       |     (Squiz.WhiteSpace.SuperfluousWhitespace.EndLine)
  209 | ERROR | [x] Inline control structures are not allowed
      |       |     (Generic.ControlStructures.InlineControlStructure.NotAllowed)
  265 | ERROR | [x] Inline control structures are not allowed
      |       |     (Generic.ControlStructures.InlineControlStructure.NotAllowed)
  269 | ERROR | [x] Inline control structures are not allowed
      |       |     (Generic.ControlStructures.InlineControlStructure.NotAllowed)
  281 | ERROR | [x] Inline control structures are not allowed
      |       |     (Generic.ControlStructures.InlineControlStructure.NotAllowed)
  283 | ERROR | [x] Inline control structures are not allowed
      |       |     (Generic.ControlStructures.InlineControlStructure.NotAllowed)
  285 | ERROR | [x] Inline control structures are not allowed
      |       |     (Generic.ControlStructures.InlineControlStructure.NotAllowed)
  288 | ERROR | [x] Blank line found at start of control
      |       |     structure
      |       |     (Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen)

Not sure why this is happening as above lines are not modified during this commit. Am i missing any configurations here? What i want to achieve is to validate the code which is modified and staged only. It should not validate other lines written in the file.

veewee commented 1 year ago

phpcs is not able to run on diffs - only on complete files.