|
1 | 1 | # typed: true |
2 | 2 |
|
3 | | -module QueryPackwerk::ConsoleHelpers |
4 | | - extend T::Sig |
| 3 | +module QueryPackwerk |
| 4 | + module ConsoleHelpers |
| 5 | + extend T::Sig |
5 | 6 |
|
6 | | - sig { returns(String) } |
7 | | - def inspect |
8 | | - 'query_packwerk console' |
9 | | - end |
10 | | - |
11 | | - sig { returns(NilClass) } # returning nil is less ugly in the console. |
12 | | - def welcome |
13 | | - help_query_packwerk |
14 | | - puts |
15 | | - help_help |
16 | | - end |
| 7 | + sig { returns(String) } |
| 8 | + def inspect |
| 9 | + 'query_packwerk console' |
| 10 | + end |
17 | 11 |
|
18 | | - sig { params(type: T.nilable(T.any(String, Symbol))).returns(NilClass) } |
19 | | - def help(type = nil) |
20 | | - case type.to_s.downcase |
21 | | - when 'violation' |
22 | | - help_violation |
23 | | - when 'violations' |
24 | | - help_violations |
25 | | - when 'package' |
26 | | - help_package |
27 | | - when 'packages' |
28 | | - help_packages |
29 | | - when '', 'help' |
30 | | - help_help |
31 | | - else |
32 | | - puts "Unknown help topic: #{type}\n" |
| 12 | + sig { returns(NilClass) } # returning nil is less ugly in the console. |
| 13 | + def welcome |
| 14 | + help_query_packwerk |
| 15 | + puts |
33 | 16 | help_help |
34 | 17 | end |
35 | | - end |
36 | 18 |
|
37 | | - sig { returns(NilClass) } |
38 | | - def help_help |
39 | | - puts <<~HELP |
40 | | - Available help topics: |
41 | | - help # This help |
42 | | - help_violation # Help for QueryPackwerk::Violation |
43 | | - help_violations # Help for QueryPackwerk::Violations |
44 | | - help_package # Help for QueryPackwerk::Package |
45 | | - help_packages # Help for QueryPackwerk::Packages |
46 | | - HELP |
47 | | - end |
| 19 | + sig { params(type: T.nilable(T.any(String, Symbol))).returns(NilClass) } |
| 20 | + def help(type = nil) |
| 21 | + case type.to_s.downcase |
| 22 | + when 'violation' |
| 23 | + help_violation |
| 24 | + when 'violations' |
| 25 | + help_violations |
| 26 | + when 'package' |
| 27 | + help_package |
| 28 | + when 'packages' |
| 29 | + help_packages |
| 30 | + when '', 'help' |
| 31 | + help_help |
| 32 | + else |
| 33 | + puts "Unknown help topic: #{type}\n" |
| 34 | + help_help |
| 35 | + end |
| 36 | + end |
48 | 37 |
|
49 | | - sig { returns(NilClass) } |
50 | | - def help_violation |
51 | | - puts <<~HELP |
52 | | - QueryPackwerk::Violation (lib/query_packwerk/violation.rb) |
53 | | - ------------------------------------------------ |
54 | | - .type # Returns the violation type ('privacy' or 'dependency') |
55 | | - .class_name # Returns the violated constant name |
56 | | - .files # Returns array of files containing the violation |
57 | | - .producing_pack # Returns the Package that owns the violated constant |
58 | | - .consuming_pack # Returns the Package that violated the constant |
59 | | - .sources # Returns array of AST nodes representing the violation occurrences |
60 | | - .sources_with_locations # Returns array of [file:line, source] pairs for each violation |
61 | | - .source_counts # Returns hash of how often each violation source occurs |
62 | | - .anonymous_sources # Returns array of violation sources with arguments anonymized |
63 | | - .anonymous_sources_with_locations # Returns array of [file:line, source] pairs for each violation with arguments anonymized |
64 | | - .count # Returns total number of violation occurrences |
65 | | - HELP |
66 | | - end |
| 38 | + sig { returns(NilClass) } |
| 39 | + def help_help |
| 40 | + puts <<~HELP |
| 41 | + Available help topics: |
| 42 | + help # This help |
| 43 | + help_violation # Help for QueryPackwerk::Violation |
| 44 | + help_violations # Help for QueryPackwerk::Violations |
| 45 | + help_package # Help for QueryPackwerk::Package |
| 46 | + help_packages # Help for QueryPackwerk::Packages |
| 47 | + HELP |
| 48 | + end |
67 | 49 |
|
68 | | - sig { returns(NilClass) } |
69 | | - def help_violations |
70 | | - puts <<~HELP |
71 | | - QueryPackwerk::Violations (lib/query_packwerk/violations.rb) |
72 | | - -------------------------------------------------- |
73 | | - .where(conditions) # Returns new Violations filtered by conditions |
74 | | - .raw_sources # Returns hash of constant => AST nodes for all violations |
75 | | - .sources # Returns hash of constant => source strings for all violations |
76 | | - .sources_with_locations # Returns hash of constant => [file:line, source] pairs |
77 | | - .source_counts # Returns hash of constant => {source => count} with occurrence counts |
78 | | - .sources_with_contexts # Returns hash of constant => [file:line, source] pairs for each violation with context |
79 | | - .anonymous_sources # Returns hash of constant => anonymized sources |
80 | | - .anonymous_sources_with_locations # Returns array of [file:line, source] pairs for each violation with arguments anonymized |
81 | | - .consumers(threshold) # Returns hash of consuming package names and violation counts |
82 | | - .producers(threshold) # Returns hash of producing package names and violation counts |
83 | | - .including_files(globs) # Returns new Violations filtered to include specific files |
84 | | - .excluding_files(globs) # Returns new Violations filtered to exclude specific files |
85 | | - HELP |
86 | | - end |
| 50 | + sig { returns(NilClass) } |
| 51 | + def help_violation |
| 52 | + puts <<~HELP |
| 53 | + QueryPackwerk::Violation (lib/query_packwerk/violation.rb) |
| 54 | + ------------------------------------------------ |
| 55 | + .type # Returns the violation type ('privacy' or 'dependency') |
| 56 | + .class_name # Returns the violated constant name |
| 57 | + .files # Returns array of files containing the violation |
| 58 | + .producing_pack # Returns the Package that owns the violated constant |
| 59 | + .consuming_pack # Returns the Package that violated the constant |
| 60 | + .sources # Returns array of AST nodes representing the violation occurrences |
| 61 | + .sources_with_locations # Returns array of [file:line, source] pairs for each violation |
| 62 | + .source_counts # Returns hash of how often each violation source occurs |
| 63 | + .anonymous_sources # Returns array of violation sources with arguments anonymized |
| 64 | + .anonymous_sources_with_locations # Returns array of [file:line, source] pairs for each violation with arguments anonymized |
| 65 | + .count # Returns total number of violation occurrences |
| 66 | + HELP |
| 67 | + end |
87 | 68 |
|
88 | | - sig { returns(NilClass) } |
89 | | - def help_package |
90 | | - puts <<~HELP |
91 | | - QueryPackwerk::Package (lib/query_packwerk/package.rb) |
92 | | - ---------------------------------------------- |
93 | | - .name # Returns the package name |
94 | | - .enforce_dependencies # Returns whether package enforces dependencies |
95 | | - .enforce_privacy # Returns whether package enforces privacy |
96 | | - .metadata # Returns the package metadata from package.yml |
97 | | - .config # Returns the package configuration |
98 | | - .dependencies # Returns Packages collection of dependencies |
99 | | - .dependency_names # Returns array of dependency package names |
100 | | - .owner # Returns the package owner or 'Unowned' |
101 | | - .directory # Returns the package directory path |
102 | | - .todos # Returns Violations where this package is the consumer |
103 | | - .violations # Returns Violations where this package is the producer |
104 | | - .consumers # Returns Packages that consume this package |
105 | | - .consumer_names # Returns array of names of consuming packages |
106 | | - .consumer_counts # Returns hash of consumer package names and counts |
107 | | - HELP |
108 | | - end |
| 69 | + sig { returns(NilClass) } |
| 70 | + def help_violations |
| 71 | + puts <<~HELP |
| 72 | + QueryPackwerk::Violations (lib/query_packwerk/violations.rb) |
| 73 | + -------------------------------------------------- |
| 74 | + .where(conditions) # Returns new Violations filtered by conditions |
| 75 | + .raw_sources # Returns hash of constant => AST nodes for all violations |
| 76 | + .sources # Returns hash of constant => source strings for all violations |
| 77 | + .sources_with_locations # Returns hash of constant => [file:line, source] pairs |
| 78 | + .source_counts # Returns hash of constant => {source => count} with occurrence counts |
| 79 | + .sources_with_contexts # Returns hash of constant => [file:line, source] pairs for each violation with context |
| 80 | + .anonymous_sources # Returns hash of constant => anonymized sources |
| 81 | + .anonymous_sources_with_locations # Returns array of [file:line, source] pairs for each violation with arguments anonymized |
| 82 | + .consumers(threshold) # Returns hash of consuming package names and violation counts |
| 83 | + .producers(threshold) # Returns hash of producing package names and violation counts |
| 84 | + .including_files(globs) # Returns new Violations filtered to include specific files |
| 85 | + .excluding_files(globs) # Returns new Violations filtered to exclude specific files |
| 86 | + HELP |
| 87 | + end |
109 | 88 |
|
110 | | - sig { returns(NilClass) } |
111 | | - def help_packages |
112 | | - puts <<~HELP |
113 | | - QueryPackwerk::Packages (lib/query_packwerk/packages.rb) |
114 | | - ------------------------------------------------ |
115 | | - .all # Returns all packages in the application |
116 | | - .where(conditions) # Returns new Packages filtered by conditions |
117 | | - .violations # Returns Violations for all packages in collection |
118 | | - HELP |
119 | | - end |
| 89 | + sig { returns(NilClass) } |
| 90 | + def help_package |
| 91 | + puts <<~HELP |
| 92 | + QueryPackwerk::Package (lib/query_packwerk/package.rb) |
| 93 | + ---------------------------------------------- |
| 94 | + .name # Returns the package name |
| 95 | + .enforce_dependencies # Returns whether package enforces dependencies |
| 96 | + .enforce_privacy # Returns whether package enforces privacy |
| 97 | + .metadata # Returns the package metadata from package.yml |
| 98 | + .config # Returns the package configuration |
| 99 | + .dependencies # Returns Packages collection of dependencies |
| 100 | + .dependency_names # Returns array of dependency package names |
| 101 | + .owner # Returns the package owner or 'Unowned' |
| 102 | + .directory # Returns the package directory path |
| 103 | + .todos # Returns Violations where this package is the consumer |
| 104 | + .violations # Returns Violations where this package is the producer |
| 105 | + .consumers # Returns Packages that consume this package |
| 106 | + .consumer_names # Returns array of names of consuming packages |
| 107 | + .consumer_counts # Returns hash of consumer package names and counts |
| 108 | + HELP |
| 109 | + end |
| 110 | + |
| 111 | + sig { returns(NilClass) } |
| 112 | + def help_packages |
| 113 | + puts <<~HELP |
| 114 | + QueryPackwerk::Packages (lib/query_packwerk/packages.rb) |
| 115 | + ------------------------------------------------ |
| 116 | + .all # Returns all packages in the application |
| 117 | + .where(conditions) # Returns new Packages filtered by conditions |
| 118 | + .violations # Returns Violations for all packages in collection |
| 119 | + HELP |
| 120 | + end |
120 | 121 |
|
121 | | - sig { returns(NilClass) } |
122 | | - def help_query_packwerk |
123 | | - puts <<~HELP |
124 | | - QueryPackwerk (lib/query_packwerk.rb) |
125 | | - ------------------------------ |
126 | | - Available commands: |
127 | | - package(pack_name) # Get a package by name |
128 | | - Packages.all # Get all packages |
| 122 | + sig { returns(NilClass) } |
| 123 | + def help_query_packwerk |
| 124 | + puts <<~HELP |
| 125 | + QueryPackwerk (lib/query_packwerk.rb) |
| 126 | + ------------------------------ |
| 127 | + Available commands: |
| 128 | + package(pack_name) # Get a package by name |
| 129 | + Packages.all # Get all packages |
129 | 130 |
|
130 | | - Package Consumption (how others use this package): |
131 | | - violations_for(pack_name) # Get all violations where others access this package |
132 | | - violation_sources_for(pack_name) # Get where others access this package |
133 | | - violation_counts_for(pack_name) # Get how often others access this package |
134 | | - anonymous_violation_sources_for(pack_name) # Get the 'shape' of how others access this package |
135 | | - anonymous_violation_counts_for(pack_name) # Get how often each access pattern occurs |
136 | | - consumers(pack_name) # Get which packages consume this package |
| 131 | + Package Consumption (how others use this package): |
| 132 | + violations_for(pack_name) # Get all violations where others access this package |
| 133 | + violation_sources_for(pack_name) # Get where others access this package |
| 134 | + violation_counts_for(pack_name) # Get how often others access this package |
| 135 | + anonymous_violation_sources_for(pack_name) # Get the 'shape' of how others access this package |
| 136 | + anonymous_violation_counts_for(pack_name) # Get how often each access pattern occurs |
| 137 | + consumers(pack_name) # Get which packages consume this package |
137 | 138 |
|
138 | | - Package Dependencies (how this package uses others): |
139 | | - todos_for(pack_name) # Get all todos where this package accesses others |
| 139 | + Package Dependencies (how this package uses others): |
| 140 | + todos_for(pack_name) # Get all todos where this package accesses others |
140 | 141 |
|
141 | | - Violations.all # Get all violations |
142 | | - HELP |
| 142 | + Violations.all # Get all violations |
| 143 | + HELP |
| 144 | + end |
143 | 145 | end |
144 | 146 | end |
0 commit comments