phpro / grumphp

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

With GrumPHP php-cs-fixer is not able to exclude the directories as configured in .php-cs-fixer.php #1086

Closed sandipansaha closed 1 year ago

sandipansaha commented 1 year ago
Q A
Version 1.16.0
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets

My configuration

# grumphp.yml
# Please add a copy of your grumphp.yml file.
# Project level GrumPHP configuration for Magento 2
grumphp:
    hide_circumvention_tip: true
    process_timeout: 120
    stop_on_failure: false
    ignore_unstaged_changes: false
    additional_info: "\nThank you for keeping the code quality better. We appreciate your patience and efforts.\nHappy 
    Coding!!\n"
    tasks:
        jsonlint:
            detect_key_conflicts: true
            metadata:
                priority: 100
        xmllint:
            ignore_patterns:
                - "#test/(.*).xml#"
            metadata:
                priority: 100
        phplint:
            triggered_by: ['php', 'phtml']
            metadata:
                priority: 200
        yamllint:
            ignore_patterns:
                - "#test/(.*).yml#"
                - "#charts/.*#"
            metadata:
                priority: 100
        composer:
            file: ./composer.json
            no_check_all: true
            no_check_lock: false
            no_check_publish: false
            with_dependencies: false
            strict: false
            metadata:
                priority: 80
        # validate git commit message
        git_commit_message:
            allow_empty_message: false
            enforce_capitalized_subject: false
            enforce_no_subject_punctuations: false
            enforce_no_subject_trailing_period: true
            enforce_single_lined_subject: true
            type_scope_conventions: []
            max_body_width: 120
            max_subject_width: 100
            case_insensitive: true
            multiline: false
            additional_modifiers: ''
        # validate git branch names
        git_branch_name:
            whitelist:
                # allowed branch names: 'feature/new', 'feature/new1', 'feature/new-test', 'feature/test/TASK-1', etc
                - "/(hotfix|bugfix|feature|release|task)((\\/([A-Za-z|0-9|-]{3,}))(\\/([A-Z]{2,}-[0-9]+))?)$/"
            blacklist:
                - "development"
                - "production"
                - "staging"
                - "master"
                - "infra"
            allow_detached_head: true
        # catch not allowed keywords
        git_blacklist:
            keywords:
                - "\\.dev"
                - "\\.local"
                - "<<<<<<<"
                - "======="
                - "DebuggerUtility"
                - "ObjectManager::getInstance"
                - "_GET\\["
                - "_POST\\["
                - "_REQUEST\\["
                - "console.log("
                - "die("
                - "die;"
                - "exit("
                - "exit;"
                - "fileadmin"
                - "localhost"
                - "phpinfo"
                - "phpinfo("
                - "var_dump("
                - "_objectManager"
                - "objectManager"
                - "ObjectManagerInterface"
            triggered_by: ['php', 'js', 'html', 'phtml']
            ignore_patterns:
                - /^app\/bootstrap.php/
                - /^dev\/tests\/(.*)/
            metadata:
                priority: 90
        # https://devdocs.magento.com/guides/v2.4/coding-standards/code-standard-php.html
        phpcs:
            standard: Magento2
            tab_width: 4
            severity: 5 # can remove this to dis-allow all level of severity.
            error_severity: 5
            warning_severity: 5
            report: full
            triggered_by: [phtml, php]
            whitelist_patterns:
                - /^dev\/tests\/(.*)/
            metadata:
                priority: 70
        phpcsfixer2:
            allow_risky: false
            config: '.php-cs-fixer.php'
            triggered_by: ['php', 'phtml']
            using_cache: true
            cache_file: './.php-cs-fixer.cache'
            config_contains_finder: false
            verbose: true
        phpmd:
            ruleset: ['./dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml']
            triggered_by: ['php']
            exclude:
                - "./app/code/Magento/"
                - "./app/code/*/*/Setup/"
                - "./dev/tests/"
            metadata:
                priority: 70
        #  uncomment to skip modules using whitelist patterns
        #  whitelist_patterns:
        #     - /^app\/code\/MyVendor\/MyModuleToSkip\/(.*)/

        # https://devdocs.magento.com/guides/v2.4/test/testing.html#phpstan
        phpstan:
            autoload_file: ~
            configuration: './dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/phpstan.neon'
            level: 2
            triggered_by: ['php']
            force_patterns: []
            ignore_patterns:
                - /^dev\/tests\/(.*)/
            memory_limit: "-1"
            metadata:
                priority: 90
        phpversion:
            project: '8.1'
# .php-cs-fixer.php
# copy of .php-cs-fixer.php file.
# Project level .php-cs-fixer.php configuration for Magento 2
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * PHP Coding Standards fixer configuration
 */

$finder = PhpCsFixer\Finder::create()
    ->name('*.phtml')
    ->in(__DIR__)
    ->exclude('dev/tests')
    ->exclude('dev/tests/integration/tmp')
    ->exclude('dev/tests/integration/var')
    ->exclude('lib/internal/Cm')
    ->exclude('lib/internal/Credis')
    ->exclude('lib/internal/Less')
    ->exclude('lib/internal/LinLibertineFont')
    ->exclude('pub/media')
    ->exclude('pub/static')
    ->exclude('setup/vendor')
    ->exclude('setup/src')
    ->exclude('var');

$config = new PhpCsFixer\Config();
$config->setFinder($finder)
    ->setRules([
        '@PSR2' => true,
        'array_syntax' => ['syntax' => 'short'],
        'concat_space' => ['spacing' => 'one'],
        'include' => true,
        'new_with_braces' => true,
        'no_empty_statement' => true,
        'no_extra_blank_lines' => true,
        'no_leading_import_slash' => true,
        'no_leading_namespace_whitespace' => true,
        'no_multiline_whitespace_around_double_arrow' => true,
        'multiline_whitespace_before_semicolons' => true,
        'no_singleline_whitespace_before_semicolons' => true,
        'no_trailing_comma_in_singleline_array' => true,
        'no_unused_imports' => true,
        'no_whitespace_in_blank_line' => true,
        'object_operator_without_whitespace' => true,
        'ordered_imports' => true,
        'standardize_not_equals' => true,
        'ternary_operator_spaces' => true,
    ]);
return $config;

dist file - https://github.com/magento/magento2/blob/2.4-develop/.php-cs-fixer.dist.php

Steps to reproduce:

# Generate empty folder
mkdir tmp
cd tmp
git init
echo "vendor" > .gitignore
pbpaste > grumphp.yml
composer require --dev phpro/grumphp

# Your actions
# Please add the steps on how to reproduce the issue here.
We are using this with Magento 2.
The php-cs-fixer exclude is working while I run php-cs-fixer separately.
But with GrumPHP it is not able to exclude the directories as configured in .php-cs-fixer.php.
Please check the attached screenshot.

# Run GrumPHP:
git add -A && git commit -m"Test"
# or
./vendor/bin/grumphp run

Result:

# Please add the result of the run or git commit actions here.
phpcsfixer2
===========

1) /var/www/html/magento/magento245ee_1/site/magento/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductPriceTest.php (braces, method_argument_space, no_singleline_whitespace_before_semicolons, ordered_imports)
2) /var/www/html/magento/magento245ee_1/site/magento/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/CartPromotionsTest.php (no_multiline_whitespace_around_double_arrow, ordered_imports)
3) /var/www/html/magento/magento245ee_1/site/magento/dev/tests/integration/framework/Magento/TestFramework/MessageQueue/PublisherConsumerController.php (ordered_imports)

![image](https://user-images.githubusercontent.com/4614581/235480954-522a665d-8de9-4c47-9b22-8c00639656d6.png)
sandipansaha commented 1 year ago

Results screenshot: image

yguedidi commented 1 year ago

@sandipansaha I think you should set config_contains_finder to true in your phpcsfixer2 task configuration

sandipansaha commented 1 year ago

Thanks @yguedidi