sevencop 0.29.1 → 0.31.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df805d1a45b205a9edf69411d7900ee8896d7d36da95bb608e0f1d45750d2441
4
- data.tar.gz: f8318114a6fc158134f381e39a4b095957343ea35db94f86639b702a35ead7c1
3
+ metadata.gz: ee749fe11f72d661269fa08344e0b5f578a21517375a75d58f5c2bab1877fdcd
4
+ data.tar.gz: 15a392c82cc473f1a5c327e2b1a6f0e1620d3b8e405aa6e548b020559bd24afd
5
5
  SHA512:
6
- metadata.gz: 2aa56f5b6fc473ce25c3758e754dd98bd5ca635c3984fd8b6af1347821bdd7fc5b3bfd213a57db0866b96b4a5a3464cd5097b253782dc30c05471ca09afed09c
7
- data.tar.gz: d16d7cf8fe6cff81a82277a140ef6738a9089072afea4163d96d839bf3ec6f62848a5c061b7226b927cfd5da1d01c9318d216fc262271c1371886c657190c2fb
6
+ metadata.gz: 9c2ea95803821697a72157ab0608459b44467cb2ec868ba66dc21f2613f7ac4eb52745d69d19d5ea43dff6fb40e70ebc2b59110a7bd58ff9ece189b401532c74
7
+ data.tar.gz: f3e26944c43c61b5ccf1f0875117ce77aba7b1ca8f223e5b174ea7a2d4737407b949bc1e362aa1363ee350106b60dc1852ee89af55b5953393b5d7dec432c8d2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.29.1)
4
+ sevencop (0.31.0)
5
5
  activesupport
6
6
  rubocop
7
7
 
data/README.md CHANGED
@@ -29,6 +29,7 @@ Note that all cops are `Enabled: false` by default.
29
29
  ## Cops
30
30
 
31
31
  - [Sevencop/AutoloadOrdered](lib/rubocop/cop/sevencop/autoload_ordered.rb)
32
+ - [Sevencop/ConstantBase](lib/rubocop/cop/sevencop/constant_base.rb)
32
33
  - [Sevencop/FactoryBotAssociationOption](lib/rubocop/cop/sevencop/factory_bot_association_option.rb)
33
34
  - [Sevencop/FactoryBotAssociationStyle](lib/rubocop/cop/sevencop/factory_bot_association_style.rb)
34
35
  - [Sevencop/HashElementOrdered](lib/rubocop/cop/sevencop/hash_element_ordered.rb)
@@ -38,7 +39,6 @@ Note that all cops are `Enabled: false` by default.
38
39
  - [Sevencop/MethodDefinitionOrdered](lib/rubocop/cop/sevencop/method_definition_ordered.rb)
39
40
  - [Sevencop/RailsBelongsToOptional](lib/rubocop/cop/sevencop/rails_belongs_to_optional.rb)
40
41
  - [Sevencop/RailsDateAndTimeCalculation](lib/rubocop/cop/sevencop/rails_date_and_time_calculation.rb)
41
- - [Sevencop/RailsInferredSpecType](lib/rubocop/cop/sevencop/rails_inferred_spec_type.rb)
42
42
  - [Sevencop/RailsOrderField](lib/rubocop/cop/sevencop/rails_order_field.rb)
43
43
  - [Sevencop/RailsSpecificActionName](lib/rubocop/cop/sevencop/rails_specific_action_name.rb)
44
44
  - [Sevencop/RailsUniquenessValidatorExplicitCaseSensitivity](lib/rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_sensitivity.rb)
data/config/default.yml CHANGED
@@ -5,6 +5,12 @@ Sevencop/AutoloadOrdered:
5
5
  Safe: false
6
6
  VersionAdded: '0.12'
7
7
 
8
+ Sevencop/ConstantBase:
9
+ Description: |
10
+ Remove unnecessary `::` prefix from constant.
11
+ Enabled: false
12
+ VersionAdded: '0.31'
13
+
8
14
  Sevencop/FactoryBotAssociationOption:
9
15
  Description: |
10
16
  Remove redundant options from FactoryBot associations.
@@ -82,13 +88,6 @@ Sevencop/RailsDateAndTimeCalculation:
82
88
  Safe: false
83
89
  VersionAdded: '0.26'
84
90
 
85
- Sevencop/RailsInferredSpecType:
86
- Description: |
87
- Identifies redundant spec type.
88
- Enabled: false
89
- Safe: false
90
- VersionAdded: '0.9'
91
-
92
91
  Sevencop/RailsOrderField:
93
92
  Description: |
94
93
  Wrap safe SQL String by `Arel.sql`.
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Sevencop
6
+ # Remove unnecessary `::` prefix from constant.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # ::Const
11
+ #
12
+ # # good
13
+ # Const
14
+ #
15
+ # # bad
16
+ # class << self
17
+ # ::Const
18
+ # end
19
+ #
20
+ # # good
21
+ # class << self
22
+ # Const
23
+ # end
24
+ #
25
+ # # good
26
+ # class Klass
27
+ # ::Const
28
+ # end
29
+ #
30
+ # # good
31
+ # class module
32
+ # ::Const
33
+ # end
34
+ class ConstantBase < Base
35
+ extend AutoCorrector
36
+
37
+ MSG = 'Remove unnecessary `::` prefix from constant.'
38
+
39
+ # @param node [RuboCop::AST::CbaseNode]
40
+ # @return [void]
41
+ def on_cbase(node)
42
+ return unless bad?(node)
43
+
44
+ add_offense(node) do |corrector|
45
+ corrector.remove(node)
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ # @!method named_class_or_module?(node)
52
+ # @param node [RuboCop::AST::Node]
53
+ # @return [Boolean]
54
+ def_node_matcher :named_class_or_module?, <<~PATTERN
55
+ ({class module} const ...)
56
+ PATTERN
57
+
58
+ # @param node [RuboCop::AST::CbaseNode]
59
+ # @return [Boolean]
60
+ def bad?(node)
61
+ node.each_ancestor(:class, :module).none?
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.29.1'
4
+ VERSION = '0.31.0'
5
5
  end
data/lib/sevencop.rb CHANGED
@@ -5,6 +5,7 @@ require_relative 'sevencop/rubocop_extension'
5
5
  require_relative 'sevencop/version'
6
6
 
7
7
  require_relative 'rubocop/cop/sevencop/autoload_ordered'
8
+ require_relative 'rubocop/cop/sevencop/constant_base'
8
9
  require_relative 'rubocop/cop/sevencop/factory_bot_association_option'
9
10
  require_relative 'rubocop/cop/sevencop/factory_bot_association_style'
10
11
  require_relative 'rubocop/cop/sevencop/hash_element_ordered'
@@ -14,7 +15,6 @@ require_relative 'rubocop/cop/sevencop/method_definition_keyword_argument_ordere
14
15
  require_relative 'rubocop/cop/sevencop/method_definition_ordered'
15
16
  require_relative 'rubocop/cop/sevencop/rails_belongs_to_optional'
16
17
  require_relative 'rubocop/cop/sevencop/rails_date_and_time_calculation'
17
- require_relative 'rubocop/cop/sevencop/rails_inferred_spec_type'
18
18
  require_relative 'rubocop/cop/sevencop/rails_order_field'
19
19
  require_relative 'rubocop/cop/sevencop/rails_specific_action_name'
20
20
  require_relative 'rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_sensitivity'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sevencop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.1
4
+ version: 0.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-11 00:00:00.000000000 Z
11
+ date: 2022-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -57,6 +57,7 @@ files:
57
57
  - config/default.yml
58
58
  - data/reserved_words_mysql.txt
59
59
  - lib/rubocop/cop/sevencop/autoload_ordered.rb
60
+ - lib/rubocop/cop/sevencop/constant_base.rb
60
61
  - lib/rubocop/cop/sevencop/factory_bot_association_option.rb
61
62
  - lib/rubocop/cop/sevencop/factory_bot_association_style.rb
62
63
  - lib/rubocop/cop/sevencop/hash_element_ordered.rb
@@ -66,7 +67,6 @@ files:
66
67
  - lib/rubocop/cop/sevencop/method_definition_ordered.rb
67
68
  - lib/rubocop/cop/sevencop/rails_belongs_to_optional.rb
68
69
  - lib/rubocop/cop/sevencop/rails_date_and_time_calculation.rb
69
- - lib/rubocop/cop/sevencop/rails_inferred_spec_type.rb
70
70
  - lib/rubocop/cop/sevencop/rails_order_field.rb
71
71
  - lib/rubocop/cop/sevencop/rails_specific_action_name.rb
72
72
  - lib/rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_sensitivity.rb
@@ -1,125 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module Sevencop
6
- # Identifies redundant spec type.
7
- # This is automatically set by `config.infer_spec_type_from_file_location!`.
8
- #
9
- # @example
10
- #
11
- # # bad
12
- # # spec/models/user_spec.rb
13
- # RSpec.describe User, type: :model
14
- #
15
- # # good
16
- # # spec/models/user_spec.rb
17
- # RSpec.describe User
18
- #
19
- # # good
20
- # # spec/models/user_spec.rb
21
- # RSpec.describe User, type: :request
22
- #
23
- class RailsInferredSpecType < Base
24
- extend AutoCorrector
25
-
26
- # @return [Array<Hash>]
27
- INFERENCES = [
28
- { prefix: 'spec/channels/', type: :channel },
29
- { prefix: 'spec/controllers/', type: :controller },
30
- { prefix: 'spec/features/', type: :feature },
31
- { prefix: 'spec/generator/', type: :generator },
32
- { prefix: 'spec/helpers/', type: :helper },
33
- { prefix: 'spec/jobs/', type: :job },
34
- { prefix: 'spec/mailboxes/', type: :mailbox },
35
- { prefix: 'spec/mailers/', type: :mailer },
36
- { prefix: 'spec/models/', type: :model },
37
- { prefix: 'spec/requests/', type: :request },
38
- { prefix: 'spec/integration/', type: :request },
39
- { prefix: 'spec/api/', type: :request },
40
- { prefix: 'spec/routing/', type: :routing },
41
- { prefix: 'spec/system/', type: :system },
42
- { prefix: 'spec/views/', type: :view }
43
- ].freeze
44
-
45
- MSG = 'Remove redundant spec type.'
46
-
47
- RESTRICT_ON_SEND = %i[
48
- describe
49
- ].freeze
50
-
51
- # @param [RuboCop::AST::SendNode] node
52
- def on_send(node)
53
- pair_node = describe_with_type(node)
54
- return unless pair_node
55
- return unless inferred_type?(pair_node)
56
-
57
- removable_node = detect_removable_node(pair_node)
58
- add_offense(removable_node) do |corrector|
59
- autocorrect(corrector, removable_node)
60
- end
61
- end
62
-
63
- private
64
-
65
- # @!method describe_with_type(node)
66
- # @param [RuboCop::AST::SendNode] node
67
- # @return [RuboCop::AST::PairNode, nil]
68
- def_node_matcher :describe_with_type, <<~PATTERN
69
- (send
70
- { (const nil? :RSpec) | nil? }
71
- _
72
- _
73
- _*
74
- (hash
75
- (pair ...)*
76
- $(pair (sym :type) sym)
77
- (pair ...)*
78
- )
79
- )
80
- PATTERN
81
-
82
- # @param [RuboCop::AST::Corrector] corrector
83
- # @param [RuboCop::AST::Node] node
84
- def autocorrect(
85
- corrector,
86
- node
87
- )
88
- corrector.remove(
89
- node.location.expression.with(
90
- begin_pos: node.left_sibling.location.expression.end_pos
91
- )
92
- )
93
- end
94
-
95
- # @param [RuboCop::AST::PairNode] node
96
- # @return [RuboCop::AST::Node]
97
- def detect_removable_node(node)
98
- if node.parent.pairs.size == 1
99
- node.parent
100
- else
101
- node
102
- end
103
- end
104
-
105
- # @return [String]
106
- def file_path
107
- processed_source.file_path
108
- end
109
-
110
- # @param [RuboCop::AST::PairNode] node
111
- # @return [Boolean]
112
- def inferred_type?(node)
113
- inferred_type_from_file_path.inspect == node.value.source
114
- end
115
-
116
- # @return [Symbol, nil]
117
- def inferred_type_from_file_path
118
- INFERENCES.find do |inference|
119
- break inference[:type] if file_path.include?(inference[:prefix])
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end