Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pylint upstream categories not showing in docs #10441

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/ruff_dev/src/generate_rules_table.rs
Expand Up @@ -180,8 +180,17 @@ pub(crate) fn generate() -> String {
.map(|rule| (rule.upstream_category(&linter), rule))
.into_group_map();

let mut rules_by_upstream_category: Vec<_> = rules_by_upstream_category.iter().collect();

// Sort the upstream categories alphabetically by prefix.
rules_by_upstream_category.sort_by(|a, b| {
a.0.as_ref()
.map_or("", |x| x.prefix)
.cmp(b.0.as_ref().map_or("", |x| x.prefix))
});

if rules_by_upstream_category.len() > 1 {
for (opt, rules) in &rules_by_upstream_category {
for (opt, rules) in rules_by_upstream_category {
if opt.is_some() {
let UpstreamCategoryAndPrefix { category, prefix } = opt.unwrap();
table_out.push_str(&format!("#### {category} ({prefix})"));
Expand Down
40 changes: 15 additions & 25 deletions crates/ruff_linter/src/upstream_categories.rs
Expand Up @@ -8,29 +8,19 @@ pub struct UpstreamCategoryAndPrefix {
pub prefix: &'static str,
}

const PLC: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
const C: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
category: "Convention",
prefix: "PLC",
prefix: "C",
};

const PLE: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
const E: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
category: "Error",
prefix: "PLE",
prefix: "E",
};

const PLR: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
const R: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
category: "Refactor",
prefix: "PLR",
};

const PLW: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
category: "Warning",
prefix: "PLW",
};

const E: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
category: "Error",
prefix: "E",
prefix: "R",
};

const W: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
Expand All @@ -52,14 +42,14 @@ impl Rule {
}
}
Linter::Pylint => {
if code.starts_with("PLC") {
Some(PLC)
} else if code.starts_with("PLE") {
Some(PLE)
} else if code.starts_with("PLR") {
Some(PLR)
} else if code.starts_with("PLW") {
Some(PLW)
if code.starts_with('C') {
Some(C)
} else if code.starts_with('E') {
Some(E)
} else if code.starts_with('R') {
Some(R)
} else if code.starts_with('W') {
Some(W)
} else {
None
}
Expand All @@ -73,7 +63,7 @@ impl Linter {
pub const fn upstream_categories(&self) -> Option<&'static [UpstreamCategoryAndPrefix]> {
match self {
Linter::Pycodestyle => Some(&[E, W]),
Linter::Pylint => Some(&[PLC, PLE, PLR, PLW]),
Linter::Pylint => Some(&[C, E, R, W]),
_ => None,
}
}
Expand Down