2011-01-09 15:22:25 -08:00
|
|
|
<?php
|
|
|
|
|
2011-02-19 11:36:08 -08:00
|
|
|
/**
|
|
|
|
* Stifles creativity in choosing imaginative file names.
|
|
|
|
*
|
|
|
|
* @group linter
|
|
|
|
*/
|
2012-01-31 12:07:05 -08:00
|
|
|
final class ArcanistFilenameLinter extends ArcanistLinter {
|
2011-01-09 15:22:25 -08:00
|
|
|
|
|
|
|
const LINT_BAD_FILENAME = 1;
|
|
|
|
|
|
|
|
public function willLintPaths(array $paths) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLinterName() {
|
2013-02-19 14:09:20 -08:00
|
|
|
return 'NAME';
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getLintSeverityMap() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
Lay groundwork for configuration-driven linters
Summary:
Ref T2039. That task has a bunch of discussion, but basically we do a poor job of serving the midrange of lint configuration right now.
If you have something simple, the default linters work.
If you have something complex, building your own engine lets you do whatever you want.
But many users want something in between, which isn't really well accommodated. The idea is to let you write a `.arclint` file, which looks something like this:
{
"linters" : {
"css" : {
"type" : "csslint",
"include" : "(\.css$)",
"exclude" : "(^externals/)",
"bin" : "/usr/local/bin/csslint"
},
"js" : {
"type" : "jshint",
"include" : "(\.js$)",
"exclude" : "(^externals/)",
"bin" : "support/bin/jshint",
"interpreter" : "/usr/local/bin/node"
}
}
}
...which will provide a bunch of common options around lint severity, interpreter and binary locaitons, included and excluded files, etc.
This implements some basics, and very rough support in the Filename linter.
Test Plan:
Generated a `.arclint` file and saw it apply filename lint correctly. Used `debug` mode and tried invalid regexps.
{
"debug" : true,
"linters" : {
"filename" : {
"type" : "filename",
"exclude" : ["@^externals/@"]
}
}
}
Next steps include:
- Provide an external linter archetype (T3186) and expose a common set of configuration here ("bin", "interpreter", "flags", "severity").
- Provide a `.arcunit` file which works similarly (it can probably be simpler).
Reviewers: btrahan, Firehed
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2039
Differential Revision: https://secure.phabricator.com/D6797
2013-08-22 16:02:16 -07:00
|
|
|
public function getLinterConfigurationName() {
|
|
|
|
return 'filename';
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
public function getLintNameMap() {
|
|
|
|
return array(
|
|
|
|
self::LINT_BAD_FILENAME => 'Bad Filename',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function lintPath($path) {
|
2012-05-24 10:13:20 +02:00
|
|
|
if (!preg_match('@^[a-z0-9./\\\\_-]+$@i', $path)) {
|
2011-01-09 15:22:25 -08:00
|
|
|
$this->raiseLintAtPath(
|
|
|
|
self::LINT_BAD_FILENAME,
|
|
|
|
'Name files using only letters, numbers, period, hyphen and '.
|
|
|
|
'underscore.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|