mirror of https://github.com/astral-sh/ruff
separate preview defaults test
This commit is contained in:
parent
af7c72f13f
commit
2222bcf51a
|
|
@ -9,27 +9,44 @@ mod tests {
|
|||
use anyhow::Result;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
use crate::assert_diagnostics;
|
||||
use crate::registry::Rule;
|
||||
use crate::rules::flake8_import_conventions::settings::{BannedAliases, default_aliases};
|
||||
use crate::settings::{LinterSettings, types::PreviewMode};
|
||||
use crate::test::test_path;
|
||||
use crate::{assert_diagnostics, assert_diagnostics_diff};
|
||||
|
||||
#[test]
|
||||
fn defaults() -> Result<()> {
|
||||
let settings = LinterSettings {
|
||||
flake8_import_conventions: super::settings::Settings::new(PreviewMode::Enabled),
|
||||
preview: PreviewMode::Enabled,
|
||||
..LinterSettings::for_rules([Rule::UnconventionalImportAlias, Rule::BannedImportAlias])
|
||||
};
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_import_conventions/defaults.py"),
|
||||
&settings,
|
||||
&LinterSettings::for_rule(Rule::UnconventionalImportAlias),
|
||||
)?;
|
||||
assert_diagnostics!(diagnostics);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn defaults_preview() -> Result<()> {
|
||||
assert_diagnostics_diff!(
|
||||
Path::new("flake8_import_conventions/defaults.py"),
|
||||
&LinterSettings {
|
||||
flake8_import_conventions: super::settings::Settings::new(PreviewMode::Disabled),
|
||||
..LinterSettings::for_rules([
|
||||
Rule::UnconventionalImportAlias,
|
||||
Rule::BannedImportAlias
|
||||
])
|
||||
},
|
||||
&LinterSettings {
|
||||
flake8_import_conventions: super::settings::Settings::new(PreviewMode::Enabled),
|
||||
..LinterSettings::for_rules([
|
||||
Rule::UnconventionalImportAlias,
|
||||
Rule::BannedImportAlias
|
||||
])
|
||||
},
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom() -> Result<()> {
|
||||
let mut aliases = default_aliases();
|
||||
|
|
|
|||
|
|
@ -277,33 +277,3 @@ help: Alias `networkx` to `nx`
|
|||
24 |
|
||||
25 | def conventional_aliases():
|
||||
note: This is an unsafe fix and may change runtime behavior
|
||||
|
||||
ICN001 `plotly.graph_objects` should be imported as `go`
|
||||
--> defaults.py:36:8
|
||||
|
|
||||
35 | # ICN001: plotly.graph_objects should be imported as go
|
||||
36 | import plotly.graph_objects # should require alias
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
37 | import plotly.graph_objects as go # ok
|
||||
|
|
||||
help: Alias `plotly.graph_objects` to `go`
|
||||
|
||||
ICN001 `statsmodels.api` should be imported as `sm`
|
||||
--> defaults.py:40:8
|
||||
|
|
||||
39 | # ICN001: statsmodels.api should be imported as sm
|
||||
40 | import statsmodels.api # should require alias
|
||||
| ^^^^^^^^^^^^^^^
|
||||
41 | import statsmodels.api as sm # ok
|
||||
|
|
||||
help: Alias `statsmodels.api` to `sm`
|
||||
|
||||
ICN002 `geopandas` should not be imported as `gpd`
|
||||
--> defaults.py:44:1
|
||||
|
|
||||
43 | # ICN002: geopandas should not be imported as gpd
|
||||
44 | import geopandas as gpd # banned
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
45 | import geopandas # ok
|
||||
46 | import geopandas as gdf # ok
|
||||
|
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_import_conventions/mod.rs
|
||||
---
|
||||
--- Linter settings ---
|
||||
+ plotly.graph_objects = go,
|
||||
+ statsmodels.api = sm,
|
||||
-linter.flake8_import_conventions.banned_aliases = {}
|
||||
+linter.flake8_import_conventions.banned_aliases = {
|
||||
+ geopandas = [gpd],
|
||||
+}
|
||||
|
||||
--- Summary ---
|
||||
Removed: 0
|
||||
Added: 3
|
||||
|
||||
--- Added ---
|
||||
ICN001 `plotly.graph_objects` should be imported as `go`
|
||||
--> defaults.py:36:8
|
||||
|
|
||||
35 | # ICN001: plotly.graph_objects should be imported as go
|
||||
36 | import plotly.graph_objects # should require alias
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
37 | import plotly.graph_objects as go # ok
|
||||
|
|
||||
help: Alias `plotly.graph_objects` to `go`
|
||||
|
||||
|
||||
ICN001 `statsmodels.api` should be imported as `sm`
|
||||
--> defaults.py:40:8
|
||||
|
|
||||
39 | # ICN001: statsmodels.api should be imported as sm
|
||||
40 | import statsmodels.api # should require alias
|
||||
| ^^^^^^^^^^^^^^^
|
||||
41 | import statsmodels.api as sm # ok
|
||||
|
|
||||
help: Alias `statsmodels.api` to `sm`
|
||||
|
||||
|
||||
ICN002 `geopandas` should not be imported as `gpd`
|
||||
--> defaults.py:44:1
|
||||
|
|
||||
43 | # ICN002: geopandas should not be imported as gpd
|
||||
44 | import geopandas as gpd # banned
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
45 | import geopandas # ok
|
||||
46 | import geopandas as gdf # ok
|
||||
|
|
||||
Loading…
Reference in New Issue