Skip to content

Commit 977447f

Browse files
Sort linters alphabetically (astral-sh#16168)
## Summary Resolves astral-sh#16164. Linters are now sorted by their names case-insensitively. ## Test Plan ![](https://github.com/user-attachments/assets/87ffd4d8-1ba5-4a4b-8fed-dd21a020bd27) Also unit tests.
1 parent b3e99b2 commit 977447f

File tree

1 file changed

+77
-61
lines changed

1 file changed

+77
-61
lines changed

crates/ruff_linter/src/registry.rs

Lines changed: 77 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,15 @@ pub enum FromCodeError {
3333

3434
#[derive(EnumIter, Debug, PartialEq, Eq, Clone, Hash, RuleNamespace)]
3535
pub enum Linter {
36-
/// [Pyflakes](https://pypi.org/project/pyflakes/)
37-
#[prefix = "F"]
38-
Pyflakes,
39-
/// [pycodestyle](https://pypi.org/project/pycodestyle/)
40-
#[prefix = "E"]
41-
#[prefix = "W"]
42-
Pycodestyle,
43-
/// [mccabe](https://pypi.org/project/mccabe/)
44-
#[prefix = "C90"]
45-
McCabe,
46-
/// [isort](https://pypi.org/project/isort/)
47-
#[prefix = "I"]
48-
Isort,
49-
/// [pep8-naming](https://pypi.org/project/pep8-naming/)
50-
#[prefix = "N"]
51-
PEP8Naming,
52-
/// [pydocstyle](https://pypi.org/project/pydocstyle/)
53-
#[prefix = "D"]
54-
Pydocstyle,
55-
/// [pyupgrade](https://pypi.org/project/pyupgrade/)
56-
#[prefix = "UP"]
57-
Pyupgrade,
36+
/// [Airflow](https://pypi.org/project/apache-airflow/)
37+
#[prefix = "AIR"]
38+
Airflow,
39+
/// [eradicate](https://pypi.org/project/eradicate/)
40+
#[prefix = "ERA"]
41+
Eradicate,
42+
/// [FastAPI](https://pypi.org/project/fastapi/)
43+
#[prefix = "FAST"]
44+
FastApi,
5845
/// [flake8-2020](https://pypi.org/project/flake8-2020/)
5946
#[prefix = "YTT"]
6047
Flake82020,
@@ -82,12 +69,12 @@ pub enum Linter {
8269
/// [flake8-commas](https://pypi.org/project/flake8-commas/)
8370
#[prefix = "COM"]
8471
Flake8Commas,
85-
/// [flake8-copyright](https://pypi.org/project/flake8-copyright/)
86-
#[prefix = "CPY"]
87-
Flake8Copyright,
8872
/// [flake8-comprehensions](https://pypi.org/project/flake8-comprehensions/)
8973
#[prefix = "C4"]
9074
Flake8Comprehensions,
75+
/// [flake8-copyright](https://pypi.org/project/flake8-copyright/)
76+
#[prefix = "CPY"]
77+
Flake8Copyright,
9178
/// [flake8-datetimez](https://pypi.org/project/flake8-datetimez/)
9279
#[prefix = "DTZ"]
9380
Flake8Datetimez,
@@ -103,9 +90,15 @@ pub enum Linter {
10390
/// [flake8-executable](https://pypi.org/project/flake8-executable/)
10491
#[prefix = "EXE"]
10592
Flake8Executable,
93+
/// [flake8-fixme](https://github.com/tommilligan/flake8-fixme)
94+
#[prefix = "FIX"]
95+
Flake8Fixme,
10696
/// [flake8-future-annotations](https://pypi.org/project/flake8-future-annotations/)
10797
#[prefix = "FA"]
10898
Flake8FutureAnnotations,
99+
/// [flake8-gettext](https://pypi.org/project/flake8-gettext/)
100+
#[prefix = "INT"]
101+
Flake8GetText,
109102
/// [flake8-implicit-str-concat](https://pypi.org/project/flake8-implicit-str-concat/)
110103
#[prefix = "ISC"]
111104
Flake8ImplicitStrConcat,
@@ -145,72 +138,79 @@ pub enum Linter {
145138
/// [flake8-self](https://pypi.org/project/flake8-self/)
146139
#[prefix = "SLF"]
147140
Flake8Self,
148-
/// [flake8-slots](https://pypi.org/project/flake8-slots/)
149-
#[prefix = "SLOT"]
150-
Flake8Slots,
151141
/// [flake8-simplify](https://pypi.org/project/flake8-simplify/)
152142
#[prefix = "SIM"]
153143
Flake8Simplify,
144+
/// [flake8-slots](https://pypi.org/project/flake8-slots/)
145+
#[prefix = "SLOT"]
146+
Flake8Slots,
154147
/// [flake8-tidy-imports](https://pypi.org/project/flake8-tidy-imports/)
155148
#[prefix = "TID"]
156149
Flake8TidyImports,
150+
/// [flake8-todos](https://github.com/orsinium-labs/flake8-todos/)
151+
#[prefix = "TD"]
152+
Flake8Todos,
157153
/// [flake8-type-checking](https://pypi.org/project/flake8-type-checking/)
158154
#[prefix = "TC"]
159155
Flake8TypeChecking,
160-
/// [flake8-gettext](https://pypi.org/project/flake8-gettext/)
161-
#[prefix = "INT"]
162-
Flake8GetText,
163156
/// [flake8-unused-arguments](https://pypi.org/project/flake8-unused-arguments/)
164157
#[prefix = "ARG"]
165158
Flake8UnusedArguments,
166159
/// [flake8-use-pathlib](https://pypi.org/project/flake8-use-pathlib/)
167160
#[prefix = "PTH"]
168161
Flake8UsePathlib,
169-
/// [flake8-todos](https://github.com/orsinium-labs/flake8-todos/)
170-
#[prefix = "TD"]
171-
Flake8Todos,
172-
/// [flake8-fixme](https://github.com/tommilligan/flake8-fixme)
173-
#[prefix = "FIX"]
174-
Flake8Fixme,
175-
/// [eradicate](https://pypi.org/project/eradicate/)
176-
#[prefix = "ERA"]
177-
Eradicate,
178-
/// [pandas-vet](https://pypi.org/project/pandas-vet/)
179-
#[prefix = "PD"]
180-
PandasVet,
181-
/// [pygrep-hooks](https://github.com/pre-commit/pygrep-hooks)
182-
#[prefix = "PGH"]
183-
PygrepHooks,
184-
/// [Pylint](https://pypi.org/project/pylint/)
185-
#[prefix = "PL"]
186-
Pylint,
187-
/// [tryceratops](https://pypi.org/project/tryceratops/)
188-
#[prefix = "TRY"]
189-
Tryceratops,
190162
/// [flynt](https://pypi.org/project/flynt/)
191163
#[prefix = "FLY"]
192164
Flynt,
165+
/// [isort](https://pypi.org/project/isort/)
166+
#[prefix = "I"]
167+
Isort,
168+
/// [mccabe](https://pypi.org/project/mccabe/)
169+
#[prefix = "C90"]
170+
McCabe,
193171
/// NumPy-specific rules
194172
#[prefix = "NPY"]
195173
Numpy,
196-
/// [FastAPI](https://pypi.org/project/fastapi/)
197-
#[prefix = "FAST"]
198-
FastApi,
199-
/// [Airflow](https://pypi.org/project/apache-airflow/)
200-
#[prefix = "AIR"]
201-
Airflow,
174+
/// [pandas-vet](https://pypi.org/project/pandas-vet/)
175+
#[prefix = "PD"]
176+
PandasVet,
177+
/// [pep8-naming](https://pypi.org/project/pep8-naming/)
178+
#[prefix = "N"]
179+
PEP8Naming,
202180
/// [Perflint](https://pypi.org/project/perflint/)
203181
#[prefix = "PERF"]
204182
Perflint,
205-
/// [refurb](https://pypi.org/project/refurb/)
206-
#[prefix = "FURB"]
207-
Refurb,
183+
/// [pycodestyle](https://pypi.org/project/pycodestyle/)
184+
#[prefix = "E"]
185+
#[prefix = "W"]
186+
Pycodestyle,
208187
/// [pydoclint](https://pypi.org/project/pydoclint/)
209188
#[prefix = "DOC"]
210189
Pydoclint,
190+
/// [pydocstyle](https://pypi.org/project/pydocstyle/)
191+
#[prefix = "D"]
192+
Pydocstyle,
193+
/// [Pyflakes](https://pypi.org/project/pyflakes/)
194+
#[prefix = "F"]
195+
Pyflakes,
196+
/// [pygrep-hooks](https://github.com/pre-commit/pygrep-hooks)
197+
#[prefix = "PGH"]
198+
PygrepHooks,
199+
/// [Pylint](https://pypi.org/project/pylint/)
200+
#[prefix = "PL"]
201+
Pylint,
202+
/// [pyupgrade](https://pypi.org/project/pyupgrade/)
203+
#[prefix = "UP"]
204+
Pyupgrade,
205+
/// [refurb](https://pypi.org/project/refurb/)
206+
#[prefix = "FURB"]
207+
Refurb,
211208
/// Ruff-specific rules
212209
#[prefix = "RUF"]
213210
Ruff,
211+
/// [tryceratops](https://pypi.org/project/tryceratops/)
212+
#[prefix = "TRY"]
213+
Tryceratops,
214214
}
215215

216216
pub trait RuleNamespace: Sized {
@@ -430,6 +430,7 @@ pub mod clap_completion {
430430

431431
#[cfg(test)]
432432
mod tests {
433+
use itertools::Itertools;
433434
use std::mem::size_of;
434435

435436
use strum::IntoEnumIterator;
@@ -493,4 +494,19 @@ mod tests {
493494
fn rule_size() {
494495
assert_eq!(2, size_of::<Rule>());
495496
}
497+
498+
#[test]
499+
fn linter_sorting() {
500+
let names: Vec<_> = Linter::iter()
501+
.map(|linter| linter.name().to_lowercase())
502+
.collect();
503+
504+
let sorted: Vec<_> = names.iter().cloned().sorted().collect();
505+
506+
assert_eq!(
507+
&names[..],
508+
&sorted[..],
509+
"Linters are not sorted alphabetically (case insensitive)"
510+
);
511+
}
496512
}

0 commit comments

Comments
 (0)