Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22422046
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/README.md b/README.md
index 1e8d503..3a01557 100644
--- a/README.md
+++ b/README.md
@@ -1,151 +1,164 @@
# Arcanist Linters
[](https://travis-ci.org/pinterest/arcanist-linters)
This is a collection of custom [Arcanist][] linters that we've written at
Pinterest.
## Linters
### Apache Thrift Linter
Lints for errors in [Apache Thrift][] IDL (schema) files using the `thrift`
compiler.
```json
{
"type": "thrift",
"include": "(\\.thrift$)",
"flags": [
"--allow-64bit-consts"
],
"version": ">= 0.9.0",
"thrift.generators": [
"py:dynamic,utf8strings,new_style,slots",
"java",
"go",
"erl"
],
"thrift.includes": [
".",
"common"
]
}
```
[Apache Thrift]: http://thrift.apache.org/
### Apache Thrift Generated Linter
Lints files generated by the [Apache Thrift][] compiler to ensure they were
generated using a supported Thrift compiler.
```json
{
"type": "thrift-gen",
"include": "(^schemas/.*\\.py$)",
"thrift-gen.version": ">=0.9.3"
}
```
*Note:* Currently only generated Python files are supported.
+### Checkstyle Linter
+
+Uses the [Checkstyle](http://checkstyle.sourceforge.net/) tool to check Java
+code against a coding standard.
+
+```json
+{
+ "type": "checkstyle",
+ "include": "(\\.java$)",
+ "checkstyle.config": "google_check.xml"
+}
+```
+
### Go Vet Linter
Uses the [Go vet command](https://golang.org/cmd/vet/) to lint for suspicious
code constructs.
```json
{
"type": "govet",
"include": "(^src/example.com/.*\\.go$)"
}
```
### Python Imports Linter
Lints for illegal Python module imports.
```json
{
"type": "python-imports",
"python-imports.pattern": "(mock)",
"include": "(\\.py$)",
"exclude": "(^tests/)"
}
```
### Python Requirements Linter
Ensures Python package requirements in [requirements.txt files][req-txt] are
sorted, unique, and pinned to exact versions.
```json
{
"type": "requirements-txt",
"include": "(requirements.txt$)"
}
```
Individual requirement lines can be excluded by adding a `# noqa` comment:
```
six>=1.10.0 # noqa: allow any recent version of six
```
[req-txt]: https://pip.readthedocs.org/en/latest/user_guide/#requirements-files
## Installation
In short, you'll need to add this repository to your local machine and tell
Arcanist to load the extension. You either can do this globally or on a
per-project basis.
Once installed, the individual linters can be enabled and configured via the
project's `.arclint` file. See the [Arcanist Lint User Guide][lint-guide] for
details.
## Global Installation
Arcanist can load modules from an absolute path, but because it also searches
for modules one level up from itself on the filesystem, it's convenient to
clone this repository at the same level as `arcanist` and `libphutil`.
```
$ git clone https://github.com/pinterest/arcanist-linters.git pinterest-linters
$ ls
arcanist
pinterest-linters
libphutil
```
Then, tell Arcanist to load the module by editing `~/.arcconfig` (or
`/etc/arcconfig`):
```json
{
"load": ["pinterest-linters"]
}
```
## Project Installation
You can also load `arcanist-linters` on a per-project basis. In that case,
using a [git submodule](https://git-scm.com/docs/git-submodule) is probably
the most convenient approach.
```
$ git submodule add https://github.com/pinterest/arcanist-linters.git .pinterest-linters
$ git submodule update --init
```
Then, enable the module in your project-level `.arcconfig` file:
```json
{
"load": [".pinterest-linters"]
}
```
[Arcanist]: https://secure.phabricator.com/book/phabricator/article/arcanist/
[lint-guide]: https://secure.phabricator.com/book/phabricator/article/arcanist_lint/
diff --git a/__phutil_library_map__.php b/__phutil_library_map__.php
index 98a4c82..66f4b6e 100644
--- a/__phutil_library_map__.php
+++ b/__phutil_library_map__.php
@@ -1,26 +1,28 @@
<?php
/**
* This file is automatically generated. Use 'arc liberate' to rebuild it.
*
* @generated
* @phutil-library-version 2
*/
phutil_register_library_map(array(
'__library_version__' => 2,
'class' => array(
'ApacheThriftGeneratedLinter' => 'src/ApacheThriftGeneratedLinter.php',
'ApacheThriftLinter' => 'src/ApacheThriftLinter.php',
+ 'CheckstyleLinter' => 'src/CheckstyleLinter.php',
'GoVetLinter' => 'src/GoVetLinter.php',
'PythonImportsLinter' => 'src/PythonImportsLinter.php',
'PythonRequirementsLinter' => 'src/PythonRequirementsLinter.php',
),
'function' => array(),
'xmap' => array(
'ApacheThriftGeneratedLinter' => 'ArcanistLinter',
'ApacheThriftLinter' => 'ArcanistExternalLinter',
+ 'CheckstyleLinter' => 'ArcanistExternalLinter',
'GoVetLinter' => 'ArcanistExternalLinter',
'PythonImportsLinter' => 'ArcanistLinter',
'PythonRequirementsLinter' => 'ArcanistLinter',
),
));
diff --git a/src/CheckstyleLinter.php b/src/CheckstyleLinter.php
new file mode 100644
index 0000000..ab31428
--- /dev/null
+++ b/src/CheckstyleLinter.php
@@ -0,0 +1,136 @@
+<?php
+/**
+ * Copyright 2017 Pinterest, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * Lints Java source files using the "checkstyle" tool.
+ */
+final class CheckstyleLinter extends ArcanistExternalLinter {
+
+ private $config = null;
+
+ public function getInfoName() {
+ return 'Checkstyle Linter';
+ }
+
+ public function getInfoDescription() {
+ return pht('Checks Java files');
+ }
+
+ public function getInfoURI() {
+ return 'http://checkstyle.sourceforge.net/';
+ }
+
+ public function getLinterName() {
+ return 'CHECKSTYLE';
+ }
+
+ public function getLinterConfigurationName() {
+ return 'checkstyle';
+ }
+
+ public function getLinterConfigurationOptions() {
+ $options = array(
+ 'checkstyle.config' => array(
+ 'type' => 'string',
+ 'help' => pht("Configuration file to use."),
+ ),
+ );
+
+ return $options + parent::getLinterConfigurationOptions();
+ }
+
+ public function setLinterConfigurationValue($key, $value) {
+ switch ($key) {
+ case 'checkstyle.config':
+ $this->config = $value;
+ return;
+ }
+
+ return parent::setLinterConfigurationValue($key, $value);
+ }
+
+ public function getDefaultBinary() {
+ return 'checkstyle';
+ }
+
+ public function getVersion() {
+ list($err, $stdout, $stderr) = exec_manual(
+ '%C -v',
+ $this->getExecutableCommand());
+
+ $matches = array();
+ if (preg_match('/^Checkstyle version: (.*)$/', $stdout, $matches)) {
+ return $matches[1];
+ } else {
+ return false;
+ }
+ }
+
+ public function getInstallInstructions() {
+ return pht(
+ 'Install checkstyle using `%s` (macOS) or `%s` (Linux).',
+ 'brew install checkstyle',
+ 'apt-get install checkstyle');
+ }
+
+ protected function getMandatoryFlags() {
+ return array('-c', $this->config);
+ }
+
+ protected function parseLinterOutput($path, $err, $stdout, $stderr) {
+ $lines = phutil_split_lines($stdout, false);
+
+ // [ERROR] /path/to/file.java:31: Message text [Indentation]
+ // [WARN] /path/to/file.java:31:10: Message text [Indentation]
+ $regex = '/^\[(?P<severity>[A-Z]+)\] '.
+ '(?P<path>.*):(?P<line>\d+):(?:(?P<char>\d+):)? '.
+ '(?P<message>.*) \[(?P<type>.*)\]$/';
+
+ $messages = array();
+ foreach ($lines as $line) {
+ $matches = null;
+ if (preg_match($regex, $line, $matches)) {
+ $message = new ArcanistLintMessage();
+ $message->setPath($path);
+ $message->setLine($matches['line']);
+ if (!empty($matches['char'])) {
+ $message->setChar($matches['char']);
+ }
+ $message->setCode($matches['type']);
+ $message->setName($this->getLinterName());
+ $message->setDescription($matches['message']);
+ $message->setSeverity($this->getMatchSeverity($matches['severity']));
+ $messages[] = $message;
+ }
+ }
+
+ return $messages;
+ }
+
+ private function getMatchSeverity($name) {
+ $map = array(
+ 'ERROR' => ArcanistLintSeverity::SEVERITY_ERROR,
+ 'WARN' => ArcanistLintSeverity::SEVERITY_WARNING,
+ );
+
+ if (array_key_exists($name, $map)) {
+ return $map[$name];
+ }
+
+ return ArcanistLintSeverity::SEVERITY_ERROR;
+ }
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Nov 28, 03:16 (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1218216
Default Alt Text
(8 KB)
Attached To
Mode
R124 arcanist-linters
Attached
Detach File
Event Timeline