rubocop-view_component 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/default.yml +1 -0
- data/lib/rubocop/cop/view_component/test_rendered_output.rb +10 -0
- data/lib/rubocop/view_component/version.rb +1 -1
- data/script/verify +38 -19
- data/spec/expected_govuk_failures.yml +39 -0
- data/spec/expected_polaris_failures.yml +65 -0
- data/spec/expected_primer_failures.yml +27 -0
- data/spec/rubocop/cop/view_component/test_rendered_output_spec.rb +34 -0
- data/verification/primer_rubocop_config.yml +5 -0
- metadata +4 -4
- data/spec/expected_govuk_failures.json +0 -200
- data/spec/expected_polaris_failures.json +0 -356
- data/spec/expected_primer_failures.json +0 -830
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2ff827bf609adb03d687cb67fd54a92034775774f64cd0aa2808f3ceafc111fd
|
|
4
|
+
data.tar.gz: edadf55c4fdfdfb845a4377a23181358fc8a3fe178e1855ab97c96d41f775d84
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f8e2797d135b4978f4dc2abce7f36d0789382d3d494d6843bc3aa20c46406c8820cd916028e4ccc780b72035746416ac5db3ca9cbc24543dcf8928846d6d348f
|
|
7
|
+
data.tar.gz: 5615b9b6c3c9f3f195a99bd6e9e3bee741039e383d59d19be8f1c2bc1a3a5cbd9d06bed97dae181b54e84087ebf477be3038b1f26476e079d254ad62612417da
|
data/config/default.yml
CHANGED
|
@@ -27,6 +27,7 @@ module RuboCop
|
|
|
27
27
|
|
|
28
28
|
# Check Minitest-style test methods
|
|
29
29
|
def on_def(node)
|
|
30
|
+
return unless within_test_paths?
|
|
30
31
|
method_name = node.method_name.to_s
|
|
31
32
|
return unless method_name.start_with?("test_")
|
|
32
33
|
return unless instantiates_component?(node)
|
|
@@ -37,6 +38,7 @@ module RuboCop
|
|
|
37
38
|
|
|
38
39
|
# Check RSpec-style it blocks
|
|
39
40
|
def on_block(node)
|
|
41
|
+
return unless within_test_paths?
|
|
40
42
|
return unless rspec_it_block?(node)
|
|
41
43
|
return unless instantiates_component?(node)
|
|
42
44
|
return if contains_render_method?(node)
|
|
@@ -46,6 +48,14 @@ module RuboCop
|
|
|
46
48
|
|
|
47
49
|
private
|
|
48
50
|
|
|
51
|
+
def within_test_paths?
|
|
52
|
+
test_paths = cop_config["TestPaths"]
|
|
53
|
+
return true if test_paths.nil? || test_paths.empty?
|
|
54
|
+
|
|
55
|
+
file_path = processed_source.path
|
|
56
|
+
test_paths.any? { |path| file_path.include?(path) }
|
|
57
|
+
end
|
|
58
|
+
|
|
49
59
|
def instantiates_component?(node)
|
|
50
60
|
node.each_descendant(:send).any? do |send_node|
|
|
51
61
|
next unless send_node.method_name == :new
|
data/script/verify
CHANGED
|
@@ -21,7 +21,7 @@ def load_libraries
|
|
|
21
21
|
tarball_url: library["tarball_url"],
|
|
22
22
|
verification_dir: File.join(GEM_DIR, "verification", library_key),
|
|
23
23
|
config_file: File.join(GEM_DIR, "verification", "#{library_key}_rubocop_config.yml"),
|
|
24
|
-
results_file: File.join(GEM_DIR, "spec", "expected_#{library_key}_failures.
|
|
24
|
+
results_file: File.join(GEM_DIR, "spec", "expected_#{library_key}_failures.yml"),
|
|
25
25
|
display_name: library["display_name"]
|
|
26
26
|
}
|
|
27
27
|
end
|
|
@@ -134,22 +134,39 @@ end
|
|
|
134
134
|
|
|
135
135
|
def extract_offenses(rubocop_output)
|
|
136
136
|
data = JSON.parse(rubocop_output)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
"
|
|
143
|
-
|
|
137
|
+
offenses_by_cop = Hash.new { |h, k| h[k] = [] }
|
|
138
|
+
|
|
139
|
+
data["files"].each do |file|
|
|
140
|
+
file["offenses"].each do |offense|
|
|
141
|
+
offenses_by_cop[offense["cop_name"]] << {
|
|
142
|
+
location: "#{file["path"]}:#{offense["location"]["start_line"]}",
|
|
143
|
+
message: offense["message"]
|
|
144
144
|
}
|
|
145
145
|
end
|
|
146
146
|
end
|
|
147
|
+
|
|
148
|
+
offenses_by_cop.transform_values { |os| os.sort_by { |o| o[:location] } }.sort.to_h
|
|
147
149
|
end
|
|
148
150
|
|
|
149
151
|
def regenerate(offenses, results_file)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
lines = []
|
|
153
|
+
lines << "# This file is auto-generated by `script/verify --regenerate`."
|
|
154
|
+
lines << "# It captures known offenses in the library source."
|
|
155
|
+
lines << "---"
|
|
156
|
+
|
|
157
|
+
offenses.each do |cop, entries|
|
|
158
|
+
lines << "#{cop}:"
|
|
159
|
+
entries.each { |e| lines << " - #{e[:location]} # #{e[:message]}" }
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
File.write(results_file, lines.join("\n") + "\n")
|
|
163
|
+
total = offenses.values.sum(&:length)
|
|
164
|
+
puts "#{total} offense(s) written to #{results_file}"
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def load_expected(results_file)
|
|
168
|
+
# YAML strips inline comments, so each entry loads as just the location string
|
|
169
|
+
YAML.load_file(results_file)
|
|
153
170
|
end
|
|
154
171
|
|
|
155
172
|
def verify(offenses, results_file)
|
|
@@ -157,19 +174,21 @@ def verify(offenses, results_file)
|
|
|
157
174
|
abort "ERROR: #{results_file} not found. Run '#{$PROGRAM_NAME} --regenerate' first."
|
|
158
175
|
end
|
|
159
176
|
|
|
160
|
-
|
|
161
|
-
|
|
177
|
+
expected = load_expected(results_file)
|
|
178
|
+
current = offenses.transform_values { |os| os.map { |o| o[:location] } }
|
|
162
179
|
|
|
163
|
-
if
|
|
180
|
+
if current == expected
|
|
164
181
|
puts "Verification passed: output matches #{results_file}"
|
|
165
182
|
else
|
|
166
183
|
puts "Verification failed: output differs from #{results_file}"
|
|
167
|
-
expected = JSON.parse(expected_json)
|
|
168
|
-
added = offenses - expected
|
|
169
|
-
removed = expected - offenses
|
|
170
184
|
|
|
171
|
-
|
|
172
|
-
|
|
185
|
+
all_cops = (current.keys + expected.keys).uniq.sort
|
|
186
|
+
all_cops.each do |cop|
|
|
187
|
+
added = (current[cop] || []) - (expected[cop] || [])
|
|
188
|
+
removed = (expected[cop] || []) - (current[cop] || [])
|
|
189
|
+
added.each { |loc| puts " + #{cop}: #{loc}" }
|
|
190
|
+
removed.each { |loc| puts " - #{cop}: #{loc}" }
|
|
191
|
+
end
|
|
173
192
|
|
|
174
193
|
exit 1
|
|
175
194
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# This file is auto-generated by `script/verify --regenerate`.
|
|
2
|
+
# It captures known offenses in the library source.
|
|
3
|
+
---
|
|
4
|
+
ViewComponent/ComponentSuffix:
|
|
5
|
+
- app/components/govuk_component/base.rb:1 # ViewComponent class names should end with `Component`. (https://viewcomponent.org/best_practices.html)
|
|
6
|
+
- app/components/govuk_component/header_component.rb:46 # ViewComponent class names should end with `Component`. (https://viewcomponent.org/best_practices.html)
|
|
7
|
+
- app/components/govuk_component/notification_banner_component.rb:33 # ViewComponent class names should end with `Component`. (https://viewcomponent.org/best_practices.html)
|
|
8
|
+
- app/components/govuk_component/pagination_component/adjacent_page.rb:1 # ViewComponent class names should end with `Component`. (https://viewcomponent.org/best_practices.html)
|
|
9
|
+
- app/components/govuk_component/pagination_component/item.rb:1 # ViewComponent class names should end with `Component`. (https://viewcomponent.org/best_practices.html)
|
|
10
|
+
- app/components/govuk_component/tab_component.rb:21 # ViewComponent class names should end with `Component`. (https://viewcomponent.org/best_practices.html)
|
|
11
|
+
ViewComponent/PreferPrivateMethods:
|
|
12
|
+
- app/components/govuk_component/base.rb:29 # Consider making `brand` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)
|
|
13
|
+
- app/components/govuk_component/base.rb:35 # Consider making `class_prefix` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)
|
|
14
|
+
- app/components/govuk_component/notification_banner_component.rb:55 # Consider making `link` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)
|
|
15
|
+
- app/components/govuk_component/notification_banner_component.rb:59 # Consider making `default_attributes` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)
|
|
16
|
+
- app/components/govuk_component/service_navigation_component.rb:54 # Consider making `navigation` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)
|
|
17
|
+
- app/components/govuk_component/service_navigation_component.rb:62 # Consider making `navigation_list` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)
|
|
18
|
+
- app/components/govuk_component/tab_component.rb:32 # Consider making `hidden_class` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)
|
|
19
|
+
- app/components/govuk_component/tab_component.rb:38 # Consider making `li_classes` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)
|
|
20
|
+
- app/components/govuk_component/tab_component.rb:42 # Consider making `li_link` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)
|
|
21
|
+
- app/components/govuk_component/tab_component.rb:46 # Consider making `default_attributes` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)
|
|
22
|
+
- app/components/govuk_component/tab_component.rb:50 # Consider making `combined_attributes` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)
|
|
23
|
+
ViewComponent/TestRenderedOutput:
|
|
24
|
+
- spec/components/govuk_component/accordion_component_spec.rb:84 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
25
|
+
- spec/components/govuk_component/breadcrumbs_component_spec.rb:44 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
26
|
+
- spec/components/govuk_component/configuration/footer_component_configuration_spec.rb:42 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
27
|
+
- spec/components/govuk_component/footer_component_spec.rb:123 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
28
|
+
- spec/components/govuk_component/footer_component_spec.rb:182 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
29
|
+
- spec/components/govuk_component/footer_component_spec.rb:235 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
30
|
+
- spec/components/govuk_component/footer_component_spec.rb:254 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
31
|
+
- spec/components/govuk_component/footer_component_spec.rb:274 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
32
|
+
- spec/components/govuk_component/footer_component_spec.rb:294 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
33
|
+
- spec/components/govuk_component/footer_component_spec.rb:312 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
34
|
+
- spec/components/govuk_component/footer_component_spec.rb:336 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
35
|
+
- spec/components/govuk_component/notification_banner_component_spec.rb:59 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
36
|
+
- spec/components/govuk_component/pagination_component_spec.rb:317 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
37
|
+
- spec/components/govuk_component/task_list_component_spec.rb:139 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
38
|
+
- spec/components/govuk_component/warning_text_component_spec.rb:11 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
39
|
+
- spec/components/govuk_component/warning_text_component_spec.rb:41 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# This file is auto-generated by `script/verify --regenerate`.
|
|
2
|
+
# It captures known offenses in the library source.
|
|
3
|
+
---
|
|
4
|
+
ViewComponent/ComponentSuffix:
|
|
5
|
+
- app/components/polaris/base_button.rb:4 # ViewComponent class names should end with `Component`.
|
|
6
|
+
- app/components/polaris/base_checkbox.rb:2 # ViewComponent class names should end with `Component`.
|
|
7
|
+
- app/components/polaris/base_radio_button.rb:2 # ViewComponent class names should end with `Component`.
|
|
8
|
+
- app/components/polaris/headless_button.rb:4 # ViewComponent class names should end with `Component`.
|
|
9
|
+
- app/components/polaris/layout/annotated_section.rb:5 # ViewComponent class names should end with `Component`.
|
|
10
|
+
- app/components/polaris/layout/section.rb:5 # ViewComponent class names should end with `Component`.
|
|
11
|
+
- app/components/polaris/text_field_component.rb:195 # ViewComponent class names should end with `Component`.
|
|
12
|
+
ViewComponent/NoGlobalState:
|
|
13
|
+
- app/components/polaris/shopify_navigation_component.rb:59 # Avoid accessing `request` directly in ViewComponents. Pass necessary data through the constructor instead.
|
|
14
|
+
ViewComponent/PreferPrivateMethods:
|
|
15
|
+
- app/components/polaris/action_list/section_component.rb:16 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
16
|
+
- app/components/polaris/avatar_component.rb:43 # Consider making `style_class` private. Only ViewComponent interface methods should be public.
|
|
17
|
+
- app/components/polaris/avatar_component.rb:69 # Consider making `xor_hash` private. Only ViewComponent interface methods should be public.
|
|
18
|
+
- app/components/polaris/banner_component.rb:77 # Consider making `default_icon` private. Only ViewComponent interface methods should be public.
|
|
19
|
+
- app/components/polaris/base_checkbox.rb:24 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
20
|
+
- app/components/polaris/base_checkbox.rb:40 # Consider making `indeterminate?` private. Only ViewComponent interface methods should be public.
|
|
21
|
+
- app/components/polaris/base_radio_button.rb:21 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
22
|
+
- app/components/polaris/button_group_component.rb:60 # Consider making `all_items` private. Only ViewComponent interface methods should be public.
|
|
23
|
+
- app/components/polaris/checkbox_component.rb:62 # Consider making `indeterminate?` private. Only ViewComponent interface methods should be public.
|
|
24
|
+
- app/components/polaris/choice_list_component.rb:58 # Consider making `renders?` private. Only ViewComponent interface methods should be public.
|
|
25
|
+
- app/components/polaris/choice_list_component.rb:62 # Consider making `multiple_choice_allowed?` private. Only ViewComponent interface methods should be public.
|
|
26
|
+
- app/components/polaris/collapsible_component.rb:15 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
27
|
+
- app/components/polaris/description_list_component.rb:24 # Consider making `renders?` private. Only ViewComponent interface methods should be public.
|
|
28
|
+
- app/components/polaris/dropzone_component.rb:142 # Consider making `drop_actions` private. Only ViewComponent interface methods should be public.
|
|
29
|
+
- app/components/polaris/exception_list_component.rb:16 # Consider making `renders?` private. Only ViewComponent interface methods should be public.
|
|
30
|
+
- app/components/polaris/filters_component.rb:74 # Consider making `popover_arguments` private. Only ViewComponent interface methods should be public.
|
|
31
|
+
- app/components/polaris/form_layout_component.rb:29 # Consider making `all_items` private. Only ViewComponent interface methods should be public.
|
|
32
|
+
- app/components/polaris/headless_button.rb:104 # Consider making `html_options` private. Only ViewComponent interface methods should be public.
|
|
33
|
+
- app/components/polaris/headless_button.rb:96 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
34
|
+
- app/components/polaris/index_table/cell_component.rb:7 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
35
|
+
- app/components/polaris/inline_error_component.rb:14 # Consider making `renders?` private. Only ViewComponent interface methods should be public.
|
|
36
|
+
- app/components/polaris/keyboard_key_component.rb:9 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
37
|
+
- app/components/polaris/label_component.rb:32 # Consider making `renders?` private. Only ViewComponent interface methods should be public.
|
|
38
|
+
- app/components/polaris/layout_component.rb:38 # Consider making `all_sections` private. Only ViewComponent interface methods should be public.
|
|
39
|
+
- app/components/polaris/modal/section_component.rb:6 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
40
|
+
- app/components/polaris/navigation/item_component.rb:54 # Consider making `item_inner_wrapper_classes` private. Only ViewComponent interface methods should be public.
|
|
41
|
+
- app/components/polaris/navigation/item_component.rb:62 # Consider making `link_classes` private. Only ViewComponent interface methods should be public.
|
|
42
|
+
- app/components/polaris/navigation/item_component.rb:71 # Consider making `selected_sub_items?` private. Only ViewComponent interface methods should be public.
|
|
43
|
+
- app/components/polaris/navigation_component.rb:11 # Consider making `renders?` private. Only ViewComponent interface methods should be public.
|
|
44
|
+
- app/components/polaris/navigation_list_component.rb:9 # Consider making `renders?` private. Only ViewComponent interface methods should be public.
|
|
45
|
+
- app/components/polaris/new_tabs_component.rb:33 # Consider making `renders?` private. Only ViewComponent interface methods should be public.
|
|
46
|
+
- app/components/polaris/option_list/checkbox_component.rb:25 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
47
|
+
- app/components/polaris/option_list/option_component.rb:6 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
48
|
+
- app/components/polaris/option_list/radio_button_component.rb:32 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
49
|
+
- app/components/polaris/option_list/section_component.rb:42 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
50
|
+
- app/components/polaris/page_component.rb:57 # Consider making `title_length` private. Only ViewComponent interface methods should be public.
|
|
51
|
+
- app/components/polaris/popover/section_component.rb:6 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
52
|
+
- app/components/polaris/popover_component.rb:112 # Consider making `popover_placement` private. Only ViewComponent interface methods should be public.
|
|
53
|
+
- app/components/polaris/resource_item/shortcut_actions_component.rb:82 # Consider making `action_list_item_arguments` private. Only ViewComponent interface methods should be public.
|
|
54
|
+
- app/components/polaris/resource_list_component.rb:37 # Consider making `resource_string` private. Only ViewComponent interface methods should be public.
|
|
55
|
+
- app/components/polaris/resource_list_component.rb:43 # Consider making `count` private. Only ViewComponent interface methods should be public.
|
|
56
|
+
- app/components/polaris/select_component.rb:88 # Consider making `hides_label?` private. Only ViewComponent interface methods should be public.
|
|
57
|
+
- app/components/polaris/shopify_navigation_component.rb:40 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
58
|
+
- app/components/polaris/shopify_navigation_component.rb:56 # Consider making `detect_active` private. Only ViewComponent interface methods should be public.
|
|
59
|
+
- app/components/polaris/skeleton_display_text_component.rb:17 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
60
|
+
- app/components/polaris/skeleton_thumbnail_component.rb:16 # Consider making `system_arguments` private. Only ViewComponent interface methods should be public.
|
|
61
|
+
- app/components/polaris/tabs_component.rb:33 # Consider making `renders?` private. Only ViewComponent interface methods should be public.
|
|
62
|
+
- app/components/polaris/text_component.rb:114 # Consider making `alignment_class` private. Only ViewComponent interface methods should be public.
|
|
63
|
+
- app/components/polaris/text_component.rb:120 # Consider making `color_class` private. Only ViewComponent interface methods should be public.
|
|
64
|
+
- app/components/polaris/text_component.rb:126 # Consider making `font_weight_class` private. Only ViewComponent interface methods should be public.
|
|
65
|
+
- app/components/polaris/thumbnail_component.rb:39 # Consider making `renders?` private. Only ViewComponent interface methods should be public.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# This file is auto-generated by `script/verify --regenerate`.
|
|
2
|
+
# It captures known offenses in the library source.
|
|
3
|
+
---
|
|
4
|
+
ViewComponent/PreferPrivateMethods:
|
|
5
|
+
- app/components/primer/alpha/action_list.rb:189 # Consider making `build_item` private. Only ViewComponent interface methods should be public.
|
|
6
|
+
- app/components/primer/alpha/action_list.rb:217 # Consider making `build_avatar_item` private. Only ViewComponent interface methods should be public.
|
|
7
|
+
- app/components/primer/alpha/action_list.rb:228 # Consider making `single_select?` private. Only ViewComponent interface methods should be public.
|
|
8
|
+
- app/components/primer/alpha/action_list.rb:236 # Consider making `allows_selection?` private. Only ViewComponent interface methods should be public.
|
|
9
|
+
- app/components/primer/alpha/action_list.rb:240 # Consider making `acts_as_listbox?` private. Only ViewComponent interface methods should be public.
|
|
10
|
+
- app/components/primer/alpha/action_list.rb:244 # Consider making `acts_as_menu?` private. Only ViewComponent interface methods should be public.
|
|
11
|
+
- app/components/primer/alpha/action_list.rb:248 # Consider making `required_form_arguments_given?` private. Only ViewComponent interface methods should be public.
|
|
12
|
+
- app/components/primer/alpha/action_list.rb:257 # Consider making `will_add_item` private. Only ViewComponent interface methods should be public.
|
|
13
|
+
- app/components/primer/alpha/action_list.rb:53 # Consider making `custom_element_name` private. Only ViewComponent interface methods should be public.
|
|
14
|
+
- app/components/primer/alpha/action_list/divider.rb:33 # Consider making `active?` private. Only ViewComponent interface methods should be public.
|
|
15
|
+
- app/components/primer/alpha/action_list/form_wrapper.rb:53 # Consider making `get?` private. Only ViewComponent interface methods should be public.
|
|
16
|
+
- app/components/primer/alpha/dropdown/menu.rb:96 # Consider making `divider?` private. Only ViewComponent interface methods should be public.
|
|
17
|
+
- app/components/primer/alpha/form_control.rb:101 # Consider making `visually_hide_label?` private. Only ViewComponent interface methods should be public.
|
|
18
|
+
- app/components/primer/alpha/form_control.rb:107 # Consider making `full_width?` private. Only ViewComponent interface methods should be public.
|
|
19
|
+
- app/components/primer/alpha/toggle_switch.rb:94 # Consider making `on?` private. Only ViewComponent interface methods should be public.
|
|
20
|
+
- app/components/primer/alpha/toggle_switch.rb:98 # Consider making `enabled?` private. Only ViewComponent interface methods should be public.
|
|
21
|
+
- app/components/primer/alpha/tree_view/node.rb:155 # Consider making `merge_system_arguments!` private. Only ViewComponent interface methods should be public.
|
|
22
|
+
- app/components/primer/beta/avatar.rb:22 # Consider making `link?` private. Only ViewComponent interface methods should be public.
|
|
23
|
+
- app/components/primer/beta/nav_list.rb:116 # Consider making `build_item` private. Only ViewComponent interface methods should be public.
|
|
24
|
+
- app/components/primer/beta/nav_list.rb:139 # Consider making `build_avatar_item` private. Only ViewComponent interface methods should be public.
|
|
25
|
+
ViewComponent/TestRenderedOutput:
|
|
26
|
+
- test/components/alpha/action_list_test.rb:253 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly.
|
|
27
|
+
- test/components/alpha/action_list_test.rb:268 # Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly.
|
|
@@ -96,6 +96,40 @@ RSpec.describe RuboCop::Cop::ViewComponent::TestRenderedOutput, :config do
|
|
|
96
96
|
end
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
+
context "with TestPaths configured" do
|
|
100
|
+
let(:config) do
|
|
101
|
+
RuboCop::Config.new(
|
|
102
|
+
"AllCops" => {"DisplayCopNames" => true},
|
|
103
|
+
"ViewComponent/TestRenderedOutput" => {
|
|
104
|
+
"TestPaths" => ["spec/components/v2/"]
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context "when file is within a configured TestPath" do
|
|
110
|
+
it "registers an offense" do
|
|
111
|
+
expect_offense(<<~RUBY, "spec/components/v2/button_component_spec.rb")
|
|
112
|
+
def test_formatted_title
|
|
113
|
+
^^^^^^^^^^^^^^^^^^^^^^^^ ViewComponent/TestRenderedOutput: Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly.
|
|
114
|
+
component = UserComponent.new("hello")
|
|
115
|
+
assert_equal "HELLO", component.formatted_title
|
|
116
|
+
end
|
|
117
|
+
RUBY
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
context "when file is outside all configured TestPaths" do
|
|
122
|
+
it "does not register an offense" do
|
|
123
|
+
expect_no_offenses(<<~RUBY, "spec/components/v1/button_component_spec.rb")
|
|
124
|
+
def test_formatted_title
|
|
125
|
+
component = UserComponent.new("hello")
|
|
126
|
+
assert_equal "HELLO", component.formatted_title
|
|
127
|
+
end
|
|
128
|
+
RUBY
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
99
133
|
context "with RSpec-style tests" do
|
|
100
134
|
context "when it block instantiates a component but doesn't render" do
|
|
101
135
|
it "registers an offense" do
|
|
@@ -3,6 +3,11 @@ AllCops:
|
|
|
3
3
|
- Primer::Component
|
|
4
4
|
- Primer::BaseComponent
|
|
5
5
|
|
|
6
|
+
# Primer seems to intentionally omit the Component suffix from most class names
|
|
7
|
+
# (116 out of 131 components), so this cop is not useful here.
|
|
8
|
+
ViewComponent/ComponentSuffix:
|
|
9
|
+
Enabled: false
|
|
10
|
+
|
|
6
11
|
# Primer::Forms::BaseComponent is not a ViewComponent - it's a custom base class
|
|
7
12
|
# for a forms framework that mimics the component interface but doesn't inherit
|
|
8
13
|
# from ViewComponent::Base
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-view_component
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andy Waite
|
|
@@ -93,9 +93,9 @@ files:
|
|
|
93
93
|
- lib/rubocop/view_component/plugin.rb
|
|
94
94
|
- lib/rubocop/view_component/version.rb
|
|
95
95
|
- script/verify
|
|
96
|
-
- spec/expected_govuk_failures.
|
|
97
|
-
- spec/expected_polaris_failures.
|
|
98
|
-
- spec/expected_primer_failures.
|
|
96
|
+
- spec/expected_govuk_failures.yml
|
|
97
|
+
- spec/expected_polaris_failures.yml
|
|
98
|
+
- spec/expected_primer_failures.yml
|
|
99
99
|
- spec/fixtures/components/template_method_component.html.erb
|
|
100
100
|
- spec/fixtures/components/template_method_component.rb
|
|
101
101
|
- spec/rubocop/cop/view_component/component_suffix_spec.rb
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"path": "app/components/govuk_component/base.rb",
|
|
4
|
-
"line": 1,
|
|
5
|
-
"cop": "ViewComponent/ComponentSuffix",
|
|
6
|
-
"message": "ViewComponent class names should end with `Component`. (https://viewcomponent.org/best_practices.html)"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"path": "app/components/govuk_component/base.rb",
|
|
10
|
-
"line": 29,
|
|
11
|
-
"cop": "ViewComponent/PreferPrivateMethods",
|
|
12
|
-
"message": "Consider making `brand` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)"
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"path": "app/components/govuk_component/base.rb",
|
|
16
|
-
"line": 35,
|
|
17
|
-
"cop": "ViewComponent/PreferPrivateMethods",
|
|
18
|
-
"message": "Consider making `class_prefix` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"path": "app/components/govuk_component/header_component.rb",
|
|
22
|
-
"line": 46,
|
|
23
|
-
"cop": "ViewComponent/ComponentSuffix",
|
|
24
|
-
"message": "ViewComponent class names should end with `Component`. (https://viewcomponent.org/best_practices.html)"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"path": "app/components/govuk_component/notification_banner_component.rb",
|
|
28
|
-
"line": 33,
|
|
29
|
-
"cop": "ViewComponent/ComponentSuffix",
|
|
30
|
-
"message": "ViewComponent class names should end with `Component`. (https://viewcomponent.org/best_practices.html)"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"path": "app/components/govuk_component/notification_banner_component.rb",
|
|
34
|
-
"line": 55,
|
|
35
|
-
"cop": "ViewComponent/PreferPrivateMethods",
|
|
36
|
-
"message": "Consider making `link` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"path": "app/components/govuk_component/notification_banner_component.rb",
|
|
40
|
-
"line": 59,
|
|
41
|
-
"cop": "ViewComponent/PreferPrivateMethods",
|
|
42
|
-
"message": "Consider making `default_attributes` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"path": "app/components/govuk_component/pagination_component/adjacent_page.rb",
|
|
46
|
-
"line": 1,
|
|
47
|
-
"cop": "ViewComponent/ComponentSuffix",
|
|
48
|
-
"message": "ViewComponent class names should end with `Component`. (https://viewcomponent.org/best_practices.html)"
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"path": "app/components/govuk_component/pagination_component/item.rb",
|
|
52
|
-
"line": 1,
|
|
53
|
-
"cop": "ViewComponent/ComponentSuffix",
|
|
54
|
-
"message": "ViewComponent class names should end with `Component`. (https://viewcomponent.org/best_practices.html)"
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
"path": "app/components/govuk_component/service_navigation_component.rb",
|
|
58
|
-
"line": 54,
|
|
59
|
-
"cop": "ViewComponent/PreferPrivateMethods",
|
|
60
|
-
"message": "Consider making `navigation` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)"
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"path": "app/components/govuk_component/service_navigation_component.rb",
|
|
64
|
-
"line": 62,
|
|
65
|
-
"cop": "ViewComponent/PreferPrivateMethods",
|
|
66
|
-
"message": "Consider making `navigation_list` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)"
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
"path": "app/components/govuk_component/tab_component.rb",
|
|
70
|
-
"line": 21,
|
|
71
|
-
"cop": "ViewComponent/ComponentSuffix",
|
|
72
|
-
"message": "ViewComponent class names should end with `Component`. (https://viewcomponent.org/best_practices.html)"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"path": "app/components/govuk_component/tab_component.rb",
|
|
76
|
-
"line": 32,
|
|
77
|
-
"cop": "ViewComponent/PreferPrivateMethods",
|
|
78
|
-
"message": "Consider making `hidden_class` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)"
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
"path": "app/components/govuk_component/tab_component.rb",
|
|
82
|
-
"line": 38,
|
|
83
|
-
"cop": "ViewComponent/PreferPrivateMethods",
|
|
84
|
-
"message": "Consider making `li_classes` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)"
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"path": "app/components/govuk_component/tab_component.rb",
|
|
88
|
-
"line": 42,
|
|
89
|
-
"cop": "ViewComponent/PreferPrivateMethods",
|
|
90
|
-
"message": "Consider making `li_link` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)"
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
"path": "app/components/govuk_component/tab_component.rb",
|
|
94
|
-
"line": 46,
|
|
95
|
-
"cop": "ViewComponent/PreferPrivateMethods",
|
|
96
|
-
"message": "Consider making `default_attributes` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)"
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"path": "app/components/govuk_component/tab_component.rb",
|
|
100
|
-
"line": 50,
|
|
101
|
-
"cop": "ViewComponent/PreferPrivateMethods",
|
|
102
|
-
"message": "Consider making `combined_attributes` private. Only ViewComponent interface methods should be public. (https://viewcomponent.org/best_practices.html)"
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
"path": "spec/components/govuk_component/accordion_component_spec.rb",
|
|
106
|
-
"line": 84,
|
|
107
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
108
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
"path": "spec/components/govuk_component/breadcrumbs_component_spec.rb",
|
|
112
|
-
"line": 44,
|
|
113
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
114
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
"path": "spec/components/govuk_component/configuration/footer_component_configuration_spec.rb",
|
|
118
|
-
"line": 42,
|
|
119
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
120
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
"path": "spec/components/govuk_component/footer_component_spec.rb",
|
|
124
|
-
"line": 123,
|
|
125
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
126
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
"path": "spec/components/govuk_component/footer_component_spec.rb",
|
|
130
|
-
"line": 182,
|
|
131
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
132
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
"path": "spec/components/govuk_component/footer_component_spec.rb",
|
|
136
|
-
"line": 235,
|
|
137
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
138
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
"path": "spec/components/govuk_component/footer_component_spec.rb",
|
|
142
|
-
"line": 254,
|
|
143
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
144
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
"path": "spec/components/govuk_component/footer_component_spec.rb",
|
|
148
|
-
"line": 274,
|
|
149
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
150
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
"path": "spec/components/govuk_component/footer_component_spec.rb",
|
|
154
|
-
"line": 294,
|
|
155
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
156
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
"path": "spec/components/govuk_component/footer_component_spec.rb",
|
|
160
|
-
"line": 312,
|
|
161
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
162
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
"path": "spec/components/govuk_component/footer_component_spec.rb",
|
|
166
|
-
"line": 336,
|
|
167
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
168
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
"path": "spec/components/govuk_component/notification_banner_component_spec.rb",
|
|
172
|
-
"line": 59,
|
|
173
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
174
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
"path": "spec/components/govuk_component/pagination_component_spec.rb",
|
|
178
|
-
"line": 317,
|
|
179
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
180
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
"path": "spec/components/govuk_component/task_list_component_spec.rb",
|
|
184
|
-
"line": 139,
|
|
185
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
186
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
"path": "spec/components/govuk_component/warning_text_component_spec.rb",
|
|
190
|
-
"line": 11,
|
|
191
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
192
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
"path": "spec/components/govuk_component/warning_text_component_spec.rb",
|
|
196
|
-
"line": 41,
|
|
197
|
-
"cop": "ViewComponent/TestRenderedOutput",
|
|
198
|
-
"message": "Test instantiates a component but doesn't use `render_inline` or `render_preview`. Test the rendered output instead of component methods directly. (https://viewcomponent.org/guide/testing.html)"
|
|
199
|
-
}
|
|
200
|
-
]
|