2012-01-28 20:17:10 +01:00
|
|
|
@title Arcanist User Guide: Customizing Existing Linters
|
|
|
|
@group userguide
|
|
|
|
|
|
|
|
Explains how to customize existing linters.
|
|
|
|
|
2012-08-10 21:00:40 +02:00
|
|
|
This is a configuration guide that helps you set up advanced features. If you're
|
|
|
|
just getting started, you don't need to look at this yet. Instead, start with
|
|
|
|
the @{article:Arcanist User Guide}.
|
|
|
|
|
|
|
|
This guide explains how to refine lint behavior. To configure lint in the first
|
|
|
|
place, see @{article:Arcanist User Guide: Configuring a New Project} and
|
|
|
|
@{article:Arcanist User Guide: Lint}.
|
|
|
|
|
2012-01-28 20:17:10 +01:00
|
|
|
= Overview =
|
|
|
|
|
|
|
|
Arcanist ships with a number of linters which you may want to reuse in whole
|
|
|
|
or in part in other projects. This document explains how to customize existing
|
|
|
|
linters for use in new engines.
|
|
|
|
|
2012-06-01 16:55:30 +02:00
|
|
|
First, you should set up an engine by following the instructions in
|
|
|
|
@{article:Arcanist User Guide: Lint} and possibly
|
2012-01-28 20:17:10 +01:00
|
|
|
@{article:Arcanist User Guide: Customizing Lint, Unit Tests and Workflows}.
|
|
|
|
Then, follow this guide to customize linters.
|
|
|
|
|
|
|
|
= General Guidelines =
|
|
|
|
|
|
|
|
You should customize linters by configuring or composing them, not by extending
|
|
|
|
them -- their implementations are not necessarily stable. If a linter's
|
2012-06-01 16:55:30 +02:00
|
|
|
configuration options aren't flexible enough to meet your needs, sending a patch
|
2012-01-28 20:17:10 +01:00
|
|
|
which improves its configurability is better than one that makes it
|
|
|
|
nonfinal.
|
|
|
|
|
|
|
|
= Changing Rule Severities =
|
|
|
|
|
|
|
|
By default, most linters raise lint messages as errors. You may want to reduce
|
|
|
|
the severity of some messages (e.g., reduce errors to warnings). Do this by
|
2015-05-31 02:07:45 +02:00
|
|
|
calling `setCustomSeverityMap()`:
|
2012-01-28 20:17:10 +01:00
|
|
|
|
|
|
|
$linter = new ArcanistTextLinter();
|
|
|
|
|
|
|
|
// Change "missing newline at end of file" message from error to warning.
|
|
|
|
$linter->setCustomSeverityMap(
|
|
|
|
array(
|
|
|
|
ArcanistTextLinter::LINT_EOF_NEWLINE
|
|
|
|
=> ArcanistLintSeverity::SEVERITY_WARNING,
|
|
|
|
));
|
|
|
|
|
|
|
|
See @{class@arcanist:ArcanistLintSeverity} for a list of available severity
|
|
|
|
constants.
|
|
|
|
|
|
|
|
= Disabling Rules =
|
|
|
|
|
2015-05-31 02:07:45 +02:00
|
|
|
To disable rules entirely, set their severities to `SEVERITY_DISABLED`:
|
2012-01-28 20:17:10 +01:00
|
|
|
|
|
|
|
$linter = new ArcanistTextLinter();
|
|
|
|
|
|
|
|
// Disable "Tab Literal" message.
|
|
|
|
$linter->setCustomSeverityMap(
|
|
|
|
array(
|
|
|
|
ArcanistTextLinter::LINT_TAB_LITERAL
|
|
|
|
=> ArcanistLintSeverity::SEVERITY_DISABLED,
|
|
|
|
));
|
|
|
|
|
|
|
|
= Running Multiple Rulesets =
|
|
|
|
|
|
|
|
If you want to run the same linter on different types of files but vary the
|
|
|
|
configuration based on the file type, just instantiate it twice and configure
|
|
|
|
each instance appropriately. For instance, this will enforce different column
|
|
|
|
widths on different languages:
|
|
|
|
|
|
|
|
$linters = array();
|
|
|
|
|
2013-08-28 18:57:00 +02:00
|
|
|
// Warn on JS/CSS lines longer than 80 columns.
|
2012-10-20 16:08:26 +02:00
|
|
|
$linters['TextLinter80Col'] = id(new ArcanistTextLinter())
|
2013-08-28 18:57:00 +02:00
|
|
|
->setPaths(preg_grep('/\.(js|css)$/', $paths));
|
2012-10-20 16:08:26 +02:00
|
|
|
|
2013-08-28 18:57:00 +02:00
|
|
|
// Warn on Java lines longer than 120 columns.
|
2012-10-20 16:08:26 +02:00
|
|
|
$linters['TextLinter120Col'] = id(new ArcanistTextLinter())
|
2013-08-28 18:57:00 +02:00
|
|
|
->setMaxLineLength(120)
|
|
|
|
->setPaths(preg_grep('/\.(java)$/', $paths));
|
2012-01-28 20:17:10 +01:00
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
return $linters;
|
|
|
|
|
|
|
|
= Customizing Specific Linters =
|
|
|
|
|
|
|
|
Some linters are specifically customizable or configurable. Some common
|
|
|
|
options are documented here, consult class documentation for complete
|
|
|
|
information.
|
|
|
|
|
|
|
|
== ArcanistTextLinter ==
|
|
|
|
|
2015-05-31 02:07:45 +02:00
|
|
|
- Use `setMaxLineLength()` to change the 80-column warning to something
|
2012-01-28 20:17:10 +01:00
|
|
|
else.
|
|
|
|
|
|
|
|
== ArcanistXHPASTLinter ==
|
|
|
|
|
2015-05-31 02:07:45 +02:00
|
|
|
- Use `lint.xhpast.naminghook` in `.arcconfig` to override naming
|
2012-01-28 20:17:10 +01:00
|
|
|
convention rules. See @{class@arcanist:ArcanistXHPASTLintNamingHook}
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
for details.
|
2015-05-31 02:07:45 +02:00
|
|
|
- Use `getXHPASTTreeForPath()` to reuse the AAST in other linters.
|