This is a collection of custom Arcanist linters that we've written at Pinterest.
- Apache Thrift
- Apache Thrift Generated
- Black
- Checkstyle
- ESLint
- Flake8
- Flawfinder
- Go Vet
- GraphQL Schema Linter
- OpenAPI Validator
- Prettier
- Prettier ESLint
- Pylint
- Pyright
- Python Imports
- Python isort
- Python Requirements
- Spectral
- Squawk
- ThriftCheck
- YamlLinter
We also welcome additional contributions.
Lints for errors in Apache Thrift IDL (schema) files using the thrift
compiler.
{
"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"
]
}
Lints files generated by the Apache Thrift compiler to ensure they were generated using a supported Thrift compiler.
{
"type": "thrift-gen",
"include": "(^schemas/.*\\.py$)",
"thrift-gen.version": ">=0.9.3"
}
Note: Currently only generated Python files are supported.
Uses the Black opinionated code formatter to normalize the format of Python code.
{
"type": "black",
"include": "(\\.py$)",
"flags": ["-S", "--line-length=132"]
}
Uses the Checkstyle tool to check Java code against a coding standard.
{
"type": "checkstyle",
"include": "(\\.java$)",
"checkstyle.config": "google_check.xml"
}
Lints JavaScript and JSX files using ESLint.
{
"type": "eslint",
"include": "(\\.js$)",
"bin": "./node_modules/.bin/eslint",
"eslint.config": "~/my-eslint.json",
"eslint.env": "browser,node"
}
Lints Python source files using Flake8. This is an
extended version of the stock ArcanistFlake8Linter
that adds support for
checking required Python and extension versions.
{
"type": "flake8ext",
"include": "(\\.py$)",
"flake8.python": "< 3.0",
"flake8.extensions": {
"assertive": "1.0.1",
"naming": "0.7.0"
}
}
Lints C/C++ source files using flawfinder.
{
"type": "flawfinder",
"include": "(\\.(c|cc|cpp|h)$)"
}
Lint GraphQL Schema Definition Language (SDL) using graphql-schema-linter.
{
"type": "graphql-schema",
"include": "(\\.(graphql|gql)$)",
"graphql-schema.rules": [
"fields-have-descriptions",
"types-have-descriptions"
],
"graphql-schema.config": "config",
"graphql-schema.custom-rules": [
"config/custom-rules/*.js",
"vendor/extra-graphql-rules/*.js"
],
"graphql-schema.ignore": {
"fields-have-descriptions": [
"Obvious",
"Query.obvious",
"Query.something.obvious"
]
},
"graphql-schema.comment-descriptions": false,
"graphql-schema.old-implements-syntax": false,
"graphql-schema.dependencies": {
"@pinterest/graphql-lint-rules": "1.0.0"
}
}
Uses the Go vet command to lint for suspicious code constructs.
{
"type": "govet",
"include": "(^src/example.com/.*\\.go$)"
}
Lint OpenAPI specifications using openapi-validator.
(Supports openapi-validator version 0.36.0 and later.)
{
"type": "openapi-spec",
"version": ">=0.36.0",
"openapi-spec.config": ".validaterc",
"openapi-spec.debug": false,
"openapi-spec.errors_only": true,
"include": [
"(\\.yaml$)"
]
}
Formats JavaScript using Prettier.
{
"type": "prettier",
"include": "(\\.js$)",
"bin": "./node_modules/.bin/prettier",
"prettier.cwd": "./"
}
Formats JavaScript using Prettier and then fixes with ESLint.
{
"type": "prettier-eslint",
"include": "(\\.js$)",
"bin": "./node_modules/.bin/prettier-eslint",
"prettier-eslint.cwd": "./"
}
Lints for illegal Python module imports.
{
"type": "python-imports",
"python-imports.pattern": "(mock)",
"include": "(\\.py$)",
"exclude": "(^tests/)"
}
Lints Python imports using isort.
{
"type": "isort",
"include": "(\\.py$)"
}
Lints Python using pylint. Unlike the module that ships with Arcanist, this implementation works with recent releases of Pylint and also supports virtual environments.
{
"type": "pinterest-pylint",
"include": "(\\.py$)"
}
Type-checks Python code using Pyright.
{
"type": "pyright",
"include": "(\\.py$)"
}
Ensures Python package requirements in requirements.txt files are sorted, unique, and pinned to exact versions.
{
"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
Lints OpenAPI documents using Spectral.
{
"type": "spectral",
"include": "(openapi.yaml)",
"spectral.ruleset": ".spectral.yml",
}
Lints SQL files using Squawk.
{
"type": "squawk",
"include": "(\\.sql)",
"squawk.config": ".squawk.toml"
}
Lints Thrift IDL files using ThriftCheck.
{
"type": "thriftcheck",
"include": "(\\.thrift$)",
"thriftcheck.config": ".thriftcheck.toml",
"thriftcheck.includes": [
".",
"common"
]
}
Lints YAML files using YamlLinter.
{
"type": "yamllint",
"include": "(\\.(yml|yaml)$)",
"exclude": []
}
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 for
details.
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
):
{
"load": ["pinterest-linters"]
}
You can also load arcanist-linters
on a per-project basis. In that case,
using a 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:
{
"load": [".pinterest-linters"]
}