From 1f51fcb87f6099cfd6c04c9d8e4ae91033dcb82e Mon Sep 17 00:00:00 2001 From: Dunedan Date: Sat, 24 Aug 2024 13:08:42 +0200 Subject: [PATCH] =?UTF-8?q?Add=20hook=20for=20non-breaking=20space=20in=20?= =?UTF-8?q?0=C2=A0A.D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This replaces the existing arclint linter to ensure the project name does only include a non-breaking space with a pre-commit hook. The regex to check is slightly different to account for escaped non-breaking spaces in JavaScript files and to avoid some false-positives. --- .pre-commit-config.yaml | 11 +++ .../pyrolint/__phutil_library_map__.php | 2 - .../pyrolint/src/ProjectNameLinter.php | 76 ------------------- 3 files changed, 11 insertions(+), 78 deletions(-) delete mode 100644 build/arclint/pyrolint/src/ProjectNameLinter.php diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fd58227677..ed03308d0e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,3 +13,14 @@ repos: - --target-version - py311 exclude: ^source/tools/webservices/ + - repo: local + hooks: + - id: non-breaking-space-in-0ad + name: check for non-breaking space in "0 A.D." + description: | + Verify a non-breaking spaces is used in the project name ("0 A.D"). + entry: '0(?!(\xc2\xa0|\\xa0)A\.D\.)\s?(? 'src/ESLintLinter.php', 'JenkinsRenderer' => 'src/JenkinsRenderer.php', 'LicenceYearLinter' => 'src/LicenceYearLinter.php', - 'ProjectNameLinter' => 'src/ProjectNameLinter.php', ), 'function' => array( 'remove_null' => 'src/JenkinsRenderer.php', @@ -21,6 +20,5 @@ phutil_register_library_map(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 deleted file mode 100644 index 7bd5b5d0ff..0000000000 --- a/build/arclint/pyrolint/src/ProjectNameLinter.php +++ /dev/null @@ -1,76 +0,0 @@ - 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) { - $binaries_prefix = "binaries"; - if (substr($path, 0, strlen($binaries_prefix)) != $binaries_prefix) { - return; - } - $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); - } - } -}