Skip to content

Commit

Permalink
Add a link to the nursery; tweak icons
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jul 10, 2023
1 parent eb69fe3 commit 1807c8d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
31 changes: 21 additions & 10 deletions crates/ruff_dev/src/generate_rules_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ const FIX_SYMBOL: &str = "🛠";
const NURSERY_SYMBOL: &str = "🌅";

fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>, linter: &Linter) {
table_out.push_str("| Code | Name | Message | Status |");
table_out.push_str("| Code | Name | Message | |");
table_out.push('\n');
table_out.push_str("| ---- | ---- | ------- | ------ |");
table_out.push_str("| ---- | ---- | ------- | ------: |");
table_out.push('\n');
for rule in rules {
let fix_token = match rule.autofixable() {
AutofixKind::None => "",
AutofixKind::Always | AutofixKind::Sometimes => FIX_SYMBOL,
AutofixKind::Always | AutofixKind::Sometimes => {
format!("<span style='opacity: 1'>{}</span>", FIX_SYMBOL)
}
AutofixKind::None => format!("<span style='opacity: 0.1'>{}</span>", FIX_SYMBOL),
};
let nursery_token = if rule.is_nursery() {
NURSERY_SYMBOL
format!("<span style='opacity: 1'>{}</span>", NURSERY_SYMBOL)
} else {
""
format!("<span style='opacity: 0.1'>{}</span>", NURSERY_SYMBOL)
};
let status_token = format!("{fix_token} {nursery_token}");

Expand All @@ -48,10 +50,19 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>,

pub(crate) fn generate() -> String {
// Generate the table string.
let mut table_out = format!(
"The {FIX_SYMBOL} emoji indicates that a rule is automatically fixable by the `--fix` command-line option.\n\
The {NURSERY_SYMBOL} emoji indicates that a rule is part of the nursery, a collection of newer lints that are still under development.\n\n"
);
let mut table_out = String::new();

table_out.push_str(&format!(
"The {FIX_SYMBOL} emoji indicates that a rule is automatically fixable by the `--fix` command-line option."));
table_out.push('\n');
table_out.push('\n');

table_out.push_str(&format!(
"The {NURSERY_SYMBOL} emoji indicates that a rule is part of the [\"nursery\"](../faq/#what-is-the-nursery)."
));
table_out.push('\n');
table_out.push('\n');

for linter in Linter::iter() {
let codes_csv: String = match linter.common_prefix() {
"" => linter
Expand Down
32 changes: 32 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,38 @@ matter how they're provided, which avoids accidental incompatibilities and simpl
By default, no `convention` is set, and so the enabled rules are determined by the `select` setting
alone.

## What is the "nursery"?

The "nursery" is a collection of newer rules that are considered experimental or unstable.

If a rule is marked as part of the "nursery", it can only be enabled via direct selection. For
example, consider a hypothetical rule, `HYP001`. If `HYP001` were included in the "nursery", it
could be enabled by adding the following to your `pyproject.toml`:

```toml
[tool.ruff]
extend-select = ["HYP001"]
```

However, it would _not_ be enabled by selecting the `HYP` category, like so:

```toml
[tool.ruff]
extend-select = ["HYP"]
```

Similarly, it would _not_ be enabled via the `ALL` selector:

```toml
[tool.ruff]
select = ["ALL"]
```

(The "nursery" terminology comes from [Clippy](https://doc.rust-lang.org/nightly/clippy/), a similar
tool for linting Rust code.)

To see which rules are currently in the "nursery", visit the [rules reference](https://beta.ruff.rs/docs/rules/).

## How can I tell what settings Ruff is using to check my code?

Run `ruff check /path/to/code.py --show-settings` to view the resolved settings for a given file.
Expand Down

0 comments on commit 1807c8d

Please sign in to comment.