summaryrefslogtreecommitdiff
path: root/pylint
diff options
context:
space:
mode:
authorNick Drozd <nicholasdrozd@gmail.com>2023-04-02 05:41:26 -0400
committerGitHub <noreply@github.com>2023-04-02 11:41:26 +0200
commit3b42318eddaf0fded622179b19c7bcfcead26893 (patch)
tree502297ad801e6f05d56daff86500c74ba0ee8036 /pylint
parentf7bd67604f395cd50734b9559acc37ae5d34ce4b (diff)
downloadpylint-git-3b42318eddaf0fded622179b19c7bcfcead26893.tar.gz
Add Pyreverse option to exclude standalone nodes (#8520)
* Add Pyreverse option to exclude standalone nodes * Add test * Add package test * Fix test names * Clean up test files
Diffstat (limited to 'pylint')
-rw-r--r--pylint/pyreverse/main.py8
-rw-r--r--pylint/pyreverse/writer.py13
-rw-r--r--pylint/testutils/pyreverse.py2
3 files changed, 23 insertions, 0 deletions
diff --git a/pylint/pyreverse/main.py b/pylint/pyreverse/main.py
index 975e432e4..58128bb57 100644
--- a/pylint/pyreverse/main.py
+++ b/pylint/pyreverse/main.py
@@ -158,6 +158,14 @@ OPTIONS: Options = (
},
),
(
+ "no-standalone",
+ {
+ "action": "store_true",
+ "default": False,
+ "help": "only show nodes with connections",
+ },
+ ),
+ (
"output",
{
"short": "o",
diff --git a/pylint/pyreverse/writer.py b/pylint/pyreverse/writer.py
index cb711dd10..b5cab0a66 100644
--- a/pylint/pyreverse/writer.py
+++ b/pylint/pyreverse/writer.py
@@ -57,6 +57,12 @@ class DiagramWriter:
# sorted to get predictable (hence testable) results
for module in sorted(diagram.modules(), key=lambda x: x.title):
module.fig_id = module.node.qname()
+ if self.config.no_standalone and not any(
+ module in (rel.from_object, rel.to_object)
+ for rel in diagram.get_relationships("depends")
+ ):
+ continue
+
self.printer.emit_node(
module.fig_id,
type_=NodeType.PACKAGE,
@@ -75,6 +81,13 @@ class DiagramWriter:
# sorted to get predictable (hence testable) results
for obj in sorted(diagram.objects, key=lambda x: x.title): # type: ignore[no-any-return]
obj.fig_id = obj.node.qname()
+ if self.config.no_standalone and not any(
+ obj in (rel.from_object, rel.to_object)
+ for rel_type in ("specialization", "association", "aggregation")
+ for rel in diagram.get_relationships(rel_type)
+ ):
+ continue
+
self.printer.emit_node(
obj.fig_id,
type_=NodeType.CLASS,
diff --git a/pylint/testutils/pyreverse.py b/pylint/testutils/pyreverse.py
index ba79ebf8b..24fddad77 100644
--- a/pylint/testutils/pyreverse.py
+++ b/pylint/testutils/pyreverse.py
@@ -37,6 +37,7 @@ class PyreverseConfig(
all_ancestors: bool | None = None,
show_associated: int | None = None,
all_associated: bool | None = None,
+ no_standalone: bool = False,
show_builtin: bool = False,
show_stdlib: bool = False,
module_names: bool | None = None,
@@ -59,6 +60,7 @@ class PyreverseConfig(
self.all_ancestors = all_ancestors
self.show_associated = show_associated
self.all_associated = all_associated
+ self.no_standalone = no_standalone
self.show_builtin = show_builtin
self.show_stdlib = show_stdlib
self.module_names = module_names