rubocop-elegant 0.0.18 → 0.0.19
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a46226de426fa7b76116750fea759a20d48125a0d44a546accb374f5ba91da57
|
|
4
|
+
data.tar.gz: 85e3592cd2395049c4ce3f228d4a60b43dcdcb3a8a7d7eb909cead9abcd87a5c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 72f1dc5fccc9a27c3c8cbd7a39aabf4d71e8577bb6149879a2213546e0c6010a0bed1ae8035f0fdb55bc0609db38582db4737043d3db2b75783dab83e2fb8d13
|
|
7
|
+
data.tar.gz: 7e430e58ecec3d31bdfdd03895117d1e4cb18e02028e0a9156680f68d9c9caaf16653eab3a07b25eac44531956b02648f54b8d830ef761c804cc65dd8b3a2f2e
|
data/config/default.yml
CHANGED
|
@@ -12,6 +12,10 @@ Elegant/NoEmptyLinesInMethods:
|
|
|
12
12
|
Description: 'Disallows empty lines inside method bodies'
|
|
13
13
|
Enabled: true
|
|
14
14
|
VersionAdded: '0.0.2'
|
|
15
|
+
Elegant/NoEmptyLinesInBlocks:
|
|
16
|
+
Description: 'Disallows empty lines inside blocks (do/end, if/end, while, case, begin, etc.)'
|
|
17
|
+
Enabled: true
|
|
18
|
+
VersionAdded: '0.0.19'
|
|
15
19
|
Elegant/GoodVariableName:
|
|
16
20
|
Description: 'Checks that variable names match the configured pattern'
|
|
17
21
|
Enabled: true
|
|
@@ -22,7 +26,7 @@ Elegant/GoodMethodName:
|
|
|
22
26
|
Description: 'Checks that method names match the configured pattern'
|
|
23
27
|
Enabled: true
|
|
24
28
|
VersionAdded: '0.0.3'
|
|
25
|
-
Pattern: '^(((to|fake|the|with|without
|
|
29
|
+
Pattern: '^(((to|fake|the|with|without)_)?[a-z]{1,16}[!?]?|(on|test)_[a-z_]+)$'
|
|
26
30
|
AllowedNames: []
|
|
27
31
|
|
|
28
32
|
Style/RedundantException:
|
|
@@ -12,13 +12,11 @@ module RuboCop
|
|
|
12
12
|
MSG = 'Comment is not allowed, unless it is SPDX, magic, rubocop directive, or docblock'
|
|
13
13
|
public_constant :MSG
|
|
14
14
|
|
|
15
|
-
# rubocop:disable Elegant/GoodMethodName
|
|
16
15
|
def on_new_investigation
|
|
17
16
|
processed_source.comments.each do |comment|
|
|
18
17
|
register(comment) unless allowed?(comment)
|
|
19
18
|
end
|
|
20
19
|
end
|
|
21
|
-
# rubocop:enable Elegant/GoodMethodName
|
|
22
20
|
|
|
23
21
|
private
|
|
24
22
|
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
5
|
+
|
|
6
|
+
module RuboCop
|
|
7
|
+
module Cop
|
|
8
|
+
module Elegant
|
|
9
|
+
class NoEmptyLinesInBlocks < Base
|
|
10
|
+
extend AutoCorrector
|
|
11
|
+
|
|
12
|
+
MSG = 'Empty line inside block body is not allowed'
|
|
13
|
+
public_constant :MSG
|
|
14
|
+
|
|
15
|
+
def on_new_investigation
|
|
16
|
+
super
|
|
17
|
+
@reported = []
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def on_block(node)
|
|
21
|
+
check(node)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def on_numblock(node)
|
|
25
|
+
check(node)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def on_if(node)
|
|
29
|
+
check(node)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def on_while(node)
|
|
33
|
+
check(node)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def on_until(node)
|
|
37
|
+
check(node)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def on_for(node)
|
|
41
|
+
check(node)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def on_case(node)
|
|
45
|
+
check(node)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def on_case_match(node)
|
|
49
|
+
check(node)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def on_kwbegin(node)
|
|
53
|
+
check(node)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
def check(node)
|
|
59
|
+
lines = range(node)
|
|
60
|
+
return if lines.nil?
|
|
61
|
+
empty(lines).each { |num| register(num) }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def range(node)
|
|
65
|
+
first = node.first_line + 1
|
|
66
|
+
last = node.last_line - 1
|
|
67
|
+
return if first > last
|
|
68
|
+
(first..last)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def empty(lines)
|
|
72
|
+
result = []
|
|
73
|
+
lines.each do |num|
|
|
74
|
+
line = processed_source.lines[num - 1]
|
|
75
|
+
result << num if line.strip.empty?
|
|
76
|
+
end
|
|
77
|
+
result
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def register(num)
|
|
81
|
+
return if @reported.include?(num)
|
|
82
|
+
@reported << num
|
|
83
|
+
target = processed_source.buffer.line_range(num)
|
|
84
|
+
add_offense(target) do |corrector|
|
|
85
|
+
corrector.remove(fullrange(target))
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def fullrange(target)
|
|
90
|
+
ending = target.end_pos
|
|
91
|
+
ending += 1 if processed_source.buffer.source[ending] == "\n"
|
|
92
|
+
target.with(end_pos: ending)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
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.19'
|
|
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.
|
|
4
|
+
version: 0.0.19
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yegor Bugayenko
|
|
@@ -56,6 +56,7 @@ files:
|
|
|
56
56
|
- lib/rubocop/cop/elegant/good_method_name.rb
|
|
57
57
|
- lib/rubocop/cop/elegant/good_variable_name.rb
|
|
58
58
|
- lib/rubocop/cop/elegant/no_comments.rb
|
|
59
|
+
- lib/rubocop/cop/elegant/no_empty_lines_in_blocks.rb
|
|
59
60
|
- lib/rubocop/cop/elegant/no_empty_lines_in_methods.rb
|
|
60
61
|
- lib/rubocop/cop/elegant_cops.rb
|
|
61
62
|
- lib/rubocop/elegant/plugin.rb
|