Skip to content

Commit f153e8e

Browse files
authored
chore: update docs for 1.0 (#190)
* chore: update docs for 1.0 * chore: fix in-flight collision making main red
1 parent 1d9b65d commit f153e8e

File tree

4 files changed

+65
-48
lines changed

4 files changed

+65
-48
lines changed

README.md

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,11 @@ Features:
99
Instead, users simply lint their existing `*_library` targets.
1010
- Lint checks and fixes are run as normal Bazel actions, which means they support Remote Execution and the outputs are stored in the Remote Cache.
1111
- Lint results can be **presented in various ways**, such as Code Review comments or failing tests.
12-
See [Usage](https://github.com/aspect-build/rules_lint/blob/main/docs/linting.md#usage) below.
12+
See [Usage](https://github.com/aspect-build/rules_lint/blob/main/docs/linting.md#usage).
1313
- **Can format files not known to Bazel**. Formatting just runs directly on the file tree.
1414
No need to create `sh_library` targets for your shell scripts, for example.
1515
- Honors the same configuration files you use for these tools outside Bazel (e.g. in the editor)
1616

17-
This project is inspired by the design for [Tricorder].
18-
This is how Googlers get their static analysis results in code review (Critique).
19-
https://github.com/google/shipshape is an old, abandoned attempt to open-source Tricorder.
20-
It is also inspired by <https://github.com/github/super-linter>.
21-
22-
[aspect cli]: https://docs.aspect.build/v/cli
23-
[tricorder]: https://static.googleusercontent.com/media/research.google.com/en/pubs/archive/43322.pdf
24-
[reviewdog]: https://github.com/reviewdog/reviewdog
25-
2617
## Supported tools
2718

2819
| Language | Formatter | Linter(s) |
@@ -82,9 +73,14 @@ Thanks!!
8273

8374
> We'll add documentation on adding formatters as well.
8475
85-
## Design
76+
## Installation
8677

87-
Formatting and Linting work a bit differently.
78+
Follow instructions from the release you wish to use:
79+
<https://github.com/aspect-build/rules_lint/releases>
80+
81+
## Usage
82+
83+
Formatting and Linting are inherently different, which leads to differences in how they are used in rules_lint.
8884

8985
| Formatter | Linter |
9086
| ----------------------------------------------------------------- | ------------------------------------------------------ |
@@ -96,49 +92,25 @@ Formatting and Linting work a bit differently.
9692
| Can always format just changed files / regions | New violations might be introduced in unchanged files. |
9793
| Fast enough to put in a pre-commit workflow. | Some are slow. |
9894

99-
This leads to some minor differences in how they are used in rules_lint.
100-
101-
We treat type-checkers as a build tool, not as a linter. This is for a few reasons:
102-
103-
- They are commonly distributed along with compilers.
104-
In compiled languages like Java, types are required in order for the compiler to emit executable bytecode at all.
105-
In interpreted languages they're still often linked, e.g. TypeScript does both "compiling" to JavaScript and also type-checking.
106-
This suggests that rules for a language should include the type-checker,
107-
e.g. we expect Sorbet to be integrated with rules_ruby.
108-
- We think most developers want "error" semantics for type-checks:
109-
the whole repository should successfully type-check or you cannot commit the change.
110-
rules_lint is optimized for "warning" semantics, where we produce report files and it's up to the
111-
Dev Infra team how to present those, for example only on changed files.
112-
- You can only type-check a library if its dependencies were checkable, which means short-circuiting
113-
execution. rules_lint currently runs linters on every node in the dependency graph, including any
114-
whose dependencies have lint warnings.
115-
116-
## Installation
117-
118-
Follow instructions from the release you wish to use:
119-
<https://github.com/aspect-build/rules_lint/releases>
120-
121-
## Usage
122-
12395
### Format
12496

12597
To format files, run the target you create when you install rules_lint.
12698

127-
We recommend using a Git pre-commit hook to format changed files, by running `bazel run //:format [changed file ...]`.
99+
We recommend using a Git pre-commit hook to format changed files, and [Aspect Workflows] to provide the check on CI.
128100

129101
[![asciicast](https://asciinema.org/a/vGTpzD0obvhILEcSxYAVrlpqT.svg)](https://asciinema.org/a/vGTpzD0obvhILEcSxYAVrlpqT)
130102

131-
See [Formatting](./docs/formatting.md) for more ways to use the formatter, such as a pre-commit hook or a CI check.
103+
See [Formatting](./docs/formatting.md) for more ways to use the formatter.
132104

133105
### Lint
134106

135-
To lint code, we recommend using the Aspect CLI to get the missing `lint` command.
107+
To lint code, we recommend using the [Aspect CLI] to get the missing `lint` command, and [Aspect Workflows] to provide first-class support for "linters as code reviewers".
136108

137109
For example, running `bazel lint //src:all` prints lint warnings to the terminal for all targets in the `//src` package:
138110

139111
[![asciicast](https://asciinema.org/a/xQWU1Wc1JINOubeguDDQbBqcq.svg)](https://asciinema.org/a/xQWU1Wc1JINOubeguDDQbBqcq)
140112

141-
See [Linting](./docs/linting.md) for more ways to use the linter, such as running as a test target, or presenting results as code review comments.
113+
See [Linting](./docs/linting.md) for more ways to use the linter.
142114

143115
### Ignoring files
144116

@@ -162,3 +134,25 @@ But we're not trying to stop anyone, either!
162134

163135
You could probably configure the editor to always run the same Bazel command, any time a file is changed.
164136
Instructions to do this are out-of-scope for this repo, particularly since they have to be formulated and updated for so many editors.
137+
138+
## FAQ
139+
140+
### What about type-checking?
141+
142+
We consider type-checkers as a build tool, not as a linter. This is for a few reasons:
143+
144+
- They are commonly distributed along with compilers.
145+
In compiled languages like Java, types are required in order for the compiler to emit executable bytecode at all.
146+
In interpreted languages they're still often linked, e.g. TypeScript does both "compiling" to JavaScript and also type-checking.
147+
This suggests that rules for a language should include the type-checker,
148+
e.g. we expect Sorbet to be integrated with rules_ruby and mypy/pyright to be integrated with rules_python or Aspect's rules_py.
149+
- We think most developers want "build error" semantics for type-checks:
150+
the whole repository should successfully type-check or you cannot commit the change.
151+
rules_lint is optimized for "warning" semantics, where we produce report files and it's up to the
152+
Dev Infra team how to present those, for example only on changed files.
153+
- You can only type-check a library if its dependencies were checkable, which means short-circuiting
154+
execution. rules_lint currently runs linters on every node in the dependency graph, including any
155+
whose dependencies have lint warnings.
156+
157+
[aspect workflows]: https://docs.aspect.build/workflows
158+
[aspect cli]: https://docs.aspect.build/cli

docs/formatting.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ $ chmod u+x .git/hooks/pre-commit
8888

8989
### Check that files are already formatted
9090

91-
There are two ways.
91+
We recommend using [Aspect Workflows] to hook up the CI check to notify developers of formatting changes,
92+
and offer to apply them as a suggestion in the code review thread.
93+
94+
To set this up manually, there are two supported methods:
9295

9396
#### 1: `run` target
9497

@@ -138,3 +141,5 @@ format_test(
138141
Then run `bazel test //tools/format/...` to check that all files are formatted.
139142

140143
[Gazelle]: https://github.com/bazelbuild/bazel-gazelle
144+
[Aspect Workflows]: https://docs.aspect.build/workflows
145+
[Aspect CLI]: https://docs.aspect.build/cli

docs/linting.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,32 @@ Finally, register those linter aspects in the lint runner. See details below.
1818

1919
## Usage
2020

21-
### 1. (Coming Soon) Linter as Code Review Bot
21+
### 1. Linter as Code Review Bot
2222

23-
An upcoming release of [Aspect Workflows](https://docs.aspect.build/workflows/) will include a `lint` task, which wires the reports from bazel-out directly into your code review.
23+
[Aspect Workflows] includes a `lint` task, which wires the reports from bazel-out directly into your code review.
2424
The fixes produced by the tool are shown as suggested edits, so you can just accept without a context-switch back to your development machine.
2525

2626
![lint suggestions in code review](./lint_workflow.png)
2727

28+
We recommend this workflow for several reasons:
29+
30+
1. Forcing engineers to fix lint violations on code they're still iterating is a waste of time.
31+
Code review is the right time to consider whether the code changes meet your teams quality bar.
32+
2. Code review has at least two parties, which means that comments aren't simply ignored.
33+
The reviewer has to agree with the author whether a suggested lint violation should be corrected.
34+
Compare this with the usual complaint "developers just ignore warnings" - that's because the warnings were presented in their local build.
35+
3. Adding a new linter (or adjusting its configuration to be stricter) doesn't require that you fix or suppress all existing warnings in the repository.
36+
This makes it more feasible for an enthusiastic engineer to setup a linter, without having the burden of "making it green" on all existing code.
37+
4. Linters shouldn't be required to have zero false-positives. Some lint checks are quite valuable when they detect a problem, but cannot always avoid overdetection.
38+
Since code review comments are always subject to human review, it's the right time to evaluate the suggestions and ignore those which don't make sense.
39+
5. This is how Google does it, in the [Tricorder] tool that's integrated into code review (Critique) to present static analysis results.
40+
With [Aspect Workflows] we've provided a similar experience.
41+
42+
[Tricorder]: https://static.googleusercontent.com/media/research.google.com/en/pubs/archive/43322.pdf
43+
2844
### 2. Warnings in the terminal with `bazel lint`
2945

30-
Aspect CLI adds the missing 'lint' command, so users just type `bazel lint //path/to:targets`.
46+
[Aspect CLI] adds the missing 'lint' command, so users just type `bazel lint //path/to:targets`.
3147

3248
Reports are then written to the terminal.
3349

@@ -45,9 +61,9 @@ lint:
4561
4662
### 3. Warnings in the terminal with a wrapper
4763
48-
If you don't use Aspect CLI, you can use vanilla Bazel with some wrapper like a shell script that runs the linter aspects over the requested targets.
64+
If you don't use [Aspect CLI], you can use vanilla Bazel with some wrapper like a shell script that runs the linter aspects over the requested targets.
4965
50-
See the `example/lint.sh` file as an example.
66+
See the `example/lint.sh` file as an example, and pay attention to the comments at the top about fitting it into your repo.
5167

5268
[![asciicast](https://asciinema.org/a/gUUuQTCGIu85YMl6zz2GJIgD8.svg)](https://asciinema.org/a/gUUuQTCGIu85YMl6zz2GJIgD8)
5369

@@ -59,7 +75,7 @@ This is the same flag many linters support.
5975

6076
### 4. Errors during `bazel build`
6177

62-
Add `--@aspect_rules_lint//lint:fail_on_violation` to the command-line,
78+
Add `--@aspect_rules_lint//lint:fail_on_violation` to the command-line or to your `.bazelrc` file
6379
to cause all linter aspects to honor the exit code of the lint tool.
6480

6581
This makes the build fail when any lint violations are present.
@@ -80,3 +96,6 @@ To bypass this filter, add `tags=["lint-genfiles"]` to a target to force all the
8096

8197
Some linters honor the debug flag in this repo. To enable it, add a Bazel flag:
8298
`--@aspect_rules_lint//lint:debug`
99+
100+
[Aspect Workflows]: https://docs.aspect.build/workflows
101+
[Aspect CLI]: https://docs.aspect.build/cli

example/tools/format/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,5 @@ format_test(
8888
starlark = "@buildifier_prebuilt//:buildifier",
8989
# FIXME: not hermetic: error while loading shared libraries: libFoundation.so
9090
# swift = ":swiftformat",
91-
terraform = ":terraform",
9291
workspace = "//:.shellcheckrc", # A file in the workspace root, where the no_sandbox mode will run the formatter
9392
)

0 commit comments

Comments
 (0)