Add linter rule detecting project name misspellings.
Reviewed By: Freagarach Differential Revision: D4313 This was SVN commit r27787.
This commit is contained in:
parent
157c6af18e
commit
5cb9e32b73
3
.arclint
3
.arclint
@ -16,6 +16,9 @@
|
|||||||
"5": "disabled"
|
"5": "disabled"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"project-name": {
|
||||||
|
"type": "project-name"
|
||||||
|
},
|
||||||
"licence-year": {
|
"licence-year": {
|
||||||
"type": "licence-year"
|
"type": "licence-year"
|
||||||
},
|
},
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
# Linting
|
# 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/
|
Linting is done via Arcanist: https://secure.phabricator.com/book/phabricator/article/arcanist_lint/
|
||||||
|
|
||||||
## Linters
|
## Linters
|
||||||
|
|
||||||
- `text` is configured to detect whitespace issues.
|
- `text` is configured to detect whitespace issues.
|
||||||
- `json` detects JSON syntax errors.
|
- `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.
|
- `licence-year` detects Copyright header years and compares against modification time.
|
||||||
- `eslint`, if installed, will run on javascript files.
|
- `eslint`, if installed, will run on javascript files.
|
||||||
- `cppcheck`, if installed, will run on C++ files.
|
- `cppcheck`, if installed, will run on C++ files.
|
||||||
|
@ -12,11 +12,15 @@ phutil_register_library_map(array(
|
|||||||
'ESLintLinter' => 'src/ESLintLinter.php',
|
'ESLintLinter' => 'src/ESLintLinter.php',
|
||||||
'JenkinsRenderer' => 'src/JenkinsRenderer.php',
|
'JenkinsRenderer' => 'src/JenkinsRenderer.php',
|
||||||
'LicenceYearLinter' => 'src/LicenceYearLinter.php',
|
'LicenceYearLinter' => 'src/LicenceYearLinter.php',
|
||||||
|
'ProjectNameLinter' => 'src/ProjectNameLinter.php',
|
||||||
|
),
|
||||||
|
'function' => array(
|
||||||
|
'remove_null' => 'src/JenkinsRenderer.php',
|
||||||
),
|
),
|
||||||
'function' => array(),
|
|
||||||
'xmap' => array(
|
'xmap' => array(
|
||||||
'ESLintLinter' => 'ArcanistExternalLinter',
|
'ESLintLinter' => 'ArcanistExternalLinter',
|
||||||
'JenkinsRenderer' => 'ArcanistLintRenderer',
|
'JenkinsRenderer' => 'ArcanistLintRenderer',
|
||||||
'LicenceYearLinter' => 'ArcanistLinter',
|
'LicenceYearLinter' => 'ArcanistLinter',
|
||||||
|
'ProjectNameLinter' => 'ArcanistLinter',
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
72
build/arclint/pyrolint/src/ProjectNameLinter.php
Normal file
72
build/arclint/pyrolint/src/ProjectNameLinter.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user