rubocop-elegant 0.0.6 → 0.0.7
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/Rakefile +2 -2
- data/config/default.yml +23 -8
- data/lib/rubocop/cop/elegant/good_method_name.rb +37 -0
- data/lib/rubocop/cop/elegant/good_variable_name.rb +45 -0
- data/lib/rubocop/cop/elegant/no_comments.rb +15 -15
- data/lib/rubocop/cop/elegant/no_empty_lines_in_methods.rb +22 -24
- data/lib/rubocop/cop/elegant_cops.rb +2 -0
- data/lib/rubocop-elegant.rb +2 -2
- data/rubocop-elegant.gemspec +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9f7c0aef0e7b019ddcf1407cbb966e2547ff955cca1ffe8d3ec78a8d22eda8e6
|
|
4
|
+
data.tar.gz: 66f52927f1f7259b0fcf8d2f901aa2926f40e5097e53a301468bc5b4c38e847d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f109d30c32086be17e951884f862da17a291de33b3a5cfc6a1327b1d6446ac4a4d207f68a9356d7c72f1c212f31cac81afa9f075666b471e0c75a9ffb8185460
|
|
7
|
+
data.tar.gz: 622118dad505c7affc71c01070734a7e370a30d967752a30c204c1b77267dbb6d48640c58e8df81f1c1922cd149e8a491bcb898a11efa5e191670153f2d633ae
|
data/Rakefile
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'rake'
|
|
4
|
+
require 'rake/clean'
|
|
3
5
|
# SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
|
|
4
6
|
# SPDX-License-Identifier: MIT
|
|
5
7
|
|
|
6
8
|
require 'rubygems'
|
|
7
|
-
require 'rake'
|
|
8
|
-
require 'rake/clean'
|
|
9
9
|
|
|
10
10
|
CLEAN.include('coverage')
|
|
11
11
|
|
data/config/default.yml
CHANGED
|
@@ -12,20 +12,29 @@ Elegant/NoEmptyLinesInMethods:
|
|
|
12
12
|
Description: 'Disallows empty lines inside method bodies'
|
|
13
13
|
Enabled: true
|
|
14
14
|
VersionAdded: '0.0.2'
|
|
15
|
+
Elegant/GoodVariableName:
|
|
16
|
+
Description: 'Checks that variable names match the configured pattern'
|
|
17
|
+
Enabled: true
|
|
18
|
+
VersionAdded: '0.0.3'
|
|
19
|
+
Pattern: '^(@|@@|\$|the_|test_|fake_)?[a-z]{1,16}$'
|
|
20
|
+
Elegant/GoodMethodName:
|
|
21
|
+
Description: 'Checks that method names match the configured pattern'
|
|
22
|
+
Enabled: true
|
|
23
|
+
VersionAdded: '0.0.3'
|
|
24
|
+
Pattern: '^((fake_|the_)?[a-z]{1,16}[!?]?|test_[a-z_]+|on_[a-z_]+)$'
|
|
15
25
|
|
|
16
26
|
Naming/VariableName:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Max: 100
|
|
27
|
+
Enabled: false
|
|
28
|
+
Naming/MethodName:
|
|
29
|
+
Enabled: false
|
|
21
30
|
Metrics/ClassLength:
|
|
22
31
|
Max: 300
|
|
32
|
+
Metrics/MethodLength:
|
|
33
|
+
Max: 100
|
|
34
|
+
Metrics/BlockLength:
|
|
35
|
+
Max: 50
|
|
23
36
|
Metrics/AbcSize:
|
|
24
37
|
Max: 50
|
|
25
|
-
Naming/MethodName:
|
|
26
|
-
AllowedPatterns:
|
|
27
|
-
- '^(fake_|the_)?[a-z]{1,16}(!|\?)?$'
|
|
28
|
-
- '^test_[a-z_]+$'
|
|
29
38
|
Style/IfUnlessModifier:
|
|
30
39
|
Enabled: false
|
|
31
40
|
Naming/FileName:
|
|
@@ -68,6 +77,8 @@ Style/StaticClass:
|
|
|
68
77
|
Enabled: true
|
|
69
78
|
Style/TopLevelMethodDefinition:
|
|
70
79
|
Enabled: true
|
|
80
|
+
Exclude:
|
|
81
|
+
- 'Rakefile'
|
|
71
82
|
Style/ImplicitRuntimeError:
|
|
72
83
|
Enabled: true
|
|
73
84
|
Style/DateTime:
|
|
@@ -78,3 +89,7 @@ Performance/ChainArrayAllocation:
|
|
|
78
89
|
Enabled: true
|
|
79
90
|
Performance/OpenStruct:
|
|
80
91
|
Enabled: true
|
|
92
|
+
Metrics/CyclomaticComplexity:
|
|
93
|
+
Max: 15
|
|
94
|
+
Metrics/PerceivedComplexity:
|
|
95
|
+
Max: 15
|
|
@@ -0,0 +1,37 @@
|
|
|
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 GoodMethodName < Base
|
|
10
|
+
MSG = 'Method name "%<name>s" does not match the required pattern'
|
|
11
|
+
|
|
12
|
+
def on_def(node)
|
|
13
|
+
check(node, node.method_name.to_s)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def on_defs(node)
|
|
17
|
+
check(node, node.method_name.to_s)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def check(node, name)
|
|
23
|
+
return if match?(name)
|
|
24
|
+
add_offense(node, message: format(MSG, name: name))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def match?(name)
|
|
28
|
+
pattern.match?(name)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def pattern
|
|
32
|
+
@pattern ||= Regexp.new(cop_config['Pattern'] || '^[a-z]+[!?]?$')
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
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 GoodVariableName < Base
|
|
10
|
+
MSG = 'Variable name "%<name>s" does not match the required pattern'
|
|
11
|
+
|
|
12
|
+
def on_lvasgn(node)
|
|
13
|
+
check(node, node.children.first.to_s)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def on_ivasgn(node)
|
|
17
|
+
check(node, node.children.first.to_s)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def on_cvasgn(node)
|
|
21
|
+
check(node, node.children.first.to_s)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def on_gvasgn(node)
|
|
25
|
+
check(node, node.children.first.to_s)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def check(node, name)
|
|
31
|
+
return if match?(name)
|
|
32
|
+
add_offense(node, message: format(MSG, name: name))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def match?(name)
|
|
36
|
+
pattern.match?(name)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def pattern
|
|
40
|
+
@pattern ||= Regexp.new(cop_config['Pattern'] || '^[a-z]+$')
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -37,30 +37,30 @@ module RuboCop
|
|
|
37
37
|
|
|
38
38
|
def register(comment)
|
|
39
39
|
add_offense(comment) do |corrector|
|
|
40
|
-
corrector.remove(
|
|
40
|
+
corrector.remove(removal(comment))
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
def
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return
|
|
48
|
-
|
|
44
|
+
def removal(comment)
|
|
45
|
+
target = comment.source_range
|
|
46
|
+
prefix = target.source_line[0, target.column]
|
|
47
|
+
return fullrange(target) if prefix.strip.empty?
|
|
48
|
+
prefixed(target, prefix)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
def
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
def fullrange(target)
|
|
52
|
+
start = target.begin_pos - target.column
|
|
53
|
+
ending = target.end_pos
|
|
54
|
+
ending += 1 if newline?(ending)
|
|
55
|
+
target.with(begin_pos: start, end_pos: ending)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
def
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
def prefixed(target, prefix)
|
|
59
|
+
spaces = prefix.match(/\s*$/)[0]
|
|
60
|
+
target.with(begin_pos: target.begin_pos - spaces.length, end_pos: target.end_pos)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
def
|
|
63
|
+
def newline?(pos)
|
|
64
64
|
processed_source.buffer.source[pos] == "\n"
|
|
65
65
|
end
|
|
66
66
|
end
|
|
@@ -23,40 +23,38 @@ module RuboCop
|
|
|
23
23
|
|
|
24
24
|
def check(node)
|
|
25
25
|
return if node.body.nil?
|
|
26
|
-
|
|
27
|
-
return if
|
|
28
|
-
|
|
29
|
-
register(line_range)
|
|
30
|
-
end
|
|
26
|
+
lines = range(node)
|
|
27
|
+
return if lines.nil?
|
|
28
|
+
empty(lines).each { |num| register(num) }
|
|
31
29
|
end
|
|
32
30
|
|
|
33
|
-
def
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return nil if
|
|
37
|
-
(
|
|
31
|
+
def range(node)
|
|
32
|
+
first = node.body.first_line
|
|
33
|
+
last = node.body.last_line
|
|
34
|
+
return nil if first == last
|
|
35
|
+
(first..last)
|
|
38
36
|
end
|
|
39
37
|
|
|
40
|
-
def
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
line = processed_source.lines[
|
|
44
|
-
|
|
38
|
+
def empty(lines)
|
|
39
|
+
result = []
|
|
40
|
+
lines.each do |num|
|
|
41
|
+
line = processed_source.lines[num - 1]
|
|
42
|
+
result << num if line.strip.empty?
|
|
45
43
|
end
|
|
46
|
-
|
|
44
|
+
result
|
|
47
45
|
end
|
|
48
46
|
|
|
49
|
-
def register(
|
|
50
|
-
|
|
51
|
-
add_offense(
|
|
52
|
-
corrector.remove(
|
|
47
|
+
def register(num)
|
|
48
|
+
target = processed_source.buffer.line_range(num)
|
|
49
|
+
add_offense(target) do |corrector|
|
|
50
|
+
corrector.remove(fullrange(target))
|
|
53
51
|
end
|
|
54
52
|
end
|
|
55
53
|
|
|
56
|
-
def
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
def fullrange(target)
|
|
55
|
+
ending = target.end_pos
|
|
56
|
+
ending += 1 if processed_source.buffer.source[ending] == "\n"
|
|
57
|
+
target.with(end_pos: ending)
|
|
60
58
|
end
|
|
61
59
|
end
|
|
62
60
|
end
|
data/lib/rubocop-elegant.rb
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
|
5
5
|
|
|
6
6
|
require 'rubocop'
|
|
7
|
-
require_relative 'rubocop/elegant/version'
|
|
8
|
-
require_relative 'rubocop/elegant/plugin'
|
|
9
7
|
require_relative 'rubocop/cop/elegant_cops'
|
|
8
|
+
require_relative 'rubocop/elegant/plugin'
|
|
9
|
+
require_relative 'rubocop/elegant/version'
|
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.7'
|
|
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.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yegor Bugayenko
|
|
@@ -53,6 +53,8 @@ files:
|
|
|
53
53
|
- Rakefile
|
|
54
54
|
- config/default.yml
|
|
55
55
|
- lib/rubocop-elegant.rb
|
|
56
|
+
- lib/rubocop/cop/elegant/good_method_name.rb
|
|
57
|
+
- lib/rubocop/cop/elegant/good_variable_name.rb
|
|
56
58
|
- lib/rubocop/cop/elegant/no_comments.rb
|
|
57
59
|
- lib/rubocop/cop/elegant/no_empty_lines_in_methods.rb
|
|
58
60
|
- lib/rubocop/cop/elegant_cops.rb
|