diff --git a/arcanist/linter/AutoPEP8Linter.php b/arcanist/linter/AutoPEP8Linter.php index 4a6dbcc839..66bddb616d 100644 --- a/arcanist/linter/AutoPEP8Linter.php +++ b/arcanist/linter/AutoPEP8Linter.php @@ -1,102 +1,99 @@ 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. */ 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'); } public function shouldExpectCommandErrors() { return false; } protected function getMandatoryFlags() { - return array( - ); + return array(); } protected function parseLinterOutput($path, $err, $stdout, $stderr) { $ok = ($err == 0); if (!$ok) { return false; } $root = $this->getProjectRoot(); $path = Filesystem::resolvePath($path, $root); $orig = file_get_contents($path); if ($orig == $stdout) { return array(); } $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); + return array($message); } } diff --git a/arcanist/linter/CheckDocLinter.php b/arcanist/linter/CheckDocLinter.php index 8aa722ca99..b70d8b8707 100644 --- a/arcanist/linter/CheckDocLinter.php +++ b/arcanist/linter/CheckDocLinter.php @@ -1,103 +1,98 @@ 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() { return false; } 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 */ $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."); } - + // Unknown arguments $match = preg_match_all('/-[\w|-]+/', $unknown, $args); - foreach($args[0] as $arg) { - $messages[] = id(new ArcanistLintMessage()) + 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 index 7650582d51..efef327b78 100644 --- a/arcanist/linter/ClangFormatLinter.php +++ b/arcanist/linter/ClangFormatLinter.php @@ -1,91 +1,89 @@ getExecutableCommand()); $matches = array(); $regex = '/^clang-format version (?P\d+\.\d+)\./'; if (preg_match($regex, $stdout, $matches)) { return $matches['version']; } else { return false; } } public function getInstallInstructions() { return pht('Make sure clang-format is in directory specified by $PATH'); } public function shouldExpectCommandErrors() { return false; } protected function getMandatoryFlags() { - return array( - ); + return array(); } protected function parseLinterOutput($path, $err, $stdout, $stderr) { $ok = ($err == 0); if (!$ok) { return false; } $root = $this->getProjectRoot(); $path = Filesystem::resolvePath($path, $root); $orig = file_get_contents($path); if ($orig == $stdout) { return array(); } $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); + return array($message); } } diff --git a/arcanist/linter/LocalDependenceLinter.php b/arcanist/linter/LocalDependenceLinter.php index 72a656f680..f81b7645d5 100644 --- a/arcanist/linter/LocalDependenceLinter.php +++ b/arcanist/linter/LocalDependenceLinter.php @@ -1,132 +1,139 @@ 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() { return false; } 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. + * A linting error message is generated for each line of code. */ - /* + /* * Extract infos from the path */ $pathinfo = pathinfo($path); $fileName = $pathinfo['basename']; $messages = []; /* 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); } } return $messages; } } diff --git a/arcanist/linter/PythonFormatLinter.php b/arcanist/linter/PythonFormatLinter.php index 7173535dc4..e928543caf 100644 --- a/arcanist/linter/PythonFormatLinter.php +++ b/arcanist/linter/PythonFormatLinter.php @@ -1,95 +1,94 @@ 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() { return false; } protected function getMandatoryFlags() { return array(); } protected function parseLinterOutput($path, $err, $stdout, $stderr) { $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 */ if (!$found) { return array(); } $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]); } - + return $messages; } -} \ No newline at end of file +} diff --git a/arcanist/linter/TestsLinter.php b/arcanist/linter/TestsLinter.php index 8548fd371c..21ca11fc0a 100644 --- a/arcanist/linter/TestsLinter.php +++ b/arcanist/linter/TestsLinter.php @@ -1,151 +1,145 @@ 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() { return false; } 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. */ $pathinfo = pathinfo($path); $testName = $pathinfo['filename']; $fileName = $pathinfo['basename']; $messages = []; /* Search for mismatch, using the line pattern */ $pattern = '/'.$fileName.':BOOST_FIXTURE_TEST_SUITE\(([\w]+)/'; $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 */ 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.'").'); } - /* + /* * 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 { $pattern = '/^'.$testName.'$/'; } $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 + * 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'); } return $messages; } } - -?>