From 5cb9e32b73cbdf156d192f51106160db2a18ac70 Mon Sep 17 00:00:00 2001 From: bb Date: Thu, 27 Jul 2023 20:56:52 +0000 Subject: [PATCH] Add linter rule detecting project name misspellings. Reviewed By: Freagarach Differential Revision: D4313 This was SVN commit r27787. --- .arclint | 3 + build/arclint/README.md | 3 +- .../pyrolint/__phutil_library_map__.php | 6 +- .../pyrolint/src/ProjectNameLinter.php | 72 +++++++++++++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 build/arclint/pyrolint/src/ProjectNameLinter.php diff --git a/.arclint b/.arclint index d9ecad8411..addc172f80 100644 --- a/.arclint +++ b/.arclint @@ -16,6 +16,9 @@ "5": "disabled" } }, + "project-name": { + "type": "project-name" + }, "licence-year": { "type": "licence-year" }, diff --git a/build/arclint/README.md b/build/arclint/README.md index 4275eb8cda..65cb319945 100644 --- a/build/arclint/README.md +++ b/build/arclint/README.md @@ -1,12 +1,13 @@ # Linting -This folder tools for linting 0 A.D. code +This folder contains tools for linting 0 A.D. code Linting is done via Arcanist: https://secure.phabricator.com/book/phabricator/article/arcanist_lint/ ## Linters - `text` is configured to detect whitespace issues. - `json` detects JSON syntax errors. +- `project-name` detects misspellings of the project name "0 A.D.". In particular the non-breaking space. - `licence-year` detects Copyright header years and compares against modification time. - `eslint`, if installed, will run on javascript files. - `cppcheck`, if installed, will run on C++ files. diff --git a/build/arclint/pyrolint/__phutil_library_map__.php b/build/arclint/pyrolint/__phutil_library_map__.php index bfe9eade05..98f4868867 100644 --- a/build/arclint/pyrolint/__phutil_library_map__.php +++ b/build/arclint/pyrolint/__phutil_library_map__.php @@ -12,11 +12,15 @@ phutil_register_library_map(array( 'ESLintLinter' => 'src/ESLintLinter.php', 'JenkinsRenderer' => 'src/JenkinsRenderer.php', 'LicenceYearLinter' => 'src/LicenceYearLinter.php', + 'ProjectNameLinter' => 'src/ProjectNameLinter.php', + ), + 'function' => array( + 'remove_null' => 'src/JenkinsRenderer.php', ), - 'function' => array(), 'xmap' => array( 'ESLintLinter' => 'ArcanistExternalLinter', 'JenkinsRenderer' => 'ArcanistLintRenderer', 'LicenceYearLinter' => 'ArcanistLinter', + 'ProjectNameLinter' => 'ArcanistLinter', ), )); diff --git a/build/arclint/pyrolint/src/ProjectNameLinter.php b/build/arclint/pyrolint/src/ProjectNameLinter.php new file mode 100644 index 0000000000..c299d8ac29 --- /dev/null +++ b/build/arclint/pyrolint/src/ProjectNameLinter.php @@ -0,0 +1,72 @@ + ArcanistLintSeverity::SEVERITY_WARNING, + ); + } + + public function getLintNameMap() { + return array( + self::BAD_NAME => pht('Incorrect project name. Notice the non-breaking space in 0 A.D.'), + ); + } + + public function lintPath($path) { + $txt = $this->getData($path); + + $matches = null; + $preg = preg_match_all( + "/((?!0 A\\.D\\.|0ad)0\\s?(?:A|a)\\.?(?:D|d)\\.?)/", + $txt, + $matches, + PREG_OFFSET_CAPTURE); + + if (!$preg) { + return; + } + + foreach ($matches[0] as $match) { + list($string, $offset) = $match; + $this->raiseLintAtOffset( + $offset, + self::BAD_NAME, + pht('Incorrect project name. Notice the non-breaking space in 0 A.D.'), + $string); + } + } +}