lintrunner 0.12.3__py3-none-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lintrunner might be problematic. Click here for more details.
|
Binary file
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: lintrunner
|
|
3
|
+
Version: 0.12.3
|
|
4
|
+
Classifier: Programming Language :: Rust
|
|
5
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Summary: A lint running tool and framework.
|
|
9
|
+
Author: Michael Suo <suo@fb.com>
|
|
10
|
+
Author-email: Michael Suo <suo@fb.com>
|
|
11
|
+
License: BSD-3-Clause
|
|
12
|
+
Requires-Python: >=3.6
|
|
13
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
14
|
+
Project-URL: repository, https://github.com/suo/lintrunner
|
|
15
|
+
|
|
16
|
+
# Lintrunner
|
|
17
|
+
|
|
18
|
+
## Overview
|
|
19
|
+
`lintrunner` is a tool that runs linters. It is responsible for:
|
|
20
|
+
- Deciding which files need to be linted.
|
|
21
|
+
- Invoking linters according to a common protocol.
|
|
22
|
+
- Gathering results and presenting them to users.
|
|
23
|
+
|
|
24
|
+
The intention is to provide a universal way to configure and invoke linters,
|
|
25
|
+
which is useful on large polyglot projects.
|
|
26
|
+
|
|
27
|
+
The design of `lintrunner` is heavily inspired by `linttool`, a project that exists internally at Meta.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
```
|
|
31
|
+
pip install lintrunner
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
First, you need to add a configuration file to your repo. See the [Linter
|
|
36
|
+
configuration](#linter-configuration) section for more info.
|
|
37
|
+
|
|
38
|
+
Then, simply run `lintrunner` to lint your changes!
|
|
39
|
+
|
|
40
|
+
## How to control what paths to lint `lintrunner`
|
|
41
|
+
When run with no arguments, `lintrunner` will check:
|
|
42
|
+
- The files changed in the `HEAD` commit.
|
|
43
|
+
- The files changed in the user’s working tree.
|
|
44
|
+
|
|
45
|
+
It does *not* check:
|
|
46
|
+
- Any files not tracked by `git`; `git add` them to lint them.
|
|
47
|
+
|
|
48
|
+
There are multiple ways to customize how paths are checked:
|
|
49
|
+
|
|
50
|
+
### Pass paths as positional arguments
|
|
51
|
+
For example:
|
|
52
|
+
```
|
|
53
|
+
lintrunner foo.py bar.cpp
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This naturally composes with `xargs`, for example the canonical way to check
|
|
57
|
+
every path in the repo is:
|
|
58
|
+
```
|
|
59
|
+
git grep -Il . | xargs lintrunner
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### `--configs`/ `--config`
|
|
63
|
+
"Comma-separated paths to lintrunner configuration files.
|
|
64
|
+
Multiple files are merged, with later definitions overriding earlier ones.
|
|
65
|
+
ONLY THE FIRST is required to be present on your machine.
|
|
66
|
+
Defaults to `lintrunner.toml, lintrunner.private.toml`. Extra configs like `lintrunner.private.toml`
|
|
67
|
+
are useful for combining project-wide and local configs."
|
|
68
|
+
|
|
69
|
+
### `--paths-cmd`
|
|
70
|
+
Some ways to invoke `xargs` will cause multiple `lintrunner` processes to be
|
|
71
|
+
run, increasing lint time (especially on huge path sets). As an alternative that
|
|
72
|
+
gives `lintrunner` control of parallelization, you can use `--paths-cmd`. If
|
|
73
|
+
`--paths-cmd` is specified `lintrunner` will execute that command and consider
|
|
74
|
+
each line of its `stdout` to be a file to lint.
|
|
75
|
+
|
|
76
|
+
For example, the same command above would be:
|
|
77
|
+
```
|
|
78
|
+
lintrunner --paths-cmd='git grep -Il .'
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### `--paths-file`
|
|
82
|
+
If this is specified, `lintrunner` will read paths from the given file, one per
|
|
83
|
+
line, and check those. This can be useful if you have some really complex logic
|
|
84
|
+
to determine which paths to check.
|
|
85
|
+
|
|
86
|
+
### `--revision`
|
|
87
|
+
This value can be any `<tree-ish>` accepted by `git diff-tree`, like a commit
|
|
88
|
+
hash or revspec. If this is specified, `lintrunner` will check:
|
|
89
|
+
- All paths changed from `<tree-ish>` to `HEAD`
|
|
90
|
+
- All paths changed in the user's working tree.
|
|
91
|
+
|
|
92
|
+
### `--merge-base-with`
|
|
93
|
+
Like `--revision`, except the revision is determined by computing the merge-base
|
|
94
|
+
of `HEAD` and the provided `<tree-ish>`. This is useful for linting all commits
|
|
95
|
+
in a specific pull request. For example, for a pull request targeting master,
|
|
96
|
+
you can run:
|
|
97
|
+
```
|
|
98
|
+
lintrunner -m master
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### `--all-files`
|
|
102
|
+
This will run lint on all files specified in `.lintrunner.toml`.
|
|
103
|
+
|
|
104
|
+
### `--only-lint-under-config-dir`
|
|
105
|
+
If set, will only lint files under the directory where the configuration file is located and its subdirectories.
|
|
106
|
+
|
|
107
|
+
## Linter configuration
|
|
108
|
+
`lintrunner` knows which linters to run and how by looking at a configuration
|
|
109
|
+
file, conventionally named `.lintrunner.toml`.
|
|
110
|
+
|
|
111
|
+
Here is an example linter configuration:
|
|
112
|
+
|
|
113
|
+
```toml
|
|
114
|
+
merge_base_with = 'main'
|
|
115
|
+
|
|
116
|
+
[[linter]]
|
|
117
|
+
name = 'FLAKE8'
|
|
118
|
+
include_patterns = [
|
|
119
|
+
'src/**/*.py', # unix-style globs supported
|
|
120
|
+
'test/**/*.py',
|
|
121
|
+
]
|
|
122
|
+
exclude_patterns = ['src/my_bad_file.py']
|
|
123
|
+
command = [
|
|
124
|
+
'python3',
|
|
125
|
+
'flake8_linter.py',
|
|
126
|
+
'—-',
|
|
127
|
+
# {{PATHSFILE}} gets rewritten to a tmpfile containing all paths to lint
|
|
128
|
+
'@{{PATHSFILE}}',
|
|
129
|
+
]
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
A complete description of the configuration schema can be found
|
|
133
|
+
[here](https://docs.rs/lintrunner/latest/lintrunner/lint_config/struct.LintConfig.html).
|
|
134
|
+
|
|
135
|
+
## Linter protocol
|
|
136
|
+
Most linters have their own output format and arguments. In order to impose
|
|
137
|
+
consistency on linter invocation and outputs, `lintrunner` implements a protocol
|
|
138
|
+
that it expects linters to fulfill. In most cases, a small script (called a
|
|
139
|
+
*linter adapter*) is required to implement the protocol for a given external
|
|
140
|
+
linter. You can see some example adapters in `examples/` .
|
|
141
|
+
|
|
142
|
+
### Invocation
|
|
143
|
+
Linters will be invoked according to the `command` specified by their
|
|
144
|
+
configuration. They will be called once per lint run.
|
|
145
|
+
|
|
146
|
+
If a linter needs to know which paths to run on, it should take a
|
|
147
|
+
`{{PATHSFILE}}` argument. During invocation, the string `{{PATHSFILE}}` will be
|
|
148
|
+
replaced with the name of a temporary file containing which paths the linter
|
|
149
|
+
should run on, one path per line.
|
|
150
|
+
|
|
151
|
+
A common way to implement this in a linter adapter is to use `argparse`’s
|
|
152
|
+
[`fromfile_prefix_chars`](https://docs.python.org/3/library/argparse.html#fromfile-prefix-chars)
|
|
153
|
+
feature. In the Flake8 example above, we use `@` as the `fromfile_prefix_chars`
|
|
154
|
+
argument, so `argparse` will automatically read the `{{PATHSFILE}}` and supply
|
|
155
|
+
its contents as a list of arguments.
|
|
156
|
+
|
|
157
|
+
### Output
|
|
158
|
+
Any lint messages a linter would like to communicate the user must be
|
|
159
|
+
represented as a `LintMessage`. The linter, must print `LintMessage`s as [JSON
|
|
160
|
+
Lines](https://jsonlines.org/) to `stdout`, one message per line. Output to
|
|
161
|
+
`stderr` will be ignored.
|
|
162
|
+
|
|
163
|
+
A complete description of the LintMessage schema can be found
|
|
164
|
+
[here](https://docs.rs/lintrunner/latest/lintrunner/lint_message/struct.LintMessage.html).
|
|
165
|
+
|
|
166
|
+
### Exiting
|
|
167
|
+
Linters **should always exit with code 0**. This is true even if lint errors are
|
|
168
|
+
reported; `lintrunner` itself will determine how to exit based on what linters
|
|
169
|
+
report.
|
|
170
|
+
|
|
171
|
+
To signal a general linter failure (which should ideally never happen!), linters
|
|
172
|
+
can return a `LintMessage` with `path = None`.
|
|
173
|
+
|
|
174
|
+
In the event a linter exits non-zero, it will be caught by `lintrunner`and
|
|
175
|
+
presented as a “general linter failure” with stdout/stderr shown to the user.
|
|
176
|
+
This should be considered a bug in the linter’s implementation of this protocol.
|
|
177
|
+
|
|
178
|
+
## Tips for adopting `lintrunner` in a new project
|
|
179
|
+
|
|
180
|
+
When adopting lintrunner in a previously un-linted project, it may generate a lot
|
|
181
|
+
of lint messages. You can use the `--output oneline` option to make
|
|
182
|
+
`lintrunner` display each lint message in its separate line to quickly navigate
|
|
183
|
+
through them.
|
|
184
|
+
|
|
185
|
+
Additionally, you can selectively run specific linters with the `--take` option,
|
|
186
|
+
like `--take RUFF,CLANGFORMAT`, to focus on resolving specific lint errors, or
|
|
187
|
+
use `--skip` to skip a long running linter like `MYPY`.
|
|
188
|
+
|
|
189
|
+
## GitHub Action
|
|
190
|
+
|
|
191
|
+
To use `lintrunner` in a GitHub workflow, you can consider [`lintrunner-action`](https://github.com/justinchuby/lintrunner-action).
|
|
192
|
+
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
lintrunner-0.12.3.dist-info/METADATA,sha256=8OYY3bjPyffRYhZVghaSkPUTAl_7zQ7N5T3fFGTXoxA,7362
|
|
2
|
+
lintrunner-0.12.3.dist-info/WHEEL,sha256=HkkIsZtA0sTBbF3mELGjXJRINSUxtPE9noW4nlG5fdg,91
|
|
3
|
+
lintrunner-0.12.3.dist-info/license_files/LICENSE,sha256=FnG9-4L4fftD_u0xYbyexJ_u6D6lvW2qS9V7VpJLJ_I,1089
|
|
4
|
+
lintrunner-0.12.3.data/scripts/lintrunner.exe,sha256=Dl3EMk7jDd9lCPEzCRmys7KAiQ2_ivf7Xij_glBhA1U,3592704
|
|
5
|
+
lintrunner-0.12.3.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Michael Suo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|