• Stars
    star
    100
  • Rank 340,703 (Top 7 %)
  • Language Starlark
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

πŸͺ¦ Archived πŸͺ¦

Check out aspect-build/bazel-super-formatter instead.


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

More Repositories

1

example-bazel-monorepo

πŸŒΏπŸ’š Example Bazel-ified monorepo, supporting Golang, Java, Python, Scala, and Typescript
Java
283
star
2

interview-with-python

The ultimate in python interview preparation and coding practice.
Python
193
star
3

google-rules-of-machine-learning

Github mirror of M. Zinkevich's "Rules of Machine Learning" style guide, with extra goodness.
167
star
4

automated-github-organization-invites

Quickly host a webpage allowing people to click and receive an invite to your Github Organization.
Ruby
93
star
5

junior-theme

⚫ A striking black and white theme for Jekyll. Built as a developer blog + portfolio.
JavaScript
70
star
6

awesome-AI-academia

A curated list of academic AI resources and people. Partly an aspirational list, partly a memory aide.
44
star
7

the-general-problem-solver

The General Problem Solver, AI's 'first' algorithm, written in multiple programming languages.
C++
30
star
8

arXie-Bot

arXie is a Slack bot that browses and filters the arXiv repository for you
Python
29
star
9

goodreads-sh

πŸ“™Command line interface for Goodreads.com. Written in Rust.
Rust
28
star
10

thundergolfer.github.io

just my website. πŸŒ©πŸŒπŸΌβ€β™‚οΈ
JavaScript
27
star
11

Insults

Detect whether a social media comment is insulting or derogatory
Python
23
star
12

simplegraphdb

Basic Golang implementation of a Triple Store. Built to learn the Golang language before an internship.
Go
18
star
13

slack-to-pdf

create a PDF report of your team interactions. For university teams
Python
14
star
14

text-classify-with-cnn

🏫 Easy to follow text classifying implementation using a Conv. Neural Network (Tensorflow)
Jupyter Notebook
13
star
15

politifact-py

Python wrapper for the Politifact REST API
Python
13
star
16

reasoning-about-entailment-tensorflow

🏫 Tensorflow implementation of "Reasoning About Entailment with Neural Attention"
Python
10
star
17

uni

A mono-repo containing code I've written to educate myself. est. 2021. (public)
C
9
star
18

sudkamp-langs-machines-java

[WIP] Algorithms from Sudkamps' Languages and Machines - implemented in Java
Java
7
star
19

sudkamp-langs-machines-python

Algorithms from Sudkamps' Languages and Machines - implemented in Python 3
Python
6
star
20

dropbox-style-python-repo

πŸŒΏπŸ’š Learning how the github.com/dropbox/dbx_build_tools work for Python monorepos.
Python
6
star
21

library-management-slack-bot

πŸ“š Slack bot that helps facilitate tracking of books and borrowers in your office/home library
TypeScript
5
star
22

slack-up

Makes daily Slack stand-up message easier to do by automating info-gathering from GCalendar + Github
Rust
3
star
23

fast-links

Painlessly embed references into your online comments and posts. #FB-Hack2017 πŸ₯ˆ
JavaScript
3
star
24

slackify-markdown

#️⃣Convert Markdown into Slack's bastardized Markdown-like formatting
Rust
2
star
25

modal-fun

Modal.com apps doing various interesting things
Python
2
star
26

ghportfolio

A minimal CLI in Golang for catching up on the activity and health of your public Github projects
Go
2
star
27

source-rank

#️⃣FBHack Melbourne 2018 - An open approach to news and media content quality evaluation
JavaScript
2
star
28

dotfiles

Created to personalize Github Codespaces, automagically
1
star
29

homebrew-formulae

β˜•οΈ Personal Homebrew tap for relevant projects under my Github profile
Ruby
1
star