From 02897a141b2d2d1015d10e1a320e68b0bc5af77b Mon Sep 17 00:00:00 2001 From: Simon Brugman Date: Sun, 12 Feb 2023 19:09:39 +0100 Subject: [PATCH] [`flake8-tidy-imports`] add documentation for `banned-api` (#2819) --- README.md | 2 +- .../rules/flake8_tidy_imports/banned_api.rs | 17 +++++++++++++++ docs/rules/banned-api.md | 21 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 docs/rules/banned-api.md diff --git a/README.md b/README.md index 972c6c7ea8..2e50fb12da 100644 --- a/README.md +++ b/README.md @@ -1280,7 +1280,7 @@ For more, see [flake8-tidy-imports](https://pypi.org/project/flake8-tidy-imports | Code | Name | Message | Fix | | ---- | ---- | ------- | --- | -| TID251 | banned-api | `{name}` is banned: {message} | | +| TID251 | [banned-api](https://github.com/charliermarsh/ruff/blob/main/docs/rules/banned-api.md) | `{name}` is banned: {message} | | | TID252 | [relative-imports](https://github.com/charliermarsh/ruff/blob/main/docs/rules/relative-imports.md) | Relative imports from parent modules are banned | 🛠 | ### flake8-type-checking (TCH) diff --git a/crates/ruff/src/rules/flake8_tidy_imports/banned_api.rs b/crates/ruff/src/rules/flake8_tidy_imports/banned_api.rs index 08d9319b35..e9d316d0c1 100644 --- a/crates/ruff/src/rules/flake8_tidy_imports/banned_api.rs +++ b/crates/ruff/src/rules/flake8_tidy_imports/banned_api.rs @@ -20,6 +20,23 @@ pub struct ApiBan { } define_violation!( + /// ## What it does + /// Checks for banned imports. + /// + /// ## Why is this bad? + /// Projects may want to ensure that specific modules or module members are + /// not be imported or accessed. + /// + /// Security or other company policies may be a reason to impose + /// restrictions on importing external Python libraries. In some cases, + /// projects may adopt conventions around the use of certain modules or + /// module members that are not enforceable by the language itself. + /// + /// This rule enforces certain import conventions project-wide in an + /// automatic way. + /// + /// ## Options + /// * `flake8-tidy-imports.banned-api` pub struct BannedApi { pub name: String, pub message: String, diff --git a/docs/rules/banned-api.md b/docs/rules/banned-api.md new file mode 100644 index 0000000000..1337074820 --- /dev/null +++ b/docs/rules/banned-api.md @@ -0,0 +1,21 @@ +# banned-api (TID251) + +Derived from the **flake8-tidy-imports** linter. + +## What it does +Checks for banned imports. + +## Why is this bad? +Projects may want to ensure that specific modules or module members are +not be imported or accessed. + +Security or other company policies may be a reason to impose +restrictions on importing external Python libraries. In some cases, +projects may adopt conventions around the use of certain modules or +module members that are not enforceable by the language itself. + +This rule enforces certain import conventions project-wide in an +automatic way. + +## Options +* `flake8-tidy-imports.banned-api` \ No newline at end of file