sevencop 0.30.0 → 0.31.1
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/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/config/default.yml +6 -0
- data/lib/rubocop/cop/sevencop/constant_base.rb +79 -0
- data/lib/sevencop/version.rb +1 -1
- data/lib/sevencop.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc9eabfebd03bc54220aefb905dcc084374a282323a47907cbd05b7bd03df7ae
|
|
4
|
+
data.tar.gz: b27b429ddbdfa4324f2bb929fbd84622265133a78a5045cab24ac20171c62ae3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e9667ad3506390f48001dc07e16faa48c07eab28afb91f06d5406043481a0c7637fb789e2718b0f7c3414a6666b8f7cda70c950eb4b40c11217629748fc85880
|
|
7
|
+
data.tar.gz: 799f7f8cd175b53edf5804b507e954834e030c5973887b8b148ea803b0ace967e60c181bbf4f212386607eff838371cfccb8d1d255b5e2414b0a6fc9cfccf746
|
data/Gemfile.lock
CHANGED
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)
|
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.
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
# @param node [RuboCop::AST::CbaseNode]
|
|
52
|
+
# @return [Boolean]
|
|
53
|
+
def bad?(node)
|
|
54
|
+
module_nesting_ancestors_of(node).none?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @param node [RuboCop::AST::Node]
|
|
58
|
+
# @return [Enumerable<RuboCop::AST::Node>]
|
|
59
|
+
def module_nesting_ancestors_of(node)
|
|
60
|
+
node.each_ancestor(:class, :module).reject do |ancestor|
|
|
61
|
+
ancestor.class_type? && used_in_super_class_part?(node, class_node: ancestor)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# @param class_node [RuboCop::AST::Node]
|
|
66
|
+
# @param node [RuboCop::AST::CbaseNode]
|
|
67
|
+
# @return [Boolean]
|
|
68
|
+
def used_in_super_class_part?(
|
|
69
|
+
node,
|
|
70
|
+
class_node:
|
|
71
|
+
)
|
|
72
|
+
class_node.parent_class&.each_descendant(:cbase)&.any? do |descendant|
|
|
73
|
+
descendant.eql?(node)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
data/lib/sevencop/version.rb
CHANGED
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'
|
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.
|
|
4
|
+
version: 0.31.1
|
|
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
|
+
date: 2022-11-15 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
|