rubocop-elegant 0.0.1 → 0.0.2
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/config/default.yml +4 -0
- data/lib/rubocop/cop/elegant/no_empty_lines_in_methods.rb +64 -0
- data/lib/rubocop/cop/elegant_cops.rb +1 -0
- data/rubocop-elegant.gemspec +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 100bd3b91edc18d1b4ccd758ed60c6596b3c9a138f6dfa658fc276fd4ba673e5
|
|
4
|
+
data.tar.gz: afb97724cdb00b717601ac8285f32318bd6d7972fe137ba9d0503696364d3f6d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 075103cdab520aa962845d53c8bede02fa4052f78bcdd6de379400b3ad8df61650725c87c2013ad8175226c14cf07fbfb1116d9f40b3b16bf3de1077aa61d5bc
|
|
7
|
+
data.tar.gz: a699d37ec8bf83812fcde3c160e12605d83e2d8f3f75eb7da4c7b0dd8332b2ba33d790cf4fca0adaeec7505c68f401eb47f27602ff694b3b0e82841940e84f13
|
data/config/default.yml
CHANGED
|
@@ -8,3 +8,7 @@ Elegant/NoComments:
|
|
|
8
8
|
Description: 'Disallows comments in source code, except SPDX license comments'
|
|
9
9
|
Enabled: true
|
|
10
10
|
VersionAdded: '0.0.1'
|
|
11
|
+
Elegant/NoEmptyLinesInMethods:
|
|
12
|
+
Description: 'Disallows empty lines inside method bodies'
|
|
13
|
+
Enabled: true
|
|
14
|
+
VersionAdded: '0.0.2'
|
|
@@ -0,0 +1,64 @@
|
|
|
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 NoEmptyLinesInMethods < Base
|
|
10
|
+
extend AutoCorrector
|
|
11
|
+
|
|
12
|
+
MSG = 'Empty line inside method body is not allowed'
|
|
13
|
+
|
|
14
|
+
def on_def(node)
|
|
15
|
+
check(node)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def on_defs(node)
|
|
19
|
+
check(node)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def check(node)
|
|
25
|
+
return if node.body.nil?
|
|
26
|
+
body_range = body_range(node)
|
|
27
|
+
return if body_range.nil?
|
|
28
|
+
find_empty_lines(body_range).each do |line_range|
|
|
29
|
+
register(line_range)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def body_range(node)
|
|
34
|
+
first_line = node.body.first_line
|
|
35
|
+
last_line = node.body.last_line
|
|
36
|
+
return nil if first_line == last_line
|
|
37
|
+
(first_line..last_line)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def find_empty_lines(line_range)
|
|
41
|
+
empty = []
|
|
42
|
+
line_range.each do |line_num|
|
|
43
|
+
line = processed_source.lines[line_num - 1]
|
|
44
|
+
empty << line_num if line.strip.empty?
|
|
45
|
+
end
|
|
46
|
+
empty
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def register(line_num)
|
|
50
|
+
range = processed_source.buffer.line_range(line_num)
|
|
51
|
+
add_offense(range) do |corrector|
|
|
52
|
+
corrector.remove(line_with_newline(range))
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def line_with_newline(range)
|
|
57
|
+
end_pos = range.end_pos
|
|
58
|
+
end_pos += 1 if processed_source.buffer.source[end_pos] == "\n"
|
|
59
|
+
range.with(end_pos: end_pos)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
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.2'
|
|
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.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yegor Bugayenko
|
|
@@ -25,6 +25,7 @@ files:
|
|
|
25
25
|
- config/default.yml
|
|
26
26
|
- lib/rubocop-elegant.rb
|
|
27
27
|
- lib/rubocop/cop/elegant/no_comments.rb
|
|
28
|
+
- lib/rubocop/cop/elegant/no_empty_lines_in_methods.rb
|
|
28
29
|
- lib/rubocop/cop/elegant_cops.rb
|
|
29
30
|
- lib/rubocop/elegant/plugin.rb
|
|
30
31
|
- lib/rubocop/elegant/version.rb
|