mirror of https://github.com/astral-sh/ruff
Add documentation for eradicate, flake8-import-conventions, and flake8-no-pep420 (#2652)
This commit is contained in:
parent
8261d0656e
commit
4c35feaa18
|
|
@ -1076,7 +1076,7 @@ For more, see [flake8-import-conventions](https://github.com/joaopalmeiro/flake8
|
|||
|
||||
| Code | Name | Message | Fix |
|
||||
| ---- | ---- | ------- | --- |
|
||||
| ICN001 | import-alias-is-not-conventional | `{name}` should be imported as `{asname}` | |
|
||||
| [ICN001](https://github.com/charliermarsh/ruff/blob/main/docs/rules/unconventional-import-alias.md) | [unconventional-import-alias](https://github.com/charliermarsh/ruff/blob/main/docs/rules/unconventional-import-alias.md) | `{name}` should be imported as `{asname}` | |
|
||||
|
||||
### flake8-logging-format (G)
|
||||
|
||||
|
|
@ -1099,7 +1099,7 @@ For more, see [flake8-no-pep420](https://pypi.org/project/flake8-no-pep420/) on
|
|||
|
||||
| Code | Name | Message | Fix |
|
||||
| ---- | ---- | ------- | --- |
|
||||
| INP001 | implicit-namespace-package | File `{filename}` is part of an implicit namespace package. Add an `__init__.py`. | |
|
||||
| [INP001](https://github.com/charliermarsh/ruff/blob/main/docs/rules/implicit-namespace-package.md) | [implicit-namespace-package](https://github.com/charliermarsh/ruff/blob/main/docs/rules/implicit-namespace-package.md) | File `{filename}` is part of an implicit namespace package. Add an `__init__.py`. | |
|
||||
|
||||
### flake8-pie (PIE)
|
||||
|
||||
|
|
@ -1285,7 +1285,7 @@ For more, see [eradicate](https://pypi.org/project/eradicate/) on PyPI.
|
|||
|
||||
| Code | Name | Message | Fix |
|
||||
| ---- | ---- | ------- | --- |
|
||||
| ERA001 | commented-out-code | Found commented-out code | 🛠 |
|
||||
| [ERA001](https://github.com/charliermarsh/ruff/blob/main/docs/rules/commented-out-code.md) | [commented-out-code](https://github.com/charliermarsh/ruff/blob/main/docs/rules/commented-out-code.md) | Found commented-out code | 🛠 |
|
||||
|
||||
### pandas-vet (PD)
|
||||
|
||||
|
|
|
|||
|
|
@ -1064,7 +1064,7 @@ where
|
|||
if self
|
||||
.settings
|
||||
.rules
|
||||
.enabled(&Rule::ImportAliasIsNotConventional)
|
||||
.enabled(&Rule::UnconventionalImportAlias)
|
||||
{
|
||||
if let Some(diagnostic) =
|
||||
flake8_import_conventions::rules::check_conventional_import(
|
||||
|
|
@ -1323,7 +1323,7 @@ where
|
|||
if self
|
||||
.settings
|
||||
.rules
|
||||
.enabled(&Rule::ImportAliasIsNotConventional)
|
||||
.enabled(&Rule::UnconventionalImportAlias)
|
||||
{
|
||||
let full_name = helpers::format_import_from_member(
|
||||
level.as_ref(),
|
||||
|
|
|
|||
|
|
@ -388,7 +388,7 @@ ruff_macros::define_rule_mapping!(
|
|||
ARG004 => rules::flake8_unused_arguments::rules::UnusedStaticMethodArgument,
|
||||
ARG005 => rules::flake8_unused_arguments::rules::UnusedLambdaArgument,
|
||||
// flake8-import-conventions
|
||||
ICN001 => rules::flake8_import_conventions::rules::ImportAliasIsNotConventional,
|
||||
ICN001 => rules::flake8_import_conventions::rules::UnconventionalImportAlias,
|
||||
// flake8-datetimez
|
||||
DTZ001 => rules::flake8_datetimez::rules::CallDatetimeWithoutTzinfo,
|
||||
DTZ002 => rules::flake8_datetimez::rules::CallDatetimeToday,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,17 @@ use crate::source_code::Locator;
|
|||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
/// ### What it does
|
||||
/// Checks for commented-out Python code.
|
||||
///
|
||||
/// ### Why is this bad?
|
||||
/// Commented-out code is dead code, and is often included inadvertently.
|
||||
/// It should be removed.
|
||||
///
|
||||
/// ### Example
|
||||
/// ```python
|
||||
/// # print('foo')
|
||||
/// ```
|
||||
pub struct CommentedOutCode;
|
||||
);
|
||||
impl AlwaysAutofixableViolation for CommentedOutCode {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ mod tests {
|
|||
fn defaults() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_import_conventions/defaults.py"),
|
||||
&Settings::for_rule(Rule::ImportAliasIsNotConventional),
|
||||
&Settings::for_rule(Rule::UnconventionalImportAlias),
|
||||
)?;
|
||||
assert_yaml_snapshot!("defaults", diagnostics);
|
||||
Ok(())
|
||||
|
|
@ -37,7 +37,7 @@ mod tests {
|
|||
])),
|
||||
}
|
||||
.into(),
|
||||
..Settings::for_rule(Rule::ImportAliasIsNotConventional)
|
||||
..Settings::for_rule(Rule::UnconventionalImportAlias)
|
||||
},
|
||||
)?;
|
||||
assert_yaml_snapshot!("custom", diagnostics);
|
||||
|
|
@ -59,7 +59,7 @@ mod tests {
|
|||
extend_aliases: None,
|
||||
}
|
||||
.into(),
|
||||
..Settings::for_rule(Rule::ImportAliasIsNotConventional)
|
||||
..Settings::for_rule(Rule::UnconventionalImportAlias)
|
||||
},
|
||||
)?;
|
||||
assert_yaml_snapshot!("remove_default", diagnostics);
|
||||
|
|
@ -79,7 +79,7 @@ mod tests {
|
|||
)])),
|
||||
}
|
||||
.into(),
|
||||
..Settings::for_rule(Rule::ImportAliasIsNotConventional)
|
||||
..Settings::for_rule(Rule::UnconventionalImportAlias)
|
||||
},
|
||||
)?;
|
||||
assert_yaml_snapshot!("override_default", diagnostics);
|
||||
|
|
@ -102,7 +102,7 @@ mod tests {
|
|||
])),
|
||||
}
|
||||
.into(),
|
||||
..Settings::for_rule(Rule::ImportAliasIsNotConventional)
|
||||
..Settings::for_rule(Rule::UnconventionalImportAlias)
|
||||
},
|
||||
)?;
|
||||
assert_yaml_snapshot!("from_imports", diagnostics);
|
||||
|
|
|
|||
|
|
@ -7,12 +7,33 @@ use crate::registry::Diagnostic;
|
|||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
pub struct ImportAliasIsNotConventional(pub String, pub String);
|
||||
/// ### What it does
|
||||
/// Checks for imports that are typically imported using a common convention,
|
||||
/// like `import pandas as pd`, and enforces that convention.
|
||||
///
|
||||
/// ### Why is this bad?
|
||||
/// Consistency is good. Use a common convention for imports to make your code
|
||||
/// more readable and idiomatic.
|
||||
///
|
||||
/// For example, `import pandas as pd` is a common
|
||||
/// convention for importing the `pandas` library, and users typically expect
|
||||
/// Pandas to be aliased as `pd`.
|
||||
///
|
||||
/// ### Example
|
||||
/// ```python
|
||||
/// import pandas
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// import pandas as pd
|
||||
/// ```
|
||||
pub struct UnconventionalImportAlias(pub String, pub String);
|
||||
);
|
||||
impl Violation for ImportAliasIsNotConventional {
|
||||
impl Violation for UnconventionalImportAlias {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let ImportAliasIsNotConventional(name, asname) = self;
|
||||
let UnconventionalImportAlias(name, asname) = self;
|
||||
format!("`{name}` should be imported as `{asname}`")
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +58,7 @@ pub fn check_conventional_import(
|
|||
}
|
||||
if !is_valid_import {
|
||||
return Some(Diagnostic::new(
|
||||
ImportAliasIsNotConventional(name.to_string(), expected_alias.to_string()),
|
||||
UnconventionalImportAlias(name.to_string(), expected_alias.to_string()),
|
||||
Range::from_located(import_from),
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
source: src/rules/flake8_import_conventions/mod.rs
|
||||
source: crates/ruff/src/rules/flake8_import_conventions/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- altair
|
||||
- alt
|
||||
location:
|
||||
|
|
@ -15,7 +15,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- dask.array
|
||||
- da
|
||||
location:
|
||||
|
|
@ -27,7 +27,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- dask.dataframe
|
||||
- dd
|
||||
location:
|
||||
|
|
@ -39,7 +39,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- matplotlib.pyplot
|
||||
- plt
|
||||
location:
|
||||
|
|
@ -51,7 +51,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- numpy
|
||||
- np
|
||||
location:
|
||||
|
|
@ -63,7 +63,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- pandas
|
||||
- pd
|
||||
location:
|
||||
|
|
@ -75,7 +75,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- seaborn
|
||||
- sns
|
||||
location:
|
||||
|
|
@ -87,7 +87,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- tensorflow
|
||||
- tf
|
||||
location:
|
||||
|
|
@ -99,7 +99,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- holoviews
|
||||
- hv
|
||||
location:
|
||||
|
|
@ -111,7 +111,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- panel
|
||||
- pn
|
||||
location:
|
||||
|
|
@ -123,7 +123,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- plotly.express
|
||||
- px
|
||||
location:
|
||||
|
|
@ -135,7 +135,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- matplotlib
|
||||
- mpl
|
||||
location:
|
||||
|
|
@ -147,7 +147,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- polars
|
||||
- pl
|
||||
location:
|
||||
|
|
@ -159,7 +159,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- pyarrow
|
||||
- pa
|
||||
location:
|
||||
|
|
@ -171,7 +171,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- altair
|
||||
- alt
|
||||
location:
|
||||
|
|
@ -183,7 +183,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- matplotlib.pyplot
|
||||
- plt
|
||||
location:
|
||||
|
|
@ -195,7 +195,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- dask.array
|
||||
- da
|
||||
location:
|
||||
|
|
@ -207,7 +207,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- dask.dataframe
|
||||
- dd
|
||||
location:
|
||||
|
|
@ -219,7 +219,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- numpy
|
||||
- np
|
||||
location:
|
||||
|
|
@ -231,7 +231,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- pandas
|
||||
- pd
|
||||
location:
|
||||
|
|
@ -243,7 +243,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- seaborn
|
||||
- sns
|
||||
location:
|
||||
|
|
@ -255,7 +255,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- tensorflow
|
||||
- tf
|
||||
location:
|
||||
|
|
@ -267,7 +267,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- holoviews
|
||||
- hv
|
||||
location:
|
||||
|
|
@ -279,7 +279,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- panel
|
||||
- pn
|
||||
location:
|
||||
|
|
@ -291,7 +291,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- plotly.express
|
||||
- px
|
||||
location:
|
||||
|
|
@ -303,7 +303,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- matplotlib
|
||||
- mpl
|
||||
location:
|
||||
|
|
@ -315,7 +315,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- polars
|
||||
- pl
|
||||
location:
|
||||
|
|
@ -327,7 +327,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- pyarrow
|
||||
- pa
|
||||
location:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
source: src/rules/flake8_import_conventions/mod.rs
|
||||
source: crates/ruff/src/rules/flake8_import_conventions/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- altair
|
||||
- alt
|
||||
location:
|
||||
|
|
@ -15,7 +15,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- matplotlib.pyplot
|
||||
- plt
|
||||
location:
|
||||
|
|
@ -27,7 +27,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- numpy
|
||||
- np
|
||||
location:
|
||||
|
|
@ -39,7 +39,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- pandas
|
||||
- pd
|
||||
location:
|
||||
|
|
@ -51,7 +51,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- seaborn
|
||||
- sns
|
||||
location:
|
||||
|
|
@ -63,7 +63,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- altair
|
||||
- alt
|
||||
location:
|
||||
|
|
@ -75,7 +75,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- matplotlib.pyplot
|
||||
- plt
|
||||
location:
|
||||
|
|
@ -87,7 +87,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- numpy
|
||||
- np
|
||||
location:
|
||||
|
|
@ -99,7 +99,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- pandas
|
||||
- pd
|
||||
location:
|
||||
|
|
@ -111,7 +111,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- seaborn
|
||||
- sns
|
||||
location:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
source: src/rules/flake8_import_conventions/mod.rs
|
||||
source: crates/ruff/src/rules/flake8_import_conventions/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- xml.dom.minidom
|
||||
- md
|
||||
location:
|
||||
|
|
@ -15,7 +15,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- xml.dom.minidom
|
||||
- md
|
||||
location:
|
||||
|
|
@ -27,7 +27,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- xml.dom.minidom
|
||||
- md
|
||||
location:
|
||||
|
|
@ -39,7 +39,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- xml.dom.minidom
|
||||
- md
|
||||
location:
|
||||
|
|
@ -51,7 +51,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- xml.dom.minidom.parseString
|
||||
- pstr
|
||||
location:
|
||||
|
|
@ -63,7 +63,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- xml.dom.minidom.parseString
|
||||
- pstr
|
||||
location:
|
||||
|
|
@ -75,7 +75,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- xml.dom.minidom.parseString
|
||||
- pstr
|
||||
location:
|
||||
|
|
@ -87,7 +87,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- xml.dom.minidom.parseString
|
||||
- pstr
|
||||
location:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
source: src/rules/flake8_import_conventions/mod.rs
|
||||
source: crates/ruff/src/rules/flake8_import_conventions/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- altair
|
||||
- alt
|
||||
location:
|
||||
|
|
@ -15,7 +15,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- matplotlib.pyplot
|
||||
- plt
|
||||
location:
|
||||
|
|
@ -27,7 +27,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- numpy
|
||||
- nmp
|
||||
location:
|
||||
|
|
@ -39,7 +39,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- pandas
|
||||
- pd
|
||||
location:
|
||||
|
|
@ -51,7 +51,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- seaborn
|
||||
- sns
|
||||
location:
|
||||
|
|
@ -63,7 +63,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- altair
|
||||
- alt
|
||||
location:
|
||||
|
|
@ -75,7 +75,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- matplotlib.pyplot
|
||||
- plt
|
||||
location:
|
||||
|
|
@ -87,7 +87,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- numpy
|
||||
- nmp
|
||||
location:
|
||||
|
|
@ -99,7 +99,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- pandas
|
||||
- pd
|
||||
location:
|
||||
|
|
@ -111,7 +111,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- seaborn
|
||||
- sns
|
||||
location:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
source: src/rules/flake8_import_conventions/mod.rs
|
||||
source: crates/ruff/src/rules/flake8_import_conventions/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- altair
|
||||
- alt
|
||||
location:
|
||||
|
|
@ -15,7 +15,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- matplotlib.pyplot
|
||||
- plt
|
||||
location:
|
||||
|
|
@ -27,7 +27,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- pandas
|
||||
- pd
|
||||
location:
|
||||
|
|
@ -39,7 +39,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- seaborn
|
||||
- sns
|
||||
location:
|
||||
|
|
@ -51,7 +51,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- altair
|
||||
- alt
|
||||
location:
|
||||
|
|
@ -63,7 +63,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- matplotlib.pyplot
|
||||
- plt
|
||||
location:
|
||||
|
|
@ -75,7 +75,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- pandas
|
||||
- pd
|
||||
location:
|
||||
|
|
@ -87,7 +87,7 @@ expression: diagnostics
|
|||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ImportAliasIsNotConventional:
|
||||
UnconventionalImportAlias:
|
||||
- seaborn
|
||||
- sns
|
||||
location:
|
||||
|
|
|
|||
|
|
@ -8,6 +8,23 @@ use crate::registry::Diagnostic;
|
|||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
/// ### What it does
|
||||
/// Checks for packages that are missing an `__init__.py` file.
|
||||
///
|
||||
/// ### Why is this bad?
|
||||
/// Python packages are directories that contain a file named `__init__.py`.
|
||||
/// The existence of this file indicates that the directory is a Python
|
||||
/// package, and so it can be imported the same way a module can be
|
||||
/// imported.
|
||||
///
|
||||
/// Directories that lack an `__init__.py` file can still be imported, but
|
||||
/// they're indicative of a special kind of package, known as a namespace
|
||||
/// package (see: [PEP 420](https://www.python.org/dev/peps/pep-0420/)).
|
||||
///
|
||||
/// Namespace packages are a relatively new feature of Python, and they're
|
||||
/// not widely used. So a package that lacks an `__init__.py` file is
|
||||
/// typically meant to be a regular package, and the absence of the
|
||||
/// `__init__.py` file is probably an oversight.
|
||||
pub struct ImplicitNamespacePackage(pub String);
|
||||
);
|
||||
impl Violation for ImplicitNamespacePackage {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
# commented-out-code (ERA001)
|
||||
|
||||
Derived from the **eradicate** linter.
|
||||
|
||||
Autofix is always available.
|
||||
|
||||
### What it does
|
||||
Checks for commented-out Python code.
|
||||
|
||||
### Why is this bad?
|
||||
Commented-out code is dead code, and is often included inadvertently.
|
||||
It should be removed.
|
||||
|
||||
### Example
|
||||
```python
|
||||
```
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# implicit-namespace-package (INP001)
|
||||
|
||||
Derived from the **flake8-no-pep420** linter.
|
||||
|
||||
### What it does
|
||||
Checks for packages that are missing an `__init__.py` file.
|
||||
|
||||
### Why is this bad?
|
||||
Python packages are directories that contain a file named `__init__.py`.
|
||||
The existence of this file indicates that the directory is a Python
|
||||
package, and so it can be imported the same way a module can be
|
||||
imported.
|
||||
|
||||
Directories that lack an `__init__.py` file can still be imported, but
|
||||
they're indicative of a special kind of package, known as a namespace
|
||||
package (see: [PEP 420](https://www.python.org/dev/peps/pep-0420/)).
|
||||
|
||||
Namespace packages are a relatively new feature of Python, and they're
|
||||
not widely used. So a package that lacks an `__init__.py` file is
|
||||
typically meant to be a regular package, and the absence of the
|
||||
`__init__.py` file is probably an oversight.
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
# unconventional-import-alias (ICN001)
|
||||
|
||||
Derived from the **flake8-import-conventions** linter.
|
||||
|
||||
### What it does
|
||||
Checks for imports that are typically imported using a common convention,
|
||||
like `import pandas as pd`, and enforces that convention.
|
||||
|
||||
### Why is this bad?
|
||||
Consistency is good. Use a common convention for imports to make your code
|
||||
more readable and idiomatic.
|
||||
|
||||
For example, `import pandas as pd` is a common
|
||||
convention for importing the `pandas` library, and users typically expect
|
||||
Pandas to be aliased as `pd`.
|
||||
|
||||
### Example
|
||||
```python
|
||||
import pandas
|
||||
```
|
||||
|
||||
Use instead:
|
||||
```python
|
||||
import pandas as pd
|
||||
```
|
||||
Loading…
Reference in New Issue