Changeset View
Changeset View
Standalone View
Standalone View
build/arclint/pyrolint/src/ProjectNameLinter.php
- This file was added.
<?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( | |||||
// Error makes it appear even if on an unmodified line, too. | |||||
self::BAD_NAME => ArcanistLintSeverity::SEVERITY_ERROR, | |||||
); | |||||
bb: This might be too strong. | |||||
} | |||||
public function getLintNameMap() { | |||||
return array( | |||||
self::BAD_NAME => pht('Incorrect project name. Notice the non-breaking space in 0!A.D. This could be a false positive, if the project name is used as filesystem path.'), | |||||
); | |||||
Not Done Inline ActionsCan a user silence this then? For us it doesn't matter, since we shouldn't use spaces in filenames. (We probably still do in some cases?) Freagarach: Can a user silence this then? For us it doesn't matter, since we shouldn't use spaces in… | |||||
Done Inline ActionsA user can decide to not run linters. If one does run these linters one can expect false positives. I don't see an easy way to reduce this particular false positive though. It is hard for the linter to tell the difference between a file path in some file and any other srting. Though this should only really happen in generated files. If one uses the space-less name 0ad in a filename it will also show up. this is somewhat likely to happen for ppl who build from source. bb: A user can decide to not run linters. If one does run these linters one can expect false… | |||||
} | |||||
public function lintPath($path) { | |||||
$txt = $this->getData($path); | |||||
$matches = null; | |||||
$preg = preg_match_all( | |||||
"/((?!0!A\\.D\\.)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. This could be a false positive, if the project name is used as filesystem path.'), | |||||
$string); | |||||
} | |||||
} | |||||
} |
Wildfire Games · Phabricator
This might be too strong.