rubocop-powerhome 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 188b7b1d68d7953212e66f35202529d4aea4f587f3d72468c02909e2fc5eb45f
4
- data.tar.gz: c87fa112d9c4d86f8f901e6598ac5d7850927b2166598f5f7d50e529219d82de
3
+ metadata.gz: f600a565fdbcc14fe35a92718726d3a6ad595608ac1ef2cf1f1577ee2a86699f
4
+ data.tar.gz: 0d7e2760b6bfa60936e79789bb43aaa28a1adb6ab2857c3b459d042e2dab0ff0
5
5
  SHA512:
6
- metadata.gz: d18733226e47c335fabf4a64e5886a65fa8cf97c8e05fe90b51f0654644d314a4ef50d1d4585d3c56dc156f609f0c42ad1133b65fc1843cb897d50297953b769
7
- data.tar.gz: 1c2530786425086cb940b9495faae2e4d0c6879f7113bcb0a2abb1a5b971d16dc3fd37b108c67cc1d58b16299cbbfcd5e92d50bdf2a7c22171da12d9a7360c78
6
+ metadata.gz: a02803ca4e2ed95884ff9e90e52c6b3c155bd2b7c3759479a6cda536d34f39488ff9b42a415706190e7a74e3d3c1251e261cdc3deb36249919ebb95580a0417f
7
+ data.tar.gz: dc326b826f6deb0b1704e6d720666c174dad28ba893287841cbdc11ba9b41f1cb208adbce6302d0eb9d27c77fdf38515c773c1aeca212a24c66246908a0a29ec
data/.rubocop.yml CHANGED
@@ -5,5 +5,10 @@ Naming/FileName:
5
5
  Exclude:
6
6
  - lib/rubocop-powerhome.rb
7
7
 
8
+ Metrics/BlockLength:
9
+ Exclude:
10
+ - 'spec/**/*'
11
+ - 'rubocop-powerhome.gemspec'
12
+
8
13
  Rails:
9
14
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2022-06-01
4
+
5
+ - Adds Naming/ViewComponent cop
6
+ - Adds Style/NoHelpers cop
7
+
3
8
  ## [0.1.0] - 2022-05-18
4
9
 
5
10
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-powerhome (0.3.0)
4
+ rubocop-powerhome (0.4.0)
5
5
  rubocop
6
6
  rubocop-performance
7
7
  rubocop-rails
@@ -17,15 +17,24 @@ GEM
17
17
  minitest (>= 5.1)
18
18
  tzinfo (~> 2.0)
19
19
  ast (2.4.2)
20
+ byebug (11.1.3)
21
+ coderay (1.1.3)
20
22
  concurrent-ruby (1.1.10)
21
23
  diff-lcs (1.5.0)
22
24
  i18n (1.10.0)
23
25
  concurrent-ruby (~> 1.0)
26
+ method_source (1.0.0)
24
27
  minitest (5.15.0)
25
28
  parallel (1.22.1)
26
29
  parser (3.1.2.0)
27
30
  ast (~> 2.4.1)
28
- rack (2.2.3)
31
+ pry (0.13.1)
32
+ coderay (~> 1.1)
33
+ method_source (~> 1.0)
34
+ pry-byebug (3.9.0)
35
+ byebug (~> 11.0)
36
+ pry (~> 0.13.0)
37
+ rack (2.2.3.1)
29
38
  rainbow (3.1.1)
30
39
  rake (13.0.6)
31
40
  regexp_parser (2.4.0)
@@ -76,6 +85,7 @@ PLATFORMS
76
85
  x86_64-linux
77
86
 
78
87
  DEPENDENCIES
88
+ pry-byebug (= 3.9.0)
79
89
  rake (~> 13.0)
80
90
  rspec (~> 3.0)
81
91
  rubocop (~> 1.29.1)
data/config/default.yml CHANGED
@@ -24,6 +24,11 @@ Naming/MethodParameterName:
24
24
  - in
25
25
  - at
26
26
 
27
+ Naming/ViewComponent:
28
+ Description: 'This cop requires ViewComponent classes to end with Component in their classname.'
29
+ Enabled: true
30
+ VersionAdded: '0.4.0'
31
+
27
32
  Rails:
28
33
  Enabled: true
29
34
 
@@ -59,6 +64,11 @@ Style/HashTransformValues:
59
64
  Style/Lambda:
60
65
  EnforcedStyle: literal
61
66
 
67
+ Style/NoHelpers:
68
+ Description: 'This cop blocks global helper modules from existing in an application.'
69
+ Enabled: true
70
+ VersionAdded: '0.4.0'
71
+
62
72
  Style/NumericPredicate:
63
73
  Enabled: false
64
74
 
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Naming
6
+ # This cop requires ViewComponent classes to end with Component in their classname.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # class Foo < ::ViewComponent::Base
11
+ # # ...
12
+ # end
13
+ #
14
+ # # good
15
+ # class FooComponent < ::ViewComponent::Base
16
+ # # ...
17
+ # end
18
+ #
19
+ class ViewComponent < RuboCop::Cop::Cop
20
+ def on_class(node)
21
+ inheritance_klass = node.node_parts[1]&.source
22
+ return unless view_component_class?(inheritance_klass)
23
+
24
+ klass = node.node_parts[0]&.source
25
+ return if klass.end_with?("Component")
26
+
27
+ add_offense(node.node_parts[0], message: "End ViewComponent classnames with 'Component'")
28
+ end
29
+
30
+ private
31
+
32
+ def view_component_class?(inheritance_klass)
33
+ inheritance_klass.end_with?("::ApplicationComponent", "ViewComponent::Base")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Naming
6
+ require_relative "naming/view_component"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ # This cop does not allow helpers to be placed in an application. View objects,
7
+ # specifically ViewComponent, create better Object Oriented design.
8
+ # Global helper methods tightly couple templates.
9
+ #
10
+ class NoHelpers < RuboCop::Cop::Cop
11
+ MSG = "Helpers create global view methods. Instead, use view objects to " \
12
+ "encapsulate your display logic."
13
+
14
+ def investigate(processed_source)
15
+ return if processed_source.blank?
16
+ return unless helper_path?
17
+
18
+ add_offense(processed_source.ast, message: format(MSG))
19
+ end
20
+
21
+ private
22
+
23
+ def helper_path?
24
+ processed_source.file_path.include?("app/helpers/")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ require_relative "style/no_helpers"
7
+ end
8
+ end
9
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Powerhome
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
@@ -9,3 +9,6 @@ require "rubocop-rspec"
9
9
  require_relative "rubocop/powerhome"
10
10
 
11
11
  RuboCop::Powerhome::Inject.defaults!
12
+
13
+ require_relative "rubocop/cop/naming_cops"
14
+ require_relative "rubocop/cop/style_cops"
@@ -5,8 +5,8 @@ require_relative "lib/rubocop/powerhome/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "rubocop-powerhome"
7
7
  spec.version = RuboCop::Powerhome::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 = "Powerhome Rubocop standard rules"
12
12
  spec.description = "Powerhome Rubocop standard rules"
@@ -41,4 +41,6 @@ Gem::Specification.new do |spec|
41
41
  spec.add_runtime_dependency "rubocop-rake"
42
42
  spec.add_runtime_dependency "rubocop-rspec"
43
43
  spec.metadata["rubygems_mfa_required"] = "true"
44
+
45
+ spec.add_development_dependency "pry-byebug", "3.9.0"
44
46
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-powerhome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.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-05-20 00:00:00.000000000 Z
12
+ date: 2022-06-01 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rubocop
@@ -80,9 +81,24 @@ dependencies:
80
81
  - - ">="
81
82
  - !ruby/object:Gem::Version
82
83
  version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: pry-byebug
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '='
89
+ - !ruby/object:Gem::Version
90
+ version: 3.9.0
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '='
96
+ - !ruby/object:Gem::Version
97
+ version: 3.9.0
83
98
  description: Powerhome Rubocop standard rules
84
99
  email:
85
100
  - chjunior@gmail.com
101
+ - garettarrowood@gmail.com
86
102
  executables: []
87
103
  extensions: []
88
104
  extra_rdoc_files: []
@@ -96,6 +112,10 @@ files:
96
112
  - Rakefile
97
113
  - config/default.yml
98
114
  - lib/rubocop-powerhome.rb
115
+ - lib/rubocop/cop/naming/view_component.rb
116
+ - lib/rubocop/cop/naming_cops.rb
117
+ - lib/rubocop/cop/style/no_helpers.rb
118
+ - lib/rubocop/cop/style_cops.rb
99
119
  - lib/rubocop/powerhome.rb
100
120
  - lib/rubocop/powerhome/inject.rb
101
121
  - lib/rubocop/powerhome/version.rb