From 5b445a6d5e7621c627cfafa3724f23d85becd0c4 Mon Sep 17 00:00:00 2001 From: Zanie Date: Tue, 22 Aug 2023 11:08:43 -0500 Subject: [PATCH] Add `networkx` to conventional aliases --- .../flake8_import_conventions/defaults.py | 4 +- .../flake8_import_conventions/settings.rs | 1 + ...8_import_conventions__tests__defaults.snap | 230 +++++++++++------- 3 files changed, 141 insertions(+), 94 deletions(-) diff --git a/crates/ruff/resources/test/fixtures/flake8_import_conventions/defaults.py b/crates/ruff/resources/test/fixtures/flake8_import_conventions/defaults.py index cfe890b523a20..c1c528deca16e 100644 --- a/crates/ruff/resources/test/fixtures/flake8_import_conventions/defaults.py +++ b/crates/ruff/resources/test/fixtures/flake8_import_conventions/defaults.py @@ -9,6 +9,7 @@ def unconventional(): import pandas import seaborn import tkinter + import networkx def unconventional_aliases(): @@ -18,7 +19,7 @@ def unconventional_aliases(): import pandas as pdas import seaborn as sbrn import tkinter as tkr - + import networkx as nxy def conventional_aliases(): import altair as alt @@ -27,3 +28,4 @@ def conventional_aliases(): import pandas as pd import seaborn as sns import tkinter as tk + import networkx as nx diff --git a/crates/ruff/src/rules/flake8_import_conventions/settings.rs b/crates/ruff/src/rules/flake8_import_conventions/settings.rs index d5a038b54cc82..640aa9509628b 100644 --- a/crates/ruff/src/rules/flake8_import_conventions/settings.rs +++ b/crates/ruff/src/rules/flake8_import_conventions/settings.rs @@ -9,6 +9,7 @@ const CONVENTIONAL_ALIASES: &[(&str, &str)] = &[ ("altair", "alt"), ("matplotlib", "mpl"), ("matplotlib.pyplot", "plt"), + ("networkx", "nx"), ("numpy", "np"), ("pandas", "pd"), ("seaborn", "sns"), diff --git a/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__defaults.snap b/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__defaults.snap index e2f2b0f034028..5cd38193f6830 100644 --- a/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__defaults.snap +++ b/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__defaults.snap @@ -72,7 +72,7 @@ defaults.py:9:12: ICN001 [*] `pandas` should be imported as `pd` 9 |+ import pandas as pd 10 10 | import seaborn 11 11 | import tkinter -12 12 | +12 12 | import networkx defaults.py:10:12: ICN001 [*] `seaborn` should be imported as `sns` | @@ -81,6 +81,7 @@ defaults.py:10:12: ICN001 [*] `seaborn` should be imported as `sns` 10 | import seaborn | ^^^^^^^ ICN001 11 | import tkinter +12 | import networkx | = help: Alias `seaborn` to `sns` @@ -91,7 +92,7 @@ defaults.py:10:12: ICN001 [*] `seaborn` should be imported as `sns` 10 |- import seaborn 10 |+ import seaborn as sns 11 11 | import tkinter -12 12 | +12 12 | import networkx 13 13 | defaults.py:11:12: ICN001 [*] `tkinter` should be imported as `tk` @@ -100,6 +101,7 @@ defaults.py:11:12: ICN001 [*] `tkinter` should be imported as `tk` 10 | import seaborn 11 | import tkinter | ^^^^^^^ ICN001 +12 | import networkx | = help: Alias `tkinter` to `tk` @@ -109,130 +111,172 @@ defaults.py:11:12: ICN001 [*] `tkinter` should be imported as `tk` 10 10 | import seaborn 11 |- import tkinter 11 |+ import tkinter as tk -12 12 | +12 12 | import networkx 13 13 | -14 14 | def unconventional_aliases(): +14 14 | -defaults.py:15:22: ICN001 [*] `altair` should be imported as `alt` +defaults.py:12:12: ICN001 [*] `networkx` should be imported as `nx` | -14 | def unconventional_aliases(): -15 | import altair as altr +10 | import seaborn +11 | import tkinter +12 | import networkx + | ^^^^^^^^ ICN001 + | + = help: Alias `networkx` to `nx` + +ℹ Suggested fix +9 9 | import pandas +10 10 | import seaborn +11 11 | import tkinter +12 |- import networkx + 12 |+ import networkx as nx +13 13 | +14 14 | +15 15 | def unconventional_aliases(): + +defaults.py:16:22: ICN001 [*] `altair` should be imported as `alt` + | +15 | def unconventional_aliases(): +16 | import altair as altr | ^^^^ ICN001 -16 | import matplotlib.pyplot as plot -17 | import numpy as nmp +17 | import matplotlib.pyplot as plot +18 | import numpy as nmp | = help: Alias `altair` to `alt` ℹ Suggested fix -12 12 | 13 13 | -14 14 | def unconventional_aliases(): -15 |- import altair as altr - 15 |+ import altair as alt -16 16 | import matplotlib.pyplot as plot -17 17 | import numpy as nmp -18 18 | import pandas as pdas - -defaults.py:16:33: ICN001 [*] `matplotlib.pyplot` should be imported as `plt` - | -14 | def unconventional_aliases(): -15 | import altair as altr -16 | import matplotlib.pyplot as plot +14 14 | +15 15 | def unconventional_aliases(): +16 |- import altair as altr + 16 |+ import altair as alt +17 17 | import matplotlib.pyplot as plot +18 18 | import numpy as nmp +19 19 | import pandas as pdas + +defaults.py:17:33: ICN001 [*] `matplotlib.pyplot` should be imported as `plt` + | +15 | def unconventional_aliases(): +16 | import altair as altr +17 | import matplotlib.pyplot as plot | ^^^^ ICN001 -17 | import numpy as nmp -18 | import pandas as pdas +18 | import numpy as nmp +19 | import pandas as pdas | = help: Alias `matplotlib.pyplot` to `plt` ℹ Suggested fix -13 13 | -14 14 | def unconventional_aliases(): -15 15 | import altair as altr -16 |- import matplotlib.pyplot as plot - 16 |+ import matplotlib.pyplot as plt -17 17 | import numpy as nmp -18 18 | import pandas as pdas -19 19 | import seaborn as sbrn - -defaults.py:17:21: ICN001 [*] `numpy` should be imported as `np` - | -15 | import altair as altr -16 | import matplotlib.pyplot as plot -17 | import numpy as nmp +14 14 | +15 15 | def unconventional_aliases(): +16 16 | import altair as altr +17 |- import matplotlib.pyplot as plot + 17 |+ import matplotlib.pyplot as plt +18 18 | import numpy as nmp +19 19 | import pandas as pdas +20 20 | import seaborn as sbrn + +defaults.py:18:21: ICN001 [*] `numpy` should be imported as `np` + | +16 | import altair as altr +17 | import matplotlib.pyplot as plot +18 | import numpy as nmp | ^^^ ICN001 -18 | import pandas as pdas -19 | import seaborn as sbrn +19 | import pandas as pdas +20 | import seaborn as sbrn | = help: Alias `numpy` to `np` ℹ Suggested fix -14 14 | def unconventional_aliases(): -15 15 | import altair as altr -16 16 | import matplotlib.pyplot as plot -17 |- import numpy as nmp - 17 |+ import numpy as np -18 18 | import pandas as pdas -19 19 | import seaborn as sbrn -20 20 | import tkinter as tkr - -defaults.py:18:22: ICN001 [*] `pandas` should be imported as `pd` - | -16 | import matplotlib.pyplot as plot -17 | import numpy as nmp -18 | import pandas as pdas +15 15 | def unconventional_aliases(): +16 16 | import altair as altr +17 17 | import matplotlib.pyplot as plot +18 |- import numpy as nmp + 18 |+ import numpy as np +19 19 | import pandas as pdas +20 20 | import seaborn as sbrn +21 21 | import tkinter as tkr + +defaults.py:19:22: ICN001 [*] `pandas` should be imported as `pd` + | +17 | import matplotlib.pyplot as plot +18 | import numpy as nmp +19 | import pandas as pdas | ^^^^ ICN001 -19 | import seaborn as sbrn -20 | import tkinter as tkr +20 | import seaborn as sbrn +21 | import tkinter as tkr | = help: Alias `pandas` to `pd` ℹ Suggested fix -15 15 | import altair as altr -16 16 | import matplotlib.pyplot as plot -17 17 | import numpy as nmp -18 |- import pandas as pdas - 18 |+ import pandas as pd -19 19 | import seaborn as sbrn -20 20 | import tkinter as tkr -21 21 | - -defaults.py:19:23: ICN001 [*] `seaborn` should be imported as `sns` - | -17 | import numpy as nmp -18 | import pandas as pdas -19 | import seaborn as sbrn +16 16 | import altair as altr +17 17 | import matplotlib.pyplot as plot +18 18 | import numpy as nmp +19 |- import pandas as pdas + 19 |+ import pandas as pd +20 20 | import seaborn as sbrn +21 21 | import tkinter as tkr +22 22 | import networkx as nxy + +defaults.py:20:23: ICN001 [*] `seaborn` should be imported as `sns` + | +18 | import numpy as nmp +19 | import pandas as pdas +20 | import seaborn as sbrn | ^^^^ ICN001 -20 | import tkinter as tkr +21 | import tkinter as tkr +22 | import networkx as nxy | = help: Alias `seaborn` to `sns` ℹ Suggested fix -16 16 | import matplotlib.pyplot as plot -17 17 | import numpy as nmp -18 18 | import pandas as pdas -19 |- import seaborn as sbrn - 19 |+ import seaborn as sns -20 20 | import tkinter as tkr -21 21 | -22 22 | - -defaults.py:20:23: ICN001 [*] `tkinter` should be imported as `tk` - | -18 | import pandas as pdas -19 | import seaborn as sbrn -20 | import tkinter as tkr +17 17 | import matplotlib.pyplot as plot +18 18 | import numpy as nmp +19 19 | import pandas as pdas +20 |- import seaborn as sbrn + 20 |+ import seaborn as sns +21 21 | import tkinter as tkr +22 22 | import networkx as nxy +23 23 | + +defaults.py:21:23: ICN001 [*] `tkinter` should be imported as `tk` + | +19 | import pandas as pdas +20 | import seaborn as sbrn +21 | import tkinter as tkr | ^^^ ICN001 +22 | import networkx as nxy | = help: Alias `tkinter` to `tk` ℹ Suggested fix -17 17 | import numpy as nmp -18 18 | import pandas as pdas -19 19 | import seaborn as sbrn -20 |- import tkinter as tkr - 20 |+ import tkinter as tk -21 21 | -22 22 | -23 23 | def conventional_aliases(): +18 18 | import numpy as nmp +19 19 | import pandas as pdas +20 20 | import seaborn as sbrn +21 |- import tkinter as tkr + 21 |+ import tkinter as tk +22 22 | import networkx as nxy +23 23 | +24 24 | def conventional_aliases(): + +defaults.py:22:24: ICN001 [*] `networkx` should be imported as `nx` + | +20 | import seaborn as sbrn +21 | import tkinter as tkr +22 | import networkx as nxy + | ^^^ ICN001 +23 | +24 | def conventional_aliases(): + | + = help: Alias `networkx` to `nx` + +ℹ Suggested fix +19 19 | import pandas as pdas +20 20 | import seaborn as sbrn +21 21 | import tkinter as tkr +22 |- import networkx as nxy + 22 |+ import networkx as nx +23 23 | +24 24 | def conventional_aliases(): +25 25 | import altair as alt