Add PHPCS checks to the pre-commit hook
This commit adds PHPCS checks, using `./do qa:code-sniffer`, to the pre-commit hook. To be able to do this, I had to modify `./do qa:code-sniffer` to call PHPCS only once and change its signature to accept an optional parameters with the list of files to check. If this parameter is not passed, all files are checked. As discussed with the rest of the team, before we were calling PHPCS multiple times to be able to check for compatibility with different versions of PHP, but as far as we can tell this is not necessary, and we can check for compatibility with PHP >= 7.1 for all files. As far as I know, changing the signature of RoboFile::qaCodeSniffer() is not a problem and I updated the only instance where this method is called. [MAILPOET-3439]
This commit is contained in:
69
RoboFile.php
69
RoboFile.php
@ -350,7 +350,7 @@ class RoboFile extends \Robo\Tasks {
|
||||
$collection = $this->collectionBuilder();
|
||||
$collection->addCode([$this, 'qaLint']);
|
||||
$collection->addCode(function() {
|
||||
return $this->qaCodeSniffer('all');
|
||||
return $this->qaCodeSniffer([], ['severity' => 'all']);
|
||||
});
|
||||
return $collection->run();
|
||||
}
|
||||
@ -374,55 +374,42 @@ class RoboFile extends \Robo\Tasks {
|
||||
return $this->_exec('npm run stylelint-check -- "assets/css/src/**/*.scss"');
|
||||
}
|
||||
|
||||
public function qaCodeSniffer($severity='errors') {
|
||||
$severityFlag = $severity === 'all' ? '-w' : '-n';
|
||||
public function qaCodeSniffer(array $filesToCheck, $opts = ['severity' => 'errors']) {
|
||||
$severityFlag = $opts['severity'] === 'all' ? '-w' : '-n';
|
||||
$task = implode(' ', [
|
||||
'./tasks/code_sniffer/vendor/bin/phpcs',
|
||||
'--extensions=php',
|
||||
$severityFlag,
|
||||
'--standard=tasks/code_sniffer/MailPoet',
|
||||
]);
|
||||
$foldersToIgnore = [
|
||||
'assets',
|
||||
'doc',
|
||||
'generated',
|
||||
'lib/Config/PopulatorData/Templates',
|
||||
'lib-3rd-party',
|
||||
'node_modules',
|
||||
'plugin_repository',
|
||||
'prefixer/build',
|
||||
'prefixer/vendor',
|
||||
'tasks/code_sniffer/vendor',
|
||||
'tasks/phpstan/vendor',
|
||||
'tasks/makepot',
|
||||
'tools/vendor',
|
||||
'tests/_data',
|
||||
'tests/_output',
|
||||
'tests/_support/_generated',
|
||||
'vendor',
|
||||
'vendor-prefixed',
|
||||
'views',
|
||||
];
|
||||
$stringFilesToCheck = !empty($filesToCheck) ? implode(' ', $filesToCheck) : '.';
|
||||
|
||||
return $this->collectionBuilder()
|
||||
|
||||
// PHP >= 7.1 for lib & tests
|
||||
return $this
|
||||
->taskExec($task)
|
||||
->rawArg('--runtime-set testVersion 7.1-8.0')
|
||||
->arg('--ignore=' . implode(',', [
|
||||
'lib/Config/PopulatorData/Templates',
|
||||
'tests/_data',
|
||||
'tests/_output',
|
||||
'tests/_support/_generated',
|
||||
])
|
||||
)
|
||||
->args([
|
||||
'lib',
|
||||
'tests',
|
||||
])
|
||||
|
||||
// PHP >= 7.1 in plugin root directory
|
||||
->taskExec($task)
|
||||
->rawArg('--runtime-set testVersion 7.1-8.0')
|
||||
->rawArg('-l .')
|
||||
|
||||
// PHP >= 7.2 for dev tools, etc.
|
||||
->taskExec($task)
|
||||
->rawArg('--runtime-set testVersion 7.2-8.0')
|
||||
->arg('--ignore=' . implode(',', [
|
||||
'prefixer/build',
|
||||
'prefixer/vendor',
|
||||
'tasks/code_sniffer/vendor',
|
||||
'tasks/phpstan/vendor',
|
||||
'tasks/makepot',
|
||||
'tools/vendor',
|
||||
])
|
||||
)
|
||||
->args([
|
||||
'.circleci',
|
||||
'prefixer',
|
||||
'tasks',
|
||||
'tools',
|
||||
])
|
||||
->arg('--ignore=' . implode(',', $foldersToIgnore))
|
||||
->rawArg($stringFilesToCheck)
|
||||
->run();
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
"*.js": "eslint -c .eslintrc.es5.json --ignore-pattern helpscout.js --max-warnings 0",
|
||||
"*.jsx": "eslint -c .eslintrc.es6.json --max-warnings 0",
|
||||
"*.{tsx,ts}": "eslint -c .eslintrc.ts.json --max-warnings 0",
|
||||
"*.php": "phplint"
|
||||
"*.php": ["phplint", "./do qa:code-sniffer"]
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
|
Reference in New Issue
Block a user