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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3217f34ead6ad0b67f7a26e1161f02a95348516568d7f6e7854f55868851d61c
4
- data.tar.gz: 85731d9b53196da18194c638ca619470b560ef07618d5ba3c31ebbedfa80c874
3
+ metadata.gz: 553704ade44156d5f125292999bde77fdf3a4fec42e2b6f418dfb345c02db576
4
+ data.tar.gz: 559c7644091c2b1d118d40e2a3da04c82144dd4ffebdcd661c21eb112c5aa4df
5
5
  SHA512:
6
- metadata.gz: a893c8544575191d84d47bf8e44e6f109ca63858b2ec08410a298d81a3ccf9bcde4f2deafe70d03f299895e15a6e45c02bdf7c4daa55be505ca632aa6bcd6940
7
- data.tar.gz: 6eb5a8ac49772f0a1d11d314ce438cbadfb6cb31f567dc453d96d3820d306d1b45376bc9b471d999ead56340796bf12b6cc09d064ae1067404bcfc630057dbf1
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))
@@ -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.10'
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 =
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-elegant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko