diff options
author | Nick Drozd <nicholasdrozd@gmail.com> | 2023-04-02 05:41:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-02 11:41:26 +0200 |
commit | 3b42318eddaf0fded622179b19c7bcfcead26893 (patch) | |
tree | 502297ad801e6f05d56daff86500c74ba0ee8036 /pylint/pyreverse | |
parent | f7bd67604f395cd50734b9559acc37ae5d34ce4b (diff) | |
download | pylint-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/pyreverse')
-rw-r--r-- | pylint/pyreverse/main.py | 8 | ||||
-rw-r--r-- | pylint/pyreverse/writer.py | 13 |
2 files changed, 21 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, |