rubocop-cobra 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/CHANGELOG.md +4 -0
- data/Gemfile.lock +14 -4
- data/config/default.yml +5 -0
- data/lib/rubocop/cobra/version.rb +1 -1
- data/lib/rubocop/cop/cobra/view_component_file_placement.rb +100 -0
- data/lib/rubocop/cop/cobra_cops.rb +1 -0
- data/rubocop-cobra.gemspec +4 -2
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76f52eec926c6471df7602e1b37f8a71b95e3f912e9b9dfa68e7630e51c775aa
|
4
|
+
data.tar.gz: 0ab74366792c29c478052b70ad37c082b14950e708d2112fbd7ab762686d2391
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6df224d48e7b2f42150dcab95017a47fdaf0565becfab8d2582e981f989c793aa373932bbc7fd73966efb0bfd92abf391e0ee8559fdbcde61b7986fd4b29cf96
|
7
|
+
data.tar.gz: 4ff949b8763fb54ded35ff09b3250c46d64a2a69a1b67c79aa346716c0cd6d7410e027c04ee87c5d7705e7fa0febfb3774a94b3c02a3e1c93a0f3e7da9cf8d0f
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../rubocop-powerhome
|
3
3
|
specs:
|
4
|
-
rubocop-powerhome (0.
|
4
|
+
rubocop-powerhome (0.4.0)
|
5
5
|
rubocop
|
6
6
|
rubocop-performance
|
7
7
|
rubocop-rails
|
@@ -11,7 +11,7 @@ PATH
|
|
11
11
|
PATH
|
12
12
|
remote: .
|
13
13
|
specs:
|
14
|
-
rubocop-cobra (0.
|
14
|
+
rubocop-cobra (0.4.0)
|
15
15
|
rubocop
|
16
16
|
rubocop-powerhome
|
17
17
|
|
@@ -24,15 +24,24 @@ GEM
|
|
24
24
|
minitest (>= 5.1)
|
25
25
|
tzinfo (~> 2.0)
|
26
26
|
ast (2.4.2)
|
27
|
+
byebug (11.1.3)
|
28
|
+
coderay (1.1.3)
|
27
29
|
concurrent-ruby (1.1.10)
|
28
30
|
diff-lcs (1.5.0)
|
29
31
|
i18n (1.10.0)
|
30
32
|
concurrent-ruby (~> 1.0)
|
33
|
+
method_source (1.0.0)
|
31
34
|
minitest (5.15.0)
|
32
35
|
parallel (1.22.1)
|
33
36
|
parser (3.1.2.0)
|
34
37
|
ast (~> 2.4.1)
|
35
|
-
|
38
|
+
pry (0.13.1)
|
39
|
+
coderay (~> 1.1)
|
40
|
+
method_source (~> 1.0)
|
41
|
+
pry-byebug (3.9.0)
|
42
|
+
byebug (~> 11.0)
|
43
|
+
pry (~> 0.13.0)
|
44
|
+
rack (2.2.3.1)
|
36
45
|
rainbow (3.1.1)
|
37
46
|
rake (13.0.6)
|
38
47
|
regexp_parser (2.4.0)
|
@@ -61,7 +70,7 @@ GEM
|
|
61
70
|
unicode-display_width (>= 1.4.0, < 3.0)
|
62
71
|
rubocop-ast (1.18.0)
|
63
72
|
parser (>= 3.1.1.0)
|
64
|
-
rubocop-performance (1.
|
73
|
+
rubocop-performance (1.14.0)
|
65
74
|
rubocop (>= 1.7.0, < 2.0)
|
66
75
|
rubocop-ast (>= 0.4.0)
|
67
76
|
rubocop-rails (2.14.2)
|
@@ -82,6 +91,7 @@ PLATFORMS
|
|
82
91
|
x86_64-linux
|
83
92
|
|
84
93
|
DEPENDENCIES
|
94
|
+
pry-byebug (= 3.9.0)
|
85
95
|
rake (~> 13.0)
|
86
96
|
rspec (~> 3.0)
|
87
97
|
rubocop (~> 1.29.1)
|
data/config/default.yml
CHANGED
@@ -55,3 +55,8 @@ Cobra/PresenterFilePlacement:
|
|
55
55
|
Description: 'This cop disallows adding global presenters to the `app/presenters` directory.'
|
56
56
|
Enabled: true
|
57
57
|
VersionAdded: '0.1.0'
|
58
|
+
|
59
|
+
Cobra/ViewComponentFilePlacement:
|
60
|
+
Description: 'This cop disallows adding global view_components to the `app/components` directory.'
|
61
|
+
Enabled: true
|
62
|
+
VersionAdded: '0.4.0'
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Cobra
|
6
|
+
# This cop disallows adding global view_components to the `app/components` directory.
|
7
|
+
#
|
8
|
+
# The goal is to encourage developers to put new view_components inside the correct
|
9
|
+
# namespace, where they can be more modularly isolated and ownership is clear.
|
10
|
+
#
|
11
|
+
# The correct namespace is `app/components/my_component/resource/view_component.rb.
|
12
|
+
# Similar to how `app/views` templates are nested in a directory named after the controller's resource.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# # bad
|
16
|
+
# # path: components/my_component/app/components/foo_component.rb
|
17
|
+
# class FooComponent < ::ViewComponent::Base
|
18
|
+
# # ...
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# # bad
|
22
|
+
# # path: components/my_component/app/components/my_component/foo_component.rb
|
23
|
+
# module MyComponent
|
24
|
+
# class FooComponent < MyComponent::ApplicationComponent
|
25
|
+
# # ...
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# # acceptable
|
30
|
+
# # path: components/my_component/app/components/my_component/application_component.rb
|
31
|
+
# module MyComponent
|
32
|
+
# class ApplicationComponent < ::ViewComponent::Base
|
33
|
+
# # ...
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# # good
|
39
|
+
# # path: components/my_component/app/components/my_component/resource/foo_component.rb
|
40
|
+
# module MyComponent
|
41
|
+
# module Resource
|
42
|
+
# class FooComponent < MyComponent::ApplicationComponent
|
43
|
+
# # ...
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
class ViewComponentFilePlacement < RuboCop::Cop::Cop
|
49
|
+
FILE_PLACEMENT_MSG =
|
50
|
+
"Nest ViewComponent definitions in the parent component and resource namespace. " \
|
51
|
+
"For example: `%<correct_path>s`"
|
52
|
+
|
53
|
+
def investigate(processed_source)
|
54
|
+
return if processed_source.blank?
|
55
|
+
return unless path_contains_matcher?
|
56
|
+
return if namespaced_correctly?
|
57
|
+
|
58
|
+
add_offense(processed_source.ast,
|
59
|
+
message: format(FILE_PLACEMENT_MSG, correct_path: correct_path))
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def view_components_path
|
65
|
+
"app/components/"
|
66
|
+
end
|
67
|
+
|
68
|
+
def path
|
69
|
+
@path ||= processed_source.file_path
|
70
|
+
end
|
71
|
+
|
72
|
+
def namespaced_correctly?
|
73
|
+
potential_component_name = component_name
|
74
|
+
component_path = File.join(
|
75
|
+
potential_component_name,
|
76
|
+
view_components_path,
|
77
|
+
potential_component_name
|
78
|
+
)
|
79
|
+
return false unless path.include?("#{component_path}/")
|
80
|
+
|
81
|
+
sub_path = path.split("#{component_path}/").last
|
82
|
+
sub_path.include?("/") || sub_path == "application_component.rb"
|
83
|
+
end
|
84
|
+
|
85
|
+
def correct_path
|
86
|
+
file = path.split("/").last
|
87
|
+
"#{view_components_path}#{component_name}/<resource>/#{file}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def component_name
|
91
|
+
path.split(view_components_path).first.split("/").last
|
92
|
+
end
|
93
|
+
|
94
|
+
def path_contains_matcher?
|
95
|
+
path.include?(view_components_path)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/rubocop-cobra.gemspec
CHANGED
@@ -5,8 +5,8 @@ require_relative "lib/rubocop/cobra/version"
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "rubocop-cobra"
|
7
7
|
spec.version = RuboCop::Cobra::VERSION
|
8
|
-
spec.authors = ["Carlos Palhares"]
|
9
|
-
spec.email = ["chjunior@gmail.com"]
|
8
|
+
spec.authors = ["Carlos Palhares", "Garett Arrowood"]
|
9
|
+
spec.email = ["chjunior@gmail.com", "garettarrowood@gmail.com"]
|
10
10
|
|
11
11
|
spec.summary = "Cobra rubocop linters"
|
12
12
|
spec.description = "Cobra rubocop linters"
|
@@ -38,4 +38,6 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_runtime_dependency "rubocop"
|
39
39
|
spec.add_runtime_dependency "rubocop-powerhome"
|
40
40
|
spec.metadata["rubygems_mfa_required"] = "true"
|
41
|
+
|
42
|
+
spec.add_development_dependency "pry-byebug", "3.9.0"
|
41
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-cobra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Palhares
|
8
|
+
- Garett Arrowood
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date: 2022-
|
12
|
+
date: 2022-06-01 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rubocop
|
@@ -38,9 +39,24 @@ dependencies:
|
|
38
39
|
- - ">="
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry-byebug
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 3.9.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 3.9.0
|
41
56
|
description: Cobra rubocop linters
|
42
57
|
email:
|
43
58
|
- chjunior@gmail.com
|
59
|
+
- garettarrowood@gmail.com
|
44
60
|
executables: []
|
45
61
|
extensions: []
|
46
62
|
extra_rdoc_files: []
|
@@ -70,6 +86,7 @@ files:
|
|
70
86
|
- lib/rubocop/cop/cobra/mailer_file_placement.rb
|
71
87
|
- lib/rubocop/cop/cobra/model_file_placement.rb
|
72
88
|
- lib/rubocop/cop/cobra/presenter_file_placement.rb
|
89
|
+
- lib/rubocop/cop/cobra/view_component_file_placement.rb
|
73
90
|
- lib/rubocop/cop/cobra_cops.rb
|
74
91
|
- rubocop-cobra.gemspec
|
75
92
|
- sig/rubocop/cobra.rbs
|