Index: ps/trunk/.arclint =================================================================== --- ps/trunk/.arclint +++ ps/trunk/.arclint @@ -16,6 +16,9 @@ "5": "disabled" } }, + "project-name": { + "type": "project-name" + }, "licence-year": { "type": "licence-year" }, Index: ps/trunk/build/arclint/README.md =================================================================== --- ps/trunk/build/arclint/README.md +++ ps/trunk/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. Index: ps/trunk/build/arclint/pyrolint/__phutil_library_map__.php =================================================================== --- ps/trunk/build/arclint/pyrolint/__phutil_library_map__.php +++ ps/trunk/build/arclint/pyrolint/__phutil_library_map__.php @@ -12,11 +12,15 @@ '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', ), )); Index: ps/trunk/build/arclint/pyrolint/src/ProjectNameLinter.php =================================================================== --- ps/trunk/build/arclint/pyrolint/src/ProjectNameLinter.php +++ ps/trunk/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); + } + } +}