1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-02-04 19:08:27 +01:00
phorge-arcanist/src/lint/linter/ArcanistFilenameLinter.php

57 lines
1.2 KiB
PHP
Raw Normal View History

2011-01-09 15:22:25 -08:00
<?php
/**
* Stifles creativity in choosing imaginative file names.
*/
final class ArcanistFilenameLinter extends ArcanistLinter {
2011-01-09 15:22:25 -08:00
const LINT_BAD_FILENAME = 1;
public function getInfoName() {
return pht('Filename');
}
public function getInfoDescription() {
return pht(
'Stifles developer creativity by requiring files have uninspired names '.
'containing only letters, numbers, period, hyphen and underscore.');
}
2011-01-09 15:22:25 -08:00
public function getLinterName() {
return 'NAME';
2011-01-09 15:22:25 -08:00
}
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';
}
Ready more linters and linter functions for .arclint Summary: Ref T3186. Ref T2039. Continues work on readying linters for `.arclint`. - **Ruby**: Make this an ExternalLinter. - **Priority**: Currently, linters have an implicit "correct" order (notably, the "NoLint" linter needs to run before other linters). Make this explicit by introducing `getLinterPriority()`. - **Binaries**: Currently, linters manually reject binary files. Instead, reject binary files by default (linters can override this if they do want to lint binary files). - **Deleted Files**: Currently, linters manually reject deleted files (usually in engines). Instead, reject deleted files by default (linters can override this). - **Severity**: Move this `.arclint` config option up to top level. - **willLintPaths()**: This method is abstract, but almost all linters provide a trivial implementation. Provide a trivial implementation in the base class. - **getLintSeverityMap()/getLintNameMap()**: A bunch of linters have empty implementations; these are redundant. Remove them. - **Spelling**: clean up some dead / test-only / unconventional code. - **`.arclint`**: Allow the filename, generated, nolint, text, spelling and ruby linters to be configured via `.arclint`. Test Plan: https://github.com/epriestley/arclint-examples/commit/458beca3d65b64d52ed612904ae66eb837118b94 Ran unit tests. Reviewers: btrahan Reviewed By: btrahan CC: Firehed, aran Maniphest Tasks: T2039, T3186 Differential Revision: https://secure.phabricator.com/D6805
2013-08-26 05:37:10 -07:00
public function shouldLintBinaryFiles() {
return true;
}
2011-01-09 15:22:25 -08:00
public function getLintNameMap() {
return array(
self::LINT_BAD_FILENAME => pht('Bad Filename'),
2011-01-09 15:22:25 -08:00
);
}
public function lintPath($path) {
if (!preg_match('@^[a-z0-9./\\\\_-]+$@i', $path)) {
2011-01-09 15:22:25 -08:00
$this->raiseLintAtPath(
self::LINT_BAD_FILENAME,
Ready more linters and linter functions for .arclint Summary: Ref T3186. Ref T2039. Continues work on readying linters for `.arclint`. - **Ruby**: Make this an ExternalLinter. - **Priority**: Currently, linters have an implicit "correct" order (notably, the "NoLint" linter needs to run before other linters). Make this explicit by introducing `getLinterPriority()`. - **Binaries**: Currently, linters manually reject binary files. Instead, reject binary files by default (linters can override this if they do want to lint binary files). - **Deleted Files**: Currently, linters manually reject deleted files (usually in engines). Instead, reject deleted files by default (linters can override this). - **Severity**: Move this `.arclint` config option up to top level. - **willLintPaths()**: This method is abstract, but almost all linters provide a trivial implementation. Provide a trivial implementation in the base class. - **getLintSeverityMap()/getLintNameMap()**: A bunch of linters have empty implementations; these are redundant. Remove them. - **Spelling**: clean up some dead / test-only / unconventional code. - **`.arclint`**: Allow the filename, generated, nolint, text, spelling and ruby linters to be configured via `.arclint`. Test Plan: https://github.com/epriestley/arclint-examples/commit/458beca3d65b64d52ed612904ae66eb837118b94 Ran unit tests. Reviewers: btrahan Reviewed By: btrahan CC: Firehed, aran Maniphest Tasks: T2039, T3186 Differential Revision: https://secure.phabricator.com/D6805
2013-08-26 05:37:10 -07:00
pht(
'Name files using only letters, numbers, period, hyphen and '.
'underscore.'));
2011-01-09 15:22:25 -08:00
}
}
public function shouldLintDirectories() {
return true;
}
public function shouldLintSymbolicLinks() {
return true;
}
2011-01-09 15:22:25 -08:00
}