Add documentation for eradicate, flake8-import-conventions, and flake8-no-pep420 (#2652)

This commit is contained in:
Charlie Marsh 2023-02-07 22:19:21 -05:00 committed by GitHub
parent 8261d0656e
commit 4c35feaa18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 195 additions and 84 deletions

View File

@ -1076,7 +1076,7 @@ For more, see [flake8-import-conventions](https://github.com/joaopalmeiro/flake8
| Code | Name | Message | Fix | | 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) ### 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 | | 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) ### flake8-pie (PIE)
@ -1285,7 +1285,7 @@ For more, see [eradicate](https://pypi.org/project/eradicate/) on PyPI.
| Code | Name | Message | Fix | | 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) ### pandas-vet (PD)

View File

@ -1064,7 +1064,7 @@ where
if self if self
.settings .settings
.rules .rules
.enabled(&Rule::ImportAliasIsNotConventional) .enabled(&Rule::UnconventionalImportAlias)
{ {
if let Some(diagnostic) = if let Some(diagnostic) =
flake8_import_conventions::rules::check_conventional_import( flake8_import_conventions::rules::check_conventional_import(
@ -1323,7 +1323,7 @@ where
if self if self
.settings .settings
.rules .rules
.enabled(&Rule::ImportAliasIsNotConventional) .enabled(&Rule::UnconventionalImportAlias)
{ {
let full_name = helpers::format_import_from_member( let full_name = helpers::format_import_from_member(
level.as_ref(), level.as_ref(),

View File

@ -388,7 +388,7 @@ ruff_macros::define_rule_mapping!(
ARG004 => rules::flake8_unused_arguments::rules::UnusedStaticMethodArgument, ARG004 => rules::flake8_unused_arguments::rules::UnusedStaticMethodArgument,
ARG005 => rules::flake8_unused_arguments::rules::UnusedLambdaArgument, ARG005 => rules::flake8_unused_arguments::rules::UnusedLambdaArgument,
// flake8-import-conventions // flake8-import-conventions
ICN001 => rules::flake8_import_conventions::rules::ImportAliasIsNotConventional, ICN001 => rules::flake8_import_conventions::rules::UnconventionalImportAlias,
// flake8-datetimez // flake8-datetimez
DTZ001 => rules::flake8_datetimez::rules::CallDatetimeWithoutTzinfo, DTZ001 => rules::flake8_datetimez::rules::CallDatetimeWithoutTzinfo,
DTZ002 => rules::flake8_datetimez::rules::CallDatetimeToday, DTZ002 => rules::flake8_datetimez::rules::CallDatetimeToday,

View File

@ -10,6 +10,17 @@ use crate::source_code::Locator;
use crate::violation::AlwaysAutofixableViolation; use crate::violation::AlwaysAutofixableViolation;
define_violation!( 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; pub struct CommentedOutCode;
); );
impl AlwaysAutofixableViolation for CommentedOutCode { impl AlwaysAutofixableViolation for CommentedOutCode {

View File

@ -18,7 +18,7 @@ mod tests {
fn defaults() -> Result<()> { fn defaults() -> Result<()> {
let diagnostics = test_path( let diagnostics = test_path(
Path::new("flake8_import_conventions/defaults.py"), Path::new("flake8_import_conventions/defaults.py"),
&Settings::for_rule(Rule::ImportAliasIsNotConventional), &Settings::for_rule(Rule::UnconventionalImportAlias),
)?; )?;
assert_yaml_snapshot!("defaults", diagnostics); assert_yaml_snapshot!("defaults", diagnostics);
Ok(()) Ok(())
@ -37,7 +37,7 @@ mod tests {
])), ])),
} }
.into(), .into(),
..Settings::for_rule(Rule::ImportAliasIsNotConventional) ..Settings::for_rule(Rule::UnconventionalImportAlias)
}, },
)?; )?;
assert_yaml_snapshot!("custom", diagnostics); assert_yaml_snapshot!("custom", diagnostics);
@ -59,7 +59,7 @@ mod tests {
extend_aliases: None, extend_aliases: None,
} }
.into(), .into(),
..Settings::for_rule(Rule::ImportAliasIsNotConventional) ..Settings::for_rule(Rule::UnconventionalImportAlias)
}, },
)?; )?;
assert_yaml_snapshot!("remove_default", diagnostics); assert_yaml_snapshot!("remove_default", diagnostics);
@ -79,7 +79,7 @@ mod tests {
)])), )])),
} }
.into(), .into(),
..Settings::for_rule(Rule::ImportAliasIsNotConventional) ..Settings::for_rule(Rule::UnconventionalImportAlias)
}, },
)?; )?;
assert_yaml_snapshot!("override_default", diagnostics); assert_yaml_snapshot!("override_default", diagnostics);
@ -102,7 +102,7 @@ mod tests {
])), ])),
} }
.into(), .into(),
..Settings::for_rule(Rule::ImportAliasIsNotConventional) ..Settings::for_rule(Rule::UnconventionalImportAlias)
}, },
)?; )?;
assert_yaml_snapshot!("from_imports", diagnostics); assert_yaml_snapshot!("from_imports", diagnostics);

View File

@ -7,12 +7,33 @@ use crate::registry::Diagnostic;
use crate::violation::Violation; use crate::violation::Violation;
define_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] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
let ImportAliasIsNotConventional(name, asname) = self; let UnconventionalImportAlias(name, asname) = self;
format!("`{name}` should be imported as `{asname}`") format!("`{name}` should be imported as `{asname}`")
} }
} }
@ -37,7 +58,7 @@ pub fn check_conventional_import(
} }
if !is_valid_import { if !is_valid_import {
return Some(Diagnostic::new( 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), Range::from_located(import_from),
)); ));
} }

View File

@ -1,9 +1,9 @@
--- ---
source: src/rules/flake8_import_conventions/mod.rs source: crates/ruff/src/rules/flake8_import_conventions/mod.rs
expression: diagnostics expression: diagnostics
--- ---
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- altair - altair
- alt - alt
location: location:
@ -15,7 +15,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- dask.array - dask.array
- da - da
location: location:
@ -27,7 +27,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- dask.dataframe - dask.dataframe
- dd - dd
location: location:
@ -39,7 +39,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- matplotlib.pyplot - matplotlib.pyplot
- plt - plt
location: location:
@ -51,7 +51,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- numpy - numpy
- np - np
location: location:
@ -63,7 +63,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- pandas - pandas
- pd - pd
location: location:
@ -75,7 +75,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- seaborn - seaborn
- sns - sns
location: location:
@ -87,7 +87,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- tensorflow - tensorflow
- tf - tf
location: location:
@ -99,7 +99,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- holoviews - holoviews
- hv - hv
location: location:
@ -111,7 +111,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- panel - panel
- pn - pn
location: location:
@ -123,7 +123,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- plotly.express - plotly.express
- px - px
location: location:
@ -135,7 +135,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- matplotlib - matplotlib
- mpl - mpl
location: location:
@ -147,7 +147,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- polars - polars
- pl - pl
location: location:
@ -159,7 +159,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- pyarrow - pyarrow
- pa - pa
location: location:
@ -171,7 +171,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- altair - altair
- alt - alt
location: location:
@ -183,7 +183,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- matplotlib.pyplot - matplotlib.pyplot
- plt - plt
location: location:
@ -195,7 +195,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- dask.array - dask.array
- da - da
location: location:
@ -207,7 +207,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- dask.dataframe - dask.dataframe
- dd - dd
location: location:
@ -219,7 +219,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- numpy - numpy
- np - np
location: location:
@ -231,7 +231,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- pandas - pandas
- pd - pd
location: location:
@ -243,7 +243,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- seaborn - seaborn
- sns - sns
location: location:
@ -255,7 +255,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- tensorflow - tensorflow
- tf - tf
location: location:
@ -267,7 +267,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- holoviews - holoviews
- hv - hv
location: location:
@ -279,7 +279,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- panel - panel
- pn - pn
location: location:
@ -291,7 +291,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- plotly.express - plotly.express
- px - px
location: location:
@ -303,7 +303,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- matplotlib - matplotlib
- mpl - mpl
location: location:
@ -315,7 +315,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- polars - polars
- pl - pl
location: location:
@ -327,7 +327,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- pyarrow - pyarrow
- pa - pa
location: location:

View File

@ -1,9 +1,9 @@
--- ---
source: src/rules/flake8_import_conventions/mod.rs source: crates/ruff/src/rules/flake8_import_conventions/mod.rs
expression: diagnostics expression: diagnostics
--- ---
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- altair - altair
- alt - alt
location: location:
@ -15,7 +15,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- matplotlib.pyplot - matplotlib.pyplot
- plt - plt
location: location:
@ -27,7 +27,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- numpy - numpy
- np - np
location: location:
@ -39,7 +39,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- pandas - pandas
- pd - pd
location: location:
@ -51,7 +51,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- seaborn - seaborn
- sns - sns
location: location:
@ -63,7 +63,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- altair - altair
- alt - alt
location: location:
@ -75,7 +75,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- matplotlib.pyplot - matplotlib.pyplot
- plt - plt
location: location:
@ -87,7 +87,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- numpy - numpy
- np - np
location: location:
@ -99,7 +99,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- pandas - pandas
- pd - pd
location: location:
@ -111,7 +111,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- seaborn - seaborn
- sns - sns
location: location:

View File

@ -1,9 +1,9 @@
--- ---
source: src/rules/flake8_import_conventions/mod.rs source: crates/ruff/src/rules/flake8_import_conventions/mod.rs
expression: diagnostics expression: diagnostics
--- ---
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- xml.dom.minidom - xml.dom.minidom
- md - md
location: location:
@ -15,7 +15,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- xml.dom.minidom - xml.dom.minidom
- md - md
location: location:
@ -27,7 +27,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- xml.dom.minidom - xml.dom.minidom
- md - md
location: location:
@ -39,7 +39,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- xml.dom.minidom - xml.dom.minidom
- md - md
location: location:
@ -51,7 +51,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- xml.dom.minidom.parseString - xml.dom.minidom.parseString
- pstr - pstr
location: location:
@ -63,7 +63,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- xml.dom.minidom.parseString - xml.dom.minidom.parseString
- pstr - pstr
location: location:
@ -75,7 +75,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- xml.dom.minidom.parseString - xml.dom.minidom.parseString
- pstr - pstr
location: location:
@ -87,7 +87,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- xml.dom.minidom.parseString - xml.dom.minidom.parseString
- pstr - pstr
location: location:

View File

@ -1,9 +1,9 @@
--- ---
source: src/rules/flake8_import_conventions/mod.rs source: crates/ruff/src/rules/flake8_import_conventions/mod.rs
expression: diagnostics expression: diagnostics
--- ---
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- altair - altair
- alt - alt
location: location:
@ -15,7 +15,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- matplotlib.pyplot - matplotlib.pyplot
- plt - plt
location: location:
@ -27,7 +27,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- numpy - numpy
- nmp - nmp
location: location:
@ -39,7 +39,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- pandas - pandas
- pd - pd
location: location:
@ -51,7 +51,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- seaborn - seaborn
- sns - sns
location: location:
@ -63,7 +63,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- altair - altair
- alt - alt
location: location:
@ -75,7 +75,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- matplotlib.pyplot - matplotlib.pyplot
- plt - plt
location: location:
@ -87,7 +87,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- numpy - numpy
- nmp - nmp
location: location:
@ -99,7 +99,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- pandas - pandas
- pd - pd
location: location:
@ -111,7 +111,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- seaborn - seaborn
- sns - sns
location: location:

View File

@ -1,9 +1,9 @@
--- ---
source: src/rules/flake8_import_conventions/mod.rs source: crates/ruff/src/rules/flake8_import_conventions/mod.rs
expression: diagnostics expression: diagnostics
--- ---
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- altair - altair
- alt - alt
location: location:
@ -15,7 +15,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- matplotlib.pyplot - matplotlib.pyplot
- plt - plt
location: location:
@ -27,7 +27,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- pandas - pandas
- pd - pd
location: location:
@ -39,7 +39,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- seaborn - seaborn
- sns - sns
location: location:
@ -51,7 +51,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- altair - altair
- alt - alt
location: location:
@ -63,7 +63,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- matplotlib.pyplot - matplotlib.pyplot
- plt - plt
location: location:
@ -75,7 +75,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- pandas - pandas
- pd - pd
location: location:
@ -87,7 +87,7 @@ expression: diagnostics
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ImportAliasIsNotConventional: UnconventionalImportAlias:
- seaborn - seaborn
- sns - sns
location: location:

View File

@ -8,6 +8,23 @@ use crate::registry::Diagnostic;
use crate::violation::Violation; use crate::violation::Violation;
define_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); pub struct ImplicitNamespacePackage(pub String);
); );
impl Violation for ImplicitNamespacePackage { impl Violation for ImplicitNamespacePackage {

View File

@ -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
```

View File

@ -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.

View File

@ -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
```