From ab623a1fdbc53356c3bc7251bafa2f147f83d76a Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 30 Jan 2019 16:04:31 +0100 Subject: [PATCH] OPENEUROPA-1535: Revert. --- CONVENTIONS.md | 5 +- README.md | 9 --- composer.json | 14 +--- dist/library-conventions.yml | 2 +- grumphp.yml.dist | 1 - resources/library-phpcs-ruleset.xml | 22 ------ tests/AbstractTest.php | 6 +- tests/DrupalTest.php | 8 +-- tests/GitCommitMessageTest.php | 8 +-- tests/PhpCodeSnifferTest.php | 70 ------------------ tests/PhpCodeSnifferTestBase.php | 72 ------------------- tests/PhpMessDetectorTest.php | 4 +- tests/fixtures/phpcs/correct-library-code.php | 29 -------- .../fixtures/phpcs/incorrect-library-code.php | 34 --------- tests/library-conventions.yml.dist | 7 -- 15 files changed, 16 insertions(+), 275 deletions(-) delete mode 100644 resources/library-phpcs-ruleset.xml delete mode 100644 tests/PhpCodeSnifferTest.php delete mode 100644 tests/PhpCodeSnifferTestBase.php delete mode 100644 tests/fixtures/phpcs/correct-library-code.php delete mode 100644 tests/fixtures/phpcs/incorrect-library-code.php delete mode 100644 tests/library-conventions.yml.dist diff --git a/CONVENTIONS.md b/CONVENTIONS.md index 410cc51..127e00c 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -4,10 +4,7 @@ List of conventions for OpenEuropa projects and components. ## PHP Code Sniffer -- For generic PHP projects: [PSR-2 coding standards](https://www.php-fig.org/psr/psr-2) - with the following additions: - - Comments, array declarations and code that is split over multiple lines also - need to be indented with 4 characters. +- For generic PHP projects: [PSR-2 coding standards](https://www.php-fig.org/psr/psr-2). - For Drupal projects: [Drupal coding standards](https://www.drupal.org/docs/develop/standards) ## PHP Mess Detector diff --git a/README.md b/README.md index cbe5bca..f17b162 100644 --- a/README.md +++ b/README.md @@ -186,12 +186,3 @@ git config --global --unset core.hooksPath * Best results were gained using the [Docker app](https://docs.docker.com/docker-for-mac/install/) * The local repo folder should be shared under Docker -> Preferences -> File sharing to enable the file to be written locally. -## Patches - -The component uses the PSR-2 standard based on version 3.4 of package [squizlabs/PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer). -As the PSR-2 standard does not enforce indentation, we decided to add custom rules in a custom ruleset in order to make sure -that our code is properly indented. -Unfortunately, there are some issues in versions 3.4 of [squizlabs/PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) regarding -code indentation and we fixed them by including custom patches. -Those issues are partially solved in version 3.5 which is not stable yet. -As soon as 3.5 reaches a stable version, we will remove those patches. diff --git a/composer.json b/composer.json index c241c16..b1324ac 100644 --- a/composer.json +++ b/composer.json @@ -6,8 +6,7 @@ "cweagans/composer-patches": "^1.0", "drupal/coder": "^8.3", "phpmd/phpmd" : "^2.6", - "phpro/grumphp": "^0.14.2", - "squizlabs/php_codesniffer": "^3.4.0" + "phpro/grumphp": "^0.14.2" }, "require-dev": { "phpunit/phpunit": "^5.5|^6.0" @@ -22,17 +21,8 @@ "OpenEuropa\\CodeReview\\Tests\\": "./tests/" } }, - "extra": { - "enable-patching": true, - "composer-exit-on-patch-failure": 1, - "patches": { - "squizlabs/php_codesniffer": { - "Fix conflict between scope indentation and array indentation checking. Ref. https://github.com/squizlabs/PHP_CodeSniffer/issues/2281": "https://gist.githubusercontent.com/drupol/c307b48fe4eb187b0833afb1d1b97e6a/raw/c3d414e9f4c182387ca9405c36f5daeb7b51ae05/phpcs-390bffe2265aac8184fdf86400c0d0841e65bc4b.patch", - "Disable exact checking of multi-line chained method calls in Generic.WhiteSpace.ScopeIndent. Ref. https://github.com/squizlabs/PHP_CodeSniffer/pull/2372": "https://gist.githubusercontent.com/drupol/c307b48fe4eb187b0833afb1d1b97e6a/raw/c3d414e9f4c182387ca9405c36f5daeb7b51ae05/phpcs-pr-2372.patch" - } - } - }, "scripts": { "changelog": "docker run --rm -v \"$(pwd):$(pwd)\" -w $(pwd) muccg/github-changelog-generator openeuropa/code-review -t $CHANGELOG_GITHUB_TOKEN --future-release=$CHANGELOG_FUTURE_RELEASE" } } + diff --git a/dist/library-conventions.yml b/dist/library-conventions.yml index eb49c50..9ffed13 100644 --- a/dist/library-conventions.yml +++ b/dist/library-conventions.yml @@ -2,5 +2,5 @@ imports: - { resource: base-conventions.yml } parameters: - tasks.phpcs.standard: ./vendor/openeuropa/code-review/resources/library-phpcs-ruleset.xml + tasks.phpcs.standard: ./vendor/squizlabs/php_codesniffer/src/Standards/PSR2 tasks.phpcs.warning_severity: 0 diff --git a/grumphp.yml.dist b/grumphp.yml.dist index 8c984ac..01d96e6 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -10,4 +10,3 @@ parameters: - tests/fixtures/ tasks.phpmd.ruleset: - ./resources/phpmd-ruleset.xml - tasks.phpcs.standard: ./resources/library-phpcs-ruleset.xml diff --git a/resources/library-phpcs-ruleset.xml b/resources/library-phpcs-ruleset.xml deleted file mode 100644 index 4437fe9..0000000 --- a/resources/library-phpcs-ruleset.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - Coding standard for OpenEuropa PHP libraries. - - - - - - - - - - - - - - - - - diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index d43a2c9..ac7b8ec 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -41,10 +41,8 @@ public function getFixture($fixture) */ protected function getContainer($configuration) { - // Create a GrumPHP configuration file to use in the test. Check if a configuration specific file exists, or - // fall back to a generic template file. - $filename = file_exists(__DIR__."/$configuration.yml.dist") ? __DIR__."/$configuration.yml.dist" : __DIR__.'/grumphp.yml.dist'; - $content = file_get_contents($filename); + // Prepare test GrumPHP configuration file. + $content = file_get_contents(__DIR__."/grumphp.yml.dist"); $content = str_replace("{configuration}", $configuration, $content); file_put_contents(__DIR__."/grumphp.yml", $content); diff --git a/tests/DrupalTest.php b/tests/DrupalTest.php index 358b6e5..fcb71fe 100644 --- a/tests/DrupalTest.php +++ b/tests/DrupalTest.php @@ -42,10 +42,10 @@ public function testPhpMessDetector($fixture, $expected) public function commitMessageProvider() { return [ - ['phpmd/correct-code.inc', TaskResult::PASSED], - ['phpmd/correct-code.module', TaskResult::PASSED], - ['phpmd/correct-code.theme', TaskResult::PASSED], - ['phpmd/ignored-code.xxx', TaskResult::SKIPPED], + ['phpmd/correct-code.inc', TaskResult::PASSED], + ['phpmd/correct-code.module', TaskResult::PASSED], + ['phpmd/correct-code.theme', TaskResult::PASSED], + ['phpmd/ignored-code.xxx', TaskResult::SKIPPED], ]; } } diff --git a/tests/GitCommitMessageTest.php b/tests/GitCommitMessageTest.php index 4ffaee3..2601185 100644 --- a/tests/GitCommitMessageTest.php +++ b/tests/GitCommitMessageTest.php @@ -39,10 +39,10 @@ public function testCommitMessage($message, $expected) public function commitMessageProvider() { return [ - ['Issue #3: Nice GitHub commit message.', TaskResult::PASSED], - ['#3: Not nice GitHub commit message.', TaskResult::FAILED], - ['NEPT-123: Nice Jira commit message.', TaskResult::PASSED], - ['Failed message', TaskResult::FAILED], + ['Issue #3: Nice GitHub commit message.', TaskResult::PASSED], + ['#3: Not nice GitHub commit message.', TaskResult::FAILED], + ['NEPT-123: Nice Jira commit message.', TaskResult::PASSED], + ['Failed message', TaskResult::FAILED], ]; } } diff --git a/tests/PhpCodeSnifferTest.php b/tests/PhpCodeSnifferTest.php deleted file mode 100644 index 97a1105..0000000 --- a/tests/PhpCodeSnifferTest.php +++ /dev/null @@ -1,70 +0,0 @@ -getFixture($fixture)]); - $context = new GitPreCommitContext($collection); - $task = $this->getTask('phpcs', $configuration); - $result = $task->run($context); - $this->assertFailures($expected_failures, $this->getFailures($result)); - } - - /** - * Provides test cases for testing the PHP_CodeSniffer task. - * - * @return array - * An array of test data, with the following values: - * - A string containing the filename of the fixture that will be tested for coding standards violations, relative - * to the current directory. - * - A string representing the GrumPHP configuration to use, for example 'library-conventions'. - * - An array of line numbers on which coding standards violations are expected to be detected, keyed by failure - * type (either 'error', or 'warning'). Each value is an array with the line number as key and the number of - * failures that are expected to occur on this line as value. - * - * @see testPhpCodeSnifferTask() - */ - public function phpCodeSnifferTaskProvider() - { - return [ - [ - 'phpcs/incorrect-library-code.php', - 'library-conventions', - [ - 'error' => [ - 8 => 1, - 15 => 1, - 25 => 1, - 32 => 1, - ], - ], - ], - [ - 'phpcs/correct-library-code.php', - 'library-conventions', - [], - ], - ]; - } -} diff --git a/tests/PhpCodeSnifferTestBase.php b/tests/PhpCodeSnifferTestBase.php deleted file mode 100644 index 4957986..0000000 --- a/tests/PhpCodeSnifferTestBase.php +++ /dev/null @@ -1,72 +0,0 @@ -assertEquals($expected_failures[$failure_type], $actual_failures[$failure_type]); - } - } - - /** - * Returns the PHP_CodeSniffer failures that are reported in the given result. - * - * @param TaskResultInterface $result - * The result that has been returned by the PHP_CodeSniffer task executed by GrumPHP. - * - * @return array - * An array of failures, keyed by failure type. Each value is an array with the line number as key and the number - * of expected failures as value. - */ - protected function getFailures(TaskResultInterface $result) - { - $failures = []; - - $output = $result->getMessage(); - foreach (explode("\n", $output) as $line) { - // Skip the lines that do not correspond with an error or warning. - if (preg_match('/\s+(\d+)\s+\|\s+(error|warning)\s+\|.*/i', $line, $matches) !== 1) { - continue; - } - - $line_number = (int) $matches[1]; - $failure_type = strtolower($matches[2]); - - if (!isset($failures[$failure_type][$line_number])) { - $failures[$failure_type][$line_number] = 1; - } else { - $failures[$failure_type][$line_number]++; - } - } - - return $failures; - } -} diff --git a/tests/PhpMessDetectorTest.php b/tests/PhpMessDetectorTest.php index 6ee06e3..5cdf316 100644 --- a/tests/PhpMessDetectorTest.php +++ b/tests/PhpMessDetectorTest.php @@ -39,8 +39,8 @@ public function testPhpCodeMessage($fixture, $expected) public function commitMessageProvider() { return [ - ['phpmd/correct-code.php', TaskResult::PASSED], - ['phpmd/incorrect-code.php', TaskResult::FAILED], + ['phpmd/correct-code.php', TaskResult::PASSED], + ['phpmd/incorrect-code.php', TaskResult::FAILED], ]; } } diff --git a/tests/fixtures/phpcs/correct-library-code.php b/tests/fixtures/phpcs/correct-library-code.php deleted file mode 100644 index d7af2f8..0000000 --- a/tests/fixtures/phpcs/correct-library-code.php +++ /dev/null @@ -1,29 +0,0 @@ - 'append', - ]; - } - - public function aMethodContainingCorrectMultilineStatementIndentation() - { - $this - ->userManager - ->getUser() - ->delete(); - } -} diff --git a/tests/fixtures/phpcs/incorrect-library-code.php b/tests/fixtures/phpcs/incorrect-library-code.php deleted file mode 100644 index d291d81..0000000 --- a/tests/fixtures/phpcs/incorrect-library-code.php +++ /dev/null @@ -1,34 +0,0 @@ - 'append', - ]; - } - - public function aMethodContainingAnIncorrectlyIndentedMultilineStatement() - { - $this->userManager - ->delete(); - } -} diff --git a/tests/library-conventions.yml.dist b/tests/library-conventions.yml.dist deleted file mode 100644 index 99622ed..0000000 --- a/tests/library-conventions.yml.dist +++ /dev/null @@ -1,7 +0,0 @@ -imports: - - { resource: ../dist/{configuration}.yml } - -parameters: - tasks.phpmd.ruleset: - - ./resources/phpmd-ruleset.xml - tasks.phpcs.standard: ./resources/library-phpcs-ruleset.xml