Add hook for non-breaking space in 0 A.D.

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.
This commit is contained in:
Dunedan 2024-08-24 13:08:42 +02:00
parent a44dd59a0c
commit 1f51fcb87f
Signed by untrusted user: Dunedan
GPG Key ID: 885B16854284E0B2
3 changed files with 11 additions and 78 deletions

View File

@ -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?(?<!\\xa0)(A|a)\.(D|d)\.?'
language: pygrep
types: [text]
files: ^binaries/
exclude: (^binaries/data/mods/(mod|public)/art/.*\.xml|\.dae$)

View File

@ -12,7 +12,6 @@ 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',
@ -21,6 +20,5 @@ phutil_register_library_map(array(
'ESLintLinter' => 'ArcanistExternalLinter',
'JenkinsRenderer' => 'ArcanistLintRenderer',
'LicenceYearLinter' => 'ArcanistLinter',
'ProjectNameLinter' => 'ArcanistLinter',
),
));

View File

@ -1,76 +0,0 @@
<?php
/**
* Copyright 2023 Wildfire Games.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Linter for the project name 0 A.D..
*/
final class ProjectNameLinter extends ArcanistLinter {
public function getInfoName() {
return pht('Project Name Linter');
}
public function getLinterName() {
return 'Project Name';
}
public function getLinterConfigurationName() {
return 'project-name';
}
const BAD_NAME = 1;
public function getLintSeverityMap() {
return array(
self::BAD_NAME => 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);
}
}
}