Add linter rule detecting project name misspellings.

Reviewed By: Freagarach
Differential Revision: D4313
This was SVN commit r27787.
This commit is contained in:
bb 2023-07-27 20:56:52 +00:00
parent e7c5afbc06
commit 654664bbd5
4 changed files with 82 additions and 2 deletions

View File

@ -16,6 +16,9 @@
"5": "disabled"
}
},
"project-name": {
"type": "project-name"
},
"licence-year": {
"type": "licence-year"
},

View File

@ -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.

View File

@ -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',
),
));

View File

@ -0,0 +1,72 @@
<?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) {
$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);
}
}
}