Skip to content

febrianyuwono/arcanist-linters

 
 

Repository files navigation

Arcanist Linters

This is a collection of custom Arcanist linters that we've written at Pinterest.

We also welcome additional contributions.

Linters

Apache Thrift

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"
    ]
}

Apache Thrift Generated

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.

Black

Uses the Black opinionated code formatter to normalize the format of Python code.

{
    "type": "black",
    "include": "(\\.py$)",
    "flags": ["-S", "--line-length=132"]
}

Checkstyle

Uses the Checkstyle tool to check Java code against a coding standard.

{
    "type": "checkstyle",
    "include": "(\\.java$)",
    "checkstyle.config": "google_check.xml"
}

ESLint

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"
}

Flake8

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"
    }
}

Flawfinder

Lints C/C++ source files using flawfinder.

{
    "type": "flawfinder",
    "include": "(\\.(c|cc|cpp|h)$)"
}

GraphQL Schema Linter

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"
    }
}

Go Vet

Uses the Go vet command to lint for suspicious code constructs.

{
    "type": "govet",
    "include": "(^src/example.com/.*\\.go$)"
}

OpenAPI Validator

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$)"
    ]
}

Prettier

Formats JavaScript using Prettier.

{
    "type": "prettier",
    "include": "(\\.js$)",
    "bin": "./node_modules/.bin/prettier",
    "prettier.cwd": "./"
}

Prettier ESLint

Formats JavaScript using Prettier and then fixes with ESLint.

{
    "type": "prettier-eslint",
    "include": "(\\.js$)",
    "bin": "./node_modules/.bin/prettier-eslint",
    "prettier-eslint.cwd": "./"
}

Python Imports

Lints for illegal Python module imports.

{
    "type": "python-imports",
    "python-imports.pattern": "(mock)",
    "include": "(\\.py$)",
    "exclude": "(^tests/)"
}

Python isort

Lints Python imports using isort.

{
    "type": "isort",
    "include": "(\\.py$)"
}

Pylint

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$)"
}

Pyright

Type-checks Python code using Pyright.

{
    "type": "pyright",
    "include": "(\\.py$)"
}

Python Requirements

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

Spectral

Lints OpenAPI documents using Spectral.

{
    "type": "spectral",
    "include": "(openapi.yaml)",
    "spectral.ruleset": ".spectral.yml",
}

ThriftCheck

Lints Thrift IDL files using ThriftCheck.

{
    "type": "thriftcheck",
    "include": "(\\.thrift$)",
    "thriftcheck.config": ".thriftcheck.toml",
    "thriftcheck.includes": [
        ".",
        "common"
    ]
}

YamlLinter

Lints YAML files using YamlLinter.

{
    "type": "yamllint",
    "include": "(\\.(yml|yaml)$)",
    "exclude": []
}

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 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):

{
  "load": ["pinterest-linters"]
}

Project Installation

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"]
}

About

A collection of custom Arcanist linters

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 99.9%
  • Shell 0.1%