diff --git a/arcanist/linter/AutoPEP8Linter.php b/arcanist/linter/AutoPEP8Linter.php --- a/arcanist/linter/AutoPEP8Linter.php +++ b/arcanist/linter/AutoPEP8Linter.php @@ -26,38 +26,35 @@ } public function getLinterConfigurationOptions() { - $options = array( - ); - + $options = array(); return $options + parent::getLinterConfigurationOptions(); } public function getDefaultBinary() { return 'autopep8'; } - + public function getVersion() { list($stdout, $stderr) = execx('%C --version', $this->getExecutableCommand()); $matches = array(); - + /* Support a.b or a.b.c version numbering scheme */ $regex = '/^autopep8 (?P\d+\.\d+(?:\.\d+)?)/'; - - /* - * Old autopep8 output the version to stdout, newer output to stderr. - * Try both to determine the version. - */ + + /* + * Old autopep8 output the version to stdout, newer output to stderr. + * Try both to determine the version. + */ if (preg_match($regex, $stdout, $matches)) { return $matches['version']; - } + } if (preg_match($regex, $stderr, $matches)) { return $matches['version']; } return false; } - public function getInstallInstructions() { return pht('Make sure autopep8 is in directory specified by $PATH'); @@ -68,8 +65,7 @@ } protected function getMandatoryFlags() { - return array( - ); + return array(); } protected function parseLinterOutput($path, $err, $stdout, $stderr) { @@ -87,16 +83,17 @@ } $message = id(new ArcanistLintMessage()) - ->setPath($path) - ->setLine(1) - ->setChar(1) - ->setGranularity(ArcanistLinter::GRANULARITY_FILE) - ->setCode('CFMT') - ->setSeverity(ArcanistLintSeverity::SEVERITY_AUTOFIX) - ->setName('Code style violation') - ->setDescription("'$path' has code style errors.") - ->setOriginalText($orig) - ->setReplacementText($stdout); + ->setPath($path) + ->setLine(1) + ->setChar(1) + ->setGranularity(ArcanistLinter::GRANULARITY_FILE) + ->setCode('CFMT') + ->setSeverity(ArcanistLintSeverity::SEVERITY_AUTOFIX) + ->setName('Code style violation') + ->setDescription("'$path' has code style errors.") + ->setOriginalText($orig) + ->setReplacementText($stdout); + return array($message); } } diff --git a/arcanist/linter/CheckDocLinter.php b/arcanist/linter/CheckDocLinter.php --- a/arcanist/linter/CheckDocLinter.php +++ b/arcanist/linter/CheckDocLinter.php @@ -26,28 +26,26 @@ } public function getLinterConfigurationOptions() { - $options = array( - ); - + $options = array(); return $options + parent::getLinterConfigurationOptions(); } public function getDefaultBinary() { - return Filesystem::resolvePath( - 'test/lint/check-doc.py', + return Filesystem::resolvePath('test/lint/check-doc.py', $this->getProjectRoot()); } - + public function shouldUseInterpreter() { return true; } - + public function getDefaultInterpreter() { return "python3"; } - + public function getInstallInstructions() { - return pht('The test/lint/check-doc.py script is part of the bitcoin-abc project'); + return pht('The test/lint/check-doc.py script is part of the bitcoin-abc '. + 'project'); } public function shouldExpectCommandErrors() { @@ -55,49 +53,46 @@ } protected function getMandatoryFlags() { - return array( - ); + return array(); } protected function parseLinterOutput($path, $err, $stdout, $stderr) { /* Split stdout: - * 0 => Empty (before first 'Args' occurence) - * 1 => Args used: count - * 2 => Args documented: count - * 3 => Args undocumented: count and list - * 4 => Args unknown: count and list - */ + * 0 => Empty (before first 'Args' occurence) + * 1 => Args used: count + * 2 => Args documented: count + * 3 => Args undocumented: count and list + * 4 => Args unknown: count and list + */ $stdoutExploded = preg_split('/Args/', $stdout); - + $undocumented = $stdoutExploded[3]; $unknown = $stdoutExploded[4]; $messages = array(); - + // Undocumented arguments $match = preg_match_all('/-[\w|-]+/', $undocumented, $args); - foreach($args[0] as $arg) { + foreach ($args[0] as $arg) { $messages[] = id(new ArcanistLintMessage()) - ->setGranularity(ArcanistLinter::GRANULARITY_GLOBAL) - ->setCode('ARGDOC') - ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) - ->setName('Undocumented argument') - ->setDescription("'$arg' is undocumented."); + ->setGranularity(ArcanistLinter::GRANULARITY_GLOBAL) + ->setCode('ARGDOC') + ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) + ->setName('Undocumented argument') + ->setDescription("'$arg' is undocumented."); } - + // Unknown arguments $match = preg_match_all('/-[\w|-]+/', $unknown, $args); - foreach($args[0] as $arg) { - $messages[] = id(new ArcanistLintMessage()) - ->setGranularity(ArcanistLinter::GRANULARITY_GLOBAL) - ->setCode('ARGDOC') - ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) - ->setName('Unknown argument') - ->setDescription("'$arg' is documented but not used."); + foreach ($args[0] as $arg) { + $messages[] = id(new ArcanistLintMessage()) + ->setGranularity(ArcanistLinter::GRANULARITY_GLOBAL) + ->setCode('ARGDOC') + ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) + ->setName('Unknown argument') + ->setDescription("'$arg' is documented but not used."); } return $messages; } } - -?> diff --git a/arcanist/linter/ClangFormatLinter.php b/arcanist/linter/ClangFormatLinter.php --- a/arcanist/linter/ClangFormatLinter.php +++ b/arcanist/linter/ClangFormatLinter.php @@ -26,9 +26,7 @@ } public function getLinterConfigurationOptions() { - $options = array( - ); - + $options = array(); return $options + parent::getLinterConfigurationOptions(); } @@ -57,8 +55,7 @@ } protected function getMandatoryFlags() { - return array( - ); + return array(); } protected function parseLinterOutput($path, $err, $stdout, $stderr) { @@ -76,16 +73,17 @@ } $message = id(new ArcanistLintMessage()) - ->setPath($path) - ->setLine(1) - ->setChar(1) - ->setGranularity(ArcanistLinter::GRANULARITY_FILE) - ->setCode('CFMT') - ->setSeverity(ArcanistLintSeverity::SEVERITY_AUTOFIX) - ->setName('Code style violation') - ->setDescription("'$path' has code style errors.") - ->setOriginalText($orig) - ->setReplacementText($stdout); + ->setPath($path) + ->setLine(1) + ->setChar(1) + ->setGranularity(ArcanistLinter::GRANULARITY_FILE) + ->setCode('CFMT') + ->setSeverity(ArcanistLintSeverity::SEVERITY_AUTOFIX) + ->setName('Code style violation') + ->setDescription("'$path' has code style errors.") + ->setOriginalText($orig) + ->setReplacementText($stdout); + return array($message); } } diff --git a/arcanist/linter/LocalDependenceLinter.php b/arcanist/linter/LocalDependenceLinter.php --- a/arcanist/linter/LocalDependenceLinter.php +++ b/arcanist/linter/LocalDependenceLinter.php @@ -5,7 +5,7 @@ * functions relying on the system locale are used. */ final class LocaleDependenceLinter extends ArcanistExternalLinter { - + const ADVICE_MESSAGE = <<getProjectRoot()); } - + public function shouldUseInterpreter() { return true; } - + public function getDefaultInterpreter() { return "bash"; } - + public function getInstallInstructions() { - return pht('The test/lint/lint-locale-dependence.sh script is part of the - bitcoin-abc project. Requires git >= 2.6.5.'); + return pht('The test/lint/lint-locale-dependence.sh script is part of the '. + 'bitcoin-abc project. Requires git >= 2.6.5.'); } public function shouldExpectCommandErrors() { @@ -63,28 +61,27 @@ } protected function getMandatoryFlags() { - return array( - ); + return array(); } protected function parseLinterOutput($path, $err, $stdout, $stderr) { /* - * Stdout contains 2 sections: - * 1/ The locale dependent function in a sentence: - * The locale dependent function (...) appears to be used - * Followed by the file and the corresponding code lines - * : - * 2/ Section with a general warning, will not be used by Arcanist. Instead - * we define our own advice message. - * - * First a list of the locale dependent functions will be determined, then - * the code lines containing these functions. - * An linting error message is generated for each line of code. - */ - - /* - * Extract infos from the path - */ + * Stdout contains 2 sections: + * 1/ The locale dependent function in a sentence: + * The locale dependent function (...) appears to be used + * Followed by the file and the corresponding code lines + * : + * 2/ Section with a general warning, will not be used by Arcanist. Instead + * we define our own advice message. + * + * First a list of the locale dependent functions will be determined, then + * the code lines containing these functions. + * A linting error message is generated for each line of code. + */ + + /* + * Extract infos from the path + */ $pathinfo = pathinfo($path); $fileName = $pathinfo['basename']; @@ -92,38 +89,48 @@ /* Find the functions */ $pattern = '/The locale dependent function (\w+)\(...\)/'; - if (!preg_match_all($pattern, $stdout, $matches, $flags = PREG_SET_ORDER)) { + if (!preg_match_all( + $pattern, + $stdout, + $matches, + $flags = PREG_SET_ORDER + )) { return $messages; } $functions = []; - foreach($matches as $match) { + foreach ($matches as $match) { $functions[] = $match[1]; } /* Find the code lines */ $pattern = '/'.$fileName.':(\d+): (.+)/'; - if (preg_match_all($pattern, $stdout, $matches, $flags = PREG_SET_ORDER)) { + if (preg_match_all( + $pattern, + $stdout, + $matches, + $flags = PREG_SET_ORDER + )) { foreach ($matches as $match) { list(, $lineNumber, $codeSnippet) = $match; - + /* Determine which function is used */ $functionUsed = ''; - foreach($functions as $function) { - if (strpos($codeSnippet, $function) !== FALSE) { + foreach ($functions as $function) { + if (strpos($codeSnippet, $function) !== false) { $functionUsed = $function; break; } } $messages[] = id(new ArcanistLintMessage()) - ->setGranularity(ArcanistLinter::GRANULARITY_FILE) - ->setCode('LOCALE_DEPENDENCE') - ->setPath($path) - ->setLine($lineNumber) - ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) - ->setName('Locale dependent function '.$functionUsed) - ->setDescription(self::ADVICE_MESSAGE); + ->setGranularity(ArcanistLinter::GRANULARITY_FILE) + ->setCode('LOCALE_DEPENDENCE') + ->setPath($path) + ->setLine($lineNumber) + ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) + ->setName('Locale dependent function '.$functionUsed) + ->setDescription(self::ADVICE_MESSAGE); } } diff --git a/arcanist/linter/PythonFormatLinter.php b/arcanist/linter/PythonFormatLinter.php --- a/arcanist/linter/PythonFormatLinter.php +++ b/arcanist/linter/PythonFormatLinter.php @@ -1,7 +1,7 @@ getProjectRoot()); } - + public function shouldUseInterpreter() { return true; } - + public function getDefaultInterpreter() { return "python3"; } public function getInstallInstructions() { - return pht('The test/lint/lint-python-format.py script is part of the bitcoin-abc project'); + return pht('The test/lint/lint-python-format.py script is part of the '. + 'bitcoin-abc project'); } public function shouldExpectCommandErrors() { @@ -62,14 +61,14 @@ $pattern = '/\((\d+)\) ([\s\S]+?)=> (.+)/'; $found = preg_match_all($pattern, $stdout, $snippets, $flags = PREG_SET_ORDER); - - /* - * Matched snippets $snippets are organized like this: - * [0] The complete mask - * [1] The line number - * [2] The original snippet - * [3] The replacement snippet - */ + + /* + * Matched snippets $snippets are organized like this: + * [0] The complete mask + * [1] The line number + * [2] The original snippet + * [3] The replacement snippet + */ if (!$found) { return array(); @@ -78,18 +77,18 @@ $messages = []; foreach($snippets as $snippet) { $messages[] = id(new ArcanistLintMessage()) - ->setPath($path) - ->setLine($snippet[1]) - ->setChar(1) - ->setGranularity(ArcanistLinter::GRANULARITY_FILE) - ->setCode('PYFMT') - ->setSeverity(ArcanistLintSeverity::SEVERITY_AUTOFIX) - ->setName('Old string format notation') - ->setDescription("'$path' uses old style string formatting.") - ->setOriginalText(rtrim($snippet[2])) - ->setReplacementText($snippet[3]); + ->setPath($path) + ->setLine($snippet[1]) + ->setChar(1) + ->setGranularity(ArcanistLinter::GRANULARITY_FILE) + ->setCode('PYFMT') + ->setSeverity(ArcanistLintSeverity::SEVERITY_AUTOFIX) + ->setName('Old string format notation') + ->setDescription("'$path' uses old style string formatting.") + ->setOriginalText(rtrim($snippet[2])) + ->setReplacementText($snippet[3]); } - + return $messages; } -} \ No newline at end of file +} diff --git a/arcanist/linter/TestsLinter.php b/arcanist/linter/TestsLinter.php --- a/arcanist/linter/TestsLinter.php +++ b/arcanist/linter/TestsLinter.php @@ -15,7 +15,7 @@ public function getInfoDescription() { return pht('Check the unit tests for duplicates and ensure the file name '. - 'matches the boost test suite name.'); + 'matches the boost test suite name.'); } public function getLinterName() { @@ -27,29 +27,26 @@ } public function getLinterConfigurationOptions() { - $options = array( - ); - + $options = array(); return $options + parent::getLinterConfigurationOptions(); } public function getDefaultBinary() { - return Filesystem::resolvePath( - 'test/lint/lint-tests.sh', + return Filesystem::resolvePath('test/lint/lint-tests.sh', $this->getProjectRoot()); } - + public function shouldUseInterpreter() { return true; } - + public function getDefaultInterpreter() { return "bash"; } - + public function getInstallInstructions() { return pht('The test/lint/lint-tests.sh script is part of the bitcoin-abc '. - 'project'); + 'project'); } public function shouldExpectCommandErrors() { @@ -57,26 +54,25 @@ } protected function getMandatoryFlags() { - return array( - ); + return array(); } protected function parseLinterOutput($path, $err, $stdout, $stderr) { /* - * Stdout contains 2 sections: - * 1/ Section with name mismatches, in the form: - * :BOOST_FIXTURE_TEST_SUITE(, ... - * 2/ Section with duplicated test names: - * - */ - - /* - * Extract infos from the path - * - * Note: the files are already filtered by path thanks to the .arclint - * configuration. If the file is not a test, the grep will find nothing and - * there will be no error to parse. - */ + * Stdout contains 2 sections: + * 1/ Section with name mismatches, in the form: + * :BOOST_FIXTURE_TEST_SUITE(, ... + * 2/ Section with duplicated test names: + * + */ + + /* + * Extract infos from the path + * + * Note: the files are already filtered by path thanks to the .arclint + * configuration. If the file is not a test, the grep will find nothing and + * there will be no error to parse. + */ $pathinfo = pathinfo($path); $testName = $pathinfo['filename']; $fileName = $pathinfo['basename']; @@ -88,34 +84,34 @@ $mismatch = preg_match($pattern, $stdout, $matches); if ($mismatch) { - /* - * Expect a single result as we are testing against a single file. - * - $matches[0] contains the full mask - * - $matches[1] contains the captured match - */ + /* + * Expect a single result as we are testing against a single file. + * - $matches[0] contains the full mask + * - $matches[1] contains the captured match + */ if (count($matches) != 2) { throw new Exception( pht('Found multiple matches for a single file, lint-tests.sh output '. - 'is not formatted as expected, aborting.')); + 'is not formatted as expected, aborting.')); } $mismatchName = $matches[1]; $messages[] = id(new ArcanistLintMessage()) - ->setGranularity(ArcanistLinter::GRANULARITY_FILE) - ->setCode('TESTS') - ->setPath($path) - ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) - ->setName('Name mismatch') - ->setDescription( - 'The Boost test suite name must match the file name (set to "'. - $mismatchName.'", should be "'.$testName.'").'); + ->setGranularity(ArcanistLinter::GRANULARITY_FILE) + ->setCode('TESTS') + ->setPath($path) + ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) + ->setName('Name mismatch') + ->setDescription( + 'The Boost test suite name must match the file name (set to "'. + $mismatchName.'", should be "'.$testName.'").'); } - /* - * Search for unicity, searching for test name alone on its line. - * The test name can be whether the one extracted from the file name or the - * one extracted from the BOOST_FIXTURE_TEST_SUITE content. - */ + /* + * Search for unicity, searching for test name alone on its line. + * The test name can be whether the one extracted from the file name or the + * one extracted from the BOOST_FIXTURE_TEST_SUITE content. + */ if ($mismatch) { $pattern = '/^'.$testName.'|'.$mismatchName.'$/'; } else { @@ -125,27 +121,25 @@ $notUnique = preg_match($pattern, $stdout, $matches); /* - * Do not check the number of matches here. - * Because it is a test against unicity, there is a global search which can - * possibly return an output matching our expected test name AND our actual - * test name. This would be weird, but not impossible. - * Just returning an error for the first one is enough, as the linter will - * be rerun after the name is fix and the other match will then eventually - * get catched. - */ + * Do not check the number of matches here. + * Because it is a test against unicity, there is a global search which can + * possibly return an output matching our expected test name AND our actual + * test name. This would be weird, but not impossible. + * Just returning an error for the first one is enough, as the linter will be + * rerun after the name is fix and the other match will then eventually get + * catched. + */ if ($notUnique) { $messages[] = id(new ArcanistLintMessage()) - ->setGranularity(ArcanistLinter::GRANULARITY_FILE) - ->setCode('TESTS') - ->setPath($path) - ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) - ->setName('Duplicated name') - ->setDescription('The test name "'.$matches[0].'" already exists'); + ->setGranularity(ArcanistLinter::GRANULARITY_FILE) + ->setCode('TESTS') + ->setPath($path) + ->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR) + ->setName('Duplicated name') + ->setDescription('The test name "'.$matches[0].'" already exists'); } return $messages; } } - -?>