rubocop-elegant 0.0.9 → 0.0.11
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/README.md +10 -3
- data/config/default.yml +25 -7
- data/lib/rubocop/cop/elegant/no_comments.rb +37 -1
- data/rubocop-elegant.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 553704ade44156d5f125292999bde77fdf3a4fec42e2b6f418dfb345c02db576
|
|
4
|
+
data.tar.gz: 559c7644091c2b1d118d40e2a3da04c82144dd4ffebdcd661c21eb112c5aa4df
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6e5afbc202a78a2d443cde89542deb99bfff11d97d6226f9aa305fcabfbdb87c20b771a9addf0854a56552c4652851cceaef3a75a716d1bec0144f4ac03f5515
|
|
7
|
+
data.tar.gz: 5b4f2752fe049e3e4b7c1bf2f8685dbb53b9362e9b0170e87a6cb33600e3a36228c7a6d915f32426782df00a80dac13228f39fb38ff23a396e35fb76add19252
|
data/README.md
CHANGED
|
@@ -25,14 +25,21 @@ First, install it:
|
|
|
25
25
|
gem install rubocop-elegant
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
Then,
|
|
28
|
+
Then, format your `.rubocop.yml` like this:
|
|
29
29
|
|
|
30
30
|
```yaml
|
|
31
|
+
AllCops:
|
|
32
|
+
EnabledByDefault: true
|
|
33
|
+
NewCops: enable
|
|
31
34
|
plugins:
|
|
32
|
-
- rubocop-
|
|
35
|
+
- rubocop-minitest
|
|
36
|
+
- rubocop-performance
|
|
37
|
+
- rubocop-rake
|
|
38
|
+
- rubocop-elegant # must be the last one
|
|
33
39
|
```
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
The `rubocop-elegant` not only provides its own cops, but also configures
|
|
42
|
+
default ones the "right" way.
|
|
36
43
|
|
|
37
44
|
## How to contribute
|
|
38
45
|
|
data/config/default.yml
CHANGED
|
@@ -41,8 +41,6 @@ Naming/FileName:
|
|
|
41
41
|
Regex: '^[a-z0-9\-._]*$'
|
|
42
42
|
Minitest/EmptyLineBeforeAssertionMethods:
|
|
43
43
|
Enabled: false
|
|
44
|
-
Layout/EmptyLineAfterGuardClause:
|
|
45
|
-
Enabled: false
|
|
46
44
|
Layout/RescueEnsureAlignment:
|
|
47
45
|
Enabled: false
|
|
48
46
|
Layout/MultilineMethodCallIndentation:
|
|
@@ -93,17 +91,37 @@ Metrics/CyclomaticComplexity:
|
|
|
93
91
|
Max: 15
|
|
94
92
|
Metrics/PerceivedComplexity:
|
|
95
93
|
Max: 15
|
|
96
|
-
Style/Copyright:
|
|
97
|
-
Enabled: false
|
|
98
94
|
Lint/ConstantResolution:
|
|
99
95
|
Enabled: false
|
|
100
|
-
Style/
|
|
96
|
+
Style/IpAddresses:
|
|
97
|
+
Enabled: false
|
|
98
|
+
Minitest/NoAssertions:
|
|
99
|
+
Enabled: false
|
|
100
|
+
Layout/EmptyLineAfterGuardClause:
|
|
101
101
|
Enabled: false
|
|
102
102
|
Bundler/GemComment:
|
|
103
103
|
Enabled: false
|
|
104
|
-
|
|
104
|
+
Style/DocumentationMethod:
|
|
105
105
|
Enabled: false
|
|
106
|
-
Style/
|
|
106
|
+
Style/MissingElse:
|
|
107
|
+
Enabled: false
|
|
108
|
+
Style/MethodCalledOnDoEndBlock:
|
|
107
109
|
Enabled: false
|
|
108
110
|
Style/StringHashKeys:
|
|
109
111
|
Enabled: false
|
|
112
|
+
Style/HashLookupMethod:
|
|
113
|
+
Enabled: false
|
|
114
|
+
Style/MethodCallWithArgsParentheses:
|
|
115
|
+
Enabled: true
|
|
116
|
+
Layout/MultilineMethodArgumentLineBreaks:
|
|
117
|
+
Enabled: false
|
|
118
|
+
Layout/RedundantLineBreak:
|
|
119
|
+
Enabled: true
|
|
120
|
+
Performance/Casecmp:
|
|
121
|
+
Enabled: false
|
|
122
|
+
Layout/FirstMethodArgumentLineBreak:
|
|
123
|
+
Enabled: false
|
|
124
|
+
Style/ArrayFirstLast:
|
|
125
|
+
Enabled: false
|
|
126
|
+
Minitest/AssertEmptyLiteral:
|
|
127
|
+
Enabled: false
|
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
|
21
21
|
private
|
|
22
22
|
|
|
23
23
|
def allowed?(comment)
|
|
24
|
-
spdx?(comment) || magic?(comment) || rubocop?(comment)
|
|
24
|
+
spdx?(comment) || magic?(comment) || rubocop?(comment) || (gemspec? && docblock?(comment))
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def spdx?(comment)
|
|
@@ -36,6 +36,42 @@ module RuboCop
|
|
|
36
36
|
comment.text.match?(/^#\s*rubocop:(disable|enable|todo)\s/)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
def gemspec?
|
|
40
|
+
return @gemspec if defined?(@gemspec)
|
|
41
|
+
path = processed_source.path
|
|
42
|
+
return @gemspec = false if path.nil?
|
|
43
|
+
dir = File.dirname(path)
|
|
44
|
+
@gemspec = Dir.glob(File.join(dir, '*.gemspec')).any?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def docblock?(comment)
|
|
48
|
+
line = comment.location.line
|
|
49
|
+
successor = codeline(line)
|
|
50
|
+
return false if successor.nil?
|
|
51
|
+
definition?(successor)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def codeline(start)
|
|
55
|
+
lines = processed_source.lines
|
|
56
|
+
(start...lines.size).each do |idx|
|
|
57
|
+
content = lines[idx]
|
|
58
|
+
next if content.nil?
|
|
59
|
+
stripped = content.strip
|
|
60
|
+
next if stripped.empty? || stripped.start_with?('#')
|
|
61
|
+
return idx + 1
|
|
62
|
+
end
|
|
63
|
+
nil
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def definition?(line)
|
|
67
|
+
ast = processed_source.ast
|
|
68
|
+
return false if ast.nil?
|
|
69
|
+
ast.each_node(:class, :module, :def, :defs) do |node|
|
|
70
|
+
return true if node.location.line == line
|
|
71
|
+
end
|
|
72
|
+
false
|
|
73
|
+
end
|
|
74
|
+
|
|
39
75
|
def register(comment)
|
|
40
76
|
add_offense(comment) do |corrector|
|
|
41
77
|
corrector.remove(removal(comment))
|
data/rubocop-elegant.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
|
9
9
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to?(:required_rubygems_version=)
|
|
10
10
|
s.required_ruby_version = '>=2.2'
|
|
11
11
|
s.name = 'rubocop-elegant'
|
|
12
|
-
s.version = '0.0.
|
|
12
|
+
s.version = '0.0.11'
|
|
13
13
|
s.license = 'MIT'
|
|
14
14
|
s.summary = 'Set of custom RuboCop cops for elegant Ruby coding'
|
|
15
15
|
s.description =
|