rubocop-elegant 0.0.10 → 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/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
|
|
@@ -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 =
|