All Projects β†’ thundergolfer β†’ Bazel Linting System

thundergolfer / Bazel Linting System

Licence: apache-2.0
πŸŒΏπŸ’š Experimental system for registering, configuring, and invoking source-code linters in Bazel.

Projects that are alternatives of or similar to Bazel Linting System

Rules docker
Rules for building and handling Docker images with Bazel
Stars: ✭ 744 (+1080.95%)
Mutual labels:  bazel, bazel-rules
rules clojure
Clojure rules for Bazel
Stars: ✭ 27 (-57.14%)
Mutual labels:  bazel, bazel-rules
ios-bazel-users
Resources for using bazel for iOS development
Stars: ✭ 80 (+26.98%)
Mutual labels:  bazel, bazel-rules
Rules codeowners
Bazel rules for generating CODEOWNERS from a workspace.
Stars: ✭ 31 (-50.79%)
Mutual labels:  bazel, bazel-rules
Rules terraform
Bazel rules for using Hashicorp's Terraform in your Bazel builds.
Stars: ✭ 26 (-58.73%)
Mutual labels:  bazel, bazel-rules
rules gwt
Bazel rules for GWT
Stars: ✭ 20 (-68.25%)
Mutual labels:  bazel, bazel-rules
svelte-ts
[WIP] Tools for building Svelte apps with TS
Stars: ✭ 89 (+41.27%)
Mutual labels:  bazel, bazel-rules
rules elm
Bazel rules for building web applications written in Elm
Stars: ✭ 22 (-65.08%)
Mutual labels:  bazel, bazel-rules
Rules go
Go rules for Bazel
Stars: ✭ 852 (+1252.38%)
Mutual labels:  bazel, bazel-rules
Rules typescript
MOVED to https://github.com/bazelbuild/rules_nodejs/tree/3.x/third_party/github.com/bazelbuild/rules_typescript
Stars: ✭ 280 (+344.44%)
Mutual labels:  bazel, bazel-rules
grab-bazel-common
Common rules and macros for Grab's Android projects built with Bazel.
Stars: ✭ 20 (-68.25%)
Mutual labels:  bazel, bazel-rules
Awesome Bazel
A curated list of Bazel rules, tooling and resources.
Stars: ✭ 640 (+915.87%)
Mutual labels:  bazel, bazel-rules
rules verilator
Bazel build rules for Verilator
Stars: ✭ 14 (-77.78%)
Mutual labels:  bazel, bazel-rules
Rules grafana
Bazel rules for building Grafana dashboards
Stars: ✭ 46 (-26.98%)
Mutual labels:  bazel, bazel-rules
rules scala
Robust and featureful Bazel rules for Scala
Stars: ✭ 62 (-1.59%)
Mutual labels:  bazel, bazel-rules
rules poetry
Bazel rules that use Poetry for Python package management
Stars: ✭ 40 (-36.51%)
Mutual labels:  bazel, bazel-rules
rules java
Java rules for Bazel
Stars: ✭ 44 (-30.16%)
Mutual labels:  bazel, bazel-rules
rules helm
rules_helm: Bazel rules for managing helm charts
Stars: ✭ 46 (-26.98%)
Mutual labels:  bazel, bazel-rules
Rules scala
Scala rules for Bazel
Stars: ✭ 269 (+326.98%)
Mutual labels:  bazel, bazel-rules
Rules nodejs
JavaScript and NodeJS rules for Bazel
Stars: ✭ 488 (+674.6%)
Mutual labels:  bazel, bazel-rules

bazel-linting-system

This is an experimental project with the goals of providing a simple tool for linting source code within a polyglot Bazel repo and learning more about aspects.

Will this work with linting tool X?

This project was designed with linters like black and gofmt in mind. Given their behaviour, they're perhaps more accurately called formatters, but to me formatters are a subclass of linters.

If a linting tool restricts itself to only doing evaluation using your source code files, without needing access to any other information like dependencies or compiler-configuration then it will fit nicely into this project. I think of this project's model linter as a pure function from a source code file to a linted source code file: f(source_code: str) -> str.

Now this restriction does allow for things beyond formatting, for example you can check for unused variables, unused imports, or missing return values. But some powerful static analysis tools are outside of project scope, like mypy.

⚠️ Currently linters also must be able to modify source 'in-place'. Thankfully most linters can do this.

Usage

An example Bazel workspace exists in examples, with a lint.sh that runs the registered linters against all source code within the workspace.

Below is further explanation of the constituents of this system.

Setup

Add the following to your WORKSPACE file:

http_archive(
    name = "linting_system",
    sha256 = "",
    strip_prefix = "bazel-linting-system-0.4.0",
    url = "https://github.com/thundergolfer/bazel-linting-system/archive/v0.4.0.zip",
)

load("@linting_system//repositories:repositories.bzl", linting_sys_repositories = "repositories")
linting_sys_repositories()

load("@linting_system//repositories:go_repositories.bzl", linting_sys_deps = "go_deps")
linting_sys_deps()

Create an aspect.bzl extension file in a folder called tools/linting with the following:

load("@linting_system//:generator.bzl", "linting_aspect_generator")

lint = linting_aspect_generator(
    name = "lint",
    linters = [
        "@//tools/linting:python",
    ]
)

"@//tools/linting:python" is a label reference to target in a sibling BUILD file, for example:

load("@linting_system//:rules.bzl", "linter")

package(default_visibility = ['//visibility:public'])

linter(
    name = "python",
    executable_path = "/usr/local/bin/black",
    config = ":configuration/pyproject.toml",
    config_option = "--config",
)

linter targets define a path to the linter executable and optionally a config file for that linter.

⚠️ The name field in the linter rule must exactly match one of the supported languages. The list of supported languages is shown at the top of generator.bzl.

Run with:

bazel build //... \
    --aspects //tools/linting:aspect.bzl%lint \
    --output_groups=report

bazel run @linting_system//apply_changes -- \
  "$(git rev-parse --show-toplevel)" \
  "$(bazel info bazel-genfiles)"

Usually you'll want to wrap up the above in a simple script named something like lint.sh.

You can also add the aspect to your .bazelrc πŸŽ‰:

build --aspects //tools/linting:aspect.bzl%lint
build --output_groups=+report
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].