rubocop-on-rbs 0.9.0 → 1.1.0
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/CHANGELOG.md +16 -0
- data/config/default.yml +21 -1
- data/lib/rubocop/cop/rbs/layout/empty_lines.rb +46 -0
- data/lib/rubocop/cop/rbs/layout/empty_lines_around_access_modifier.rb +105 -0
- data/lib/rubocop/cop/rbs/layout/empty_lines_around_body.rb +48 -0
- data/lib/rubocop/cop/rbs/layout/empty_lines_around_class_body.rb +29 -0
- data/lib/rubocop/cop/rbs/layout/empty_lines_around_interface_body.rb +29 -0
- data/lib/rubocop/cop/rbs/layout/empty_lines_around_module_body.rb +29 -0
- data/lib/rubocop/cop/rbs/layout/empty_lines_around_overloads.rb +5 -6
- data/lib/rubocop/cop/rbs/layout/end_alignment.rb +2 -0
- data/lib/rubocop/cop/rbs/lint/ambiguous_operator_precedence.rb +1 -1
- data/lib/rubocop/cop/rbs_cops.rb +6 -0
- data/lib/rubocop/rbs/cop_base.rb +6 -0
- data/lib/rubocop/rbs/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c58e575d4d662fa8cf0539226bc2c9f2bcd9358cfd751c3e776ce6f66ebcb86
|
4
|
+
data.tar.gz: 7e7411ebc61e2dfc2751fb3cb3e827580ecc5c7715c0eb5accd62532e3aad3eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bba5622fc180ce5d83f368f418d9c2a730f233de4e0c66f4ca8ef07563471d714fbdc614d6149ecb001fbfbedbe4a128df6417dc8a7c1b9f6687b18e5bcf08fc
|
7
|
+
data.tar.gz: 33ab0de3a1621c4298e98f5e2577c0bcc55becc71cf0d688c59256181edcaac513bf4c04b6c9790dd176878489a4b1bd0de897285e36ed5d1d18ad15dd07289b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.0.0] - 2024-09-17
|
4
|
+
|
5
|
+
* Add RBS/Layout/EmptyLines by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/35
|
6
|
+
* Fix doc for EmptyLinesAroundOverloads by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/36
|
7
|
+
* Add Layout/EmptyLinesAround{Class,Module}Body by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/37
|
8
|
+
* Add RBS/Layout/EmptyLinesAroundInterfaceBody by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/38
|
9
|
+
|
10
|
+
## [0.9.0] - 2024-08-07
|
11
|
+
|
12
|
+
* Fix error if includes multibyte characters by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/31
|
13
|
+
|
14
|
+
## [0.8.0] - 2024-08-06
|
15
|
+
|
16
|
+
* Fix use of argument in upper_bound by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/24
|
17
|
+
* Security update by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/29
|
18
|
+
|
3
19
|
## [0.7.0] - 2024-06-27
|
4
20
|
|
5
21
|
* Add RBS/Lint/AmbiguousOperatorPrecedence by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/22
|
data/config/default.yml
CHANGED
@@ -31,10 +31,30 @@ RBS/Layout/CommentIndentation:
|
|
31
31
|
Description: 'Use 2 spaces for comment indentation'
|
32
32
|
Enabled: true
|
33
33
|
|
34
|
-
RBS/Layout/
|
34
|
+
RBS/Layout/EmptyLinesAroundAccessModifier:
|
35
|
+
Description: "Keeps track of empty lines around access modifiers."
|
36
|
+
Enabled: true
|
37
|
+
|
38
|
+
RBS/Layout/EmptyLinesAroundClassBody:
|
39
|
+
Description: "Keeps track of empty lines around class bodies."
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
RBS/Layout/EmptyLinesAroundInterfaceBody:
|
43
|
+
Description: "Keeps track of empty lines around interface bodies."
|
44
|
+
Enabled: true
|
45
|
+
|
46
|
+
RBS/Layout/EmptyLinesAroundModuleBody:
|
47
|
+
Description: "Keeps track of empty lines around module bodies."
|
48
|
+
Enabled: true
|
49
|
+
|
50
|
+
RBS/Layout/EmptyLinesAroundOverloads:
|
35
51
|
Description: 'No empty line between overload'
|
36
52
|
Enabled: true
|
37
53
|
|
54
|
+
RBS/Layout/EmptyLines:
|
55
|
+
Description: "Don't use several empty lines in a row."
|
56
|
+
Enabled: true
|
57
|
+
|
38
58
|
RBS/Layout/EndAlignment:
|
39
59
|
Description: 'Align `end` keyword'
|
40
60
|
Enabled: true
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RBS
|
6
|
+
module Layout
|
7
|
+
# Checks for two or more consecutive blank lines.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad - It has two empty lines.
|
12
|
+
# def foo: () -> void
|
13
|
+
# # one empty line
|
14
|
+
# # two empty lines
|
15
|
+
# def bar: () -> void
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# def foo: () -> void
|
19
|
+
# # one empty line
|
20
|
+
# def bar: () -> void
|
21
|
+
#
|
22
|
+
class EmptyLines < RuboCop::RBS::CopBase
|
23
|
+
include RangeHelp
|
24
|
+
extend AutoCorrector
|
25
|
+
|
26
|
+
MSG = 'Extra blank line detected.'
|
27
|
+
|
28
|
+
def on_rbs_new_investigation
|
29
|
+
# Quick check if we possibly have consecutive blank lines.
|
30
|
+
return unless processed_source.raw_source.include?("\n\n\n")
|
31
|
+
|
32
|
+
source = processed_source.raw_source
|
33
|
+
pos = 0
|
34
|
+
while index = source.index("\n\n\n", pos)
|
35
|
+
range = range_between(index + 2, index + 3)
|
36
|
+
add_offense(range) do |corrector|
|
37
|
+
corrector.remove(range)
|
38
|
+
end
|
39
|
+
pos = index + 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RBS
|
6
|
+
module Layout
|
7
|
+
# Access modifiers should be surrounded by blank lines.
|
8
|
+
#
|
9
|
+
# # bad
|
10
|
+
# class Foo
|
11
|
+
# def bar: () -> void
|
12
|
+
# private
|
13
|
+
# def baz: () -> void
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# class Foo
|
18
|
+
# def bar: () -> void
|
19
|
+
#
|
20
|
+
# private
|
21
|
+
#
|
22
|
+
# def baz: () -> void
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
class EmptyLinesAroundAccessModifier < RuboCop::RBS::CopBase
|
26
|
+
extend AutoCorrector
|
27
|
+
|
28
|
+
MSG = 'Keep a blank line before and after `<%<kind>s>`.'
|
29
|
+
|
30
|
+
def on_rbs_class(decl)
|
31
|
+
@class_or_module_def_first_line = decl.location.start_line
|
32
|
+
@class_or_module_def_last_line = decl.location.end_line
|
33
|
+
end
|
34
|
+
alias on_rbs_module on_rbs_class
|
35
|
+
|
36
|
+
def on_rbs_public(member)
|
37
|
+
check(member, 'public')
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_rbs_private(member)
|
41
|
+
check(member, 'private')
|
42
|
+
end
|
43
|
+
|
44
|
+
def check(member, kind)
|
45
|
+
line = member.location.start_line
|
46
|
+
|
47
|
+
before = processed_source.lines[line - 2]
|
48
|
+
if before.empty? || before.match?(/[^\s]/)
|
49
|
+
add_offense_with(member, kind)
|
50
|
+
end
|
51
|
+
|
52
|
+
after = processed_source.lines[line]
|
53
|
+
if after&.empty? || after&.match?(/[^\s]/)
|
54
|
+
add_offense_with(member, kind)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_offense_with(member, kind)
|
59
|
+
return if expected_empty_lines?(member)
|
60
|
+
|
61
|
+
range = location_to_range(member.location)
|
62
|
+
add_offense(range, message: format(MSG, kind: kind)) do |corrector|
|
63
|
+
current_line = range_by_whole_lines(range)
|
64
|
+
corrector.insert_before(current_line, "\n") unless previous_line_empty?(member.location.start_line)
|
65
|
+
corrector.insert_after(current_line, "\n") unless next_line_empty?(member.location.end_line)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def previous_line_ignoring_comments(processed_source, send_line)
|
70
|
+
processed_source[0..send_line - 2].reverse.find { |line| !comment_line?(line) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def previous_line_empty?(send_line)
|
74
|
+
previous_line = previous_line_ignoring_comments(processed_source, send_line)
|
75
|
+
return true unless previous_line
|
76
|
+
|
77
|
+
class_def?(send_line) || previous_line.blank?
|
78
|
+
end
|
79
|
+
|
80
|
+
def next_line_empty?(last_send_line)
|
81
|
+
next_line = processed_source[last_send_line]
|
82
|
+
|
83
|
+
body_end?(last_send_line) || next_line.blank?
|
84
|
+
end
|
85
|
+
|
86
|
+
def expected_empty_lines?(member)
|
87
|
+
previous_line_empty?(member.location.start_line) && next_line_empty?(member.location.end_line)
|
88
|
+
end
|
89
|
+
|
90
|
+
def class_def?(line)
|
91
|
+
return false unless @class_or_module_def_first_line
|
92
|
+
|
93
|
+
line == @class_or_module_def_first_line + 1
|
94
|
+
end
|
95
|
+
|
96
|
+
def body_end?(line)
|
97
|
+
return false unless @class_or_module_def_last_line
|
98
|
+
|
99
|
+
line == @class_or_module_def_last_line - 1
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RBS
|
6
|
+
module Layout
|
7
|
+
module EmptyLinesAroundBody
|
8
|
+
MSG_EXTRA = 'Extra empty line detected at %<kind>s body %<location>s.'
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def check(decl)
|
13
|
+
first_line = decl.location.start_line
|
14
|
+
last_line = decl.location.end_line
|
15
|
+
|
16
|
+
check_beginning(first_line)
|
17
|
+
check_ending(last_line)
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_beginning(first_line)
|
21
|
+
check_source(first_line, 'beginning')
|
22
|
+
end
|
23
|
+
|
24
|
+
def check_ending(last_line)
|
25
|
+
check_source(last_line - 2, 'end')
|
26
|
+
end
|
27
|
+
|
28
|
+
def check_source(line_no, desc)
|
29
|
+
return unless line_no.positive?
|
30
|
+
return unless processed_source.lines[line_no]
|
31
|
+
return unless processed_source.lines[line_no].empty?
|
32
|
+
return unless processed_source.lines[line_no + 1]
|
33
|
+
|
34
|
+
range = source_range(processed_source.buffer, line_no + 1, 0)
|
35
|
+
message = message(MSG_EXTRA, desc)
|
36
|
+
add_offense(range, message: message) do |corrector|
|
37
|
+
corrector.remove(range)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def message(type, location)
|
42
|
+
format(type, kind: self.class::KIND, location: location)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RBS
|
6
|
+
module Layout
|
7
|
+
# Checks if empty lines around the bodies of classes match
|
8
|
+
# the configuration.
|
9
|
+
#
|
10
|
+
# @example default
|
11
|
+
# # good
|
12
|
+
#
|
13
|
+
# class Foo
|
14
|
+
# def bar: () -> void
|
15
|
+
# end
|
16
|
+
class EmptyLinesAroundClassBody < RuboCop::RBS::CopBase
|
17
|
+
include EmptyLinesAroundBody
|
18
|
+
extend AutoCorrector
|
19
|
+
|
20
|
+
KIND = 'class'
|
21
|
+
|
22
|
+
def on_rbs_class(decl)
|
23
|
+
check(decl)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RBS
|
6
|
+
module Layout
|
7
|
+
# Checks if empty lines around the bodies of interfaces match
|
8
|
+
# the configuration.
|
9
|
+
#
|
10
|
+
# @example default
|
11
|
+
# # good
|
12
|
+
#
|
13
|
+
# interface _Foo
|
14
|
+
# def bar: () -> void
|
15
|
+
# end
|
16
|
+
class EmptyLinesAroundInterfaceBody < RuboCop::RBS::CopBase
|
17
|
+
include EmptyLinesAroundBody
|
18
|
+
extend AutoCorrector
|
19
|
+
|
20
|
+
KIND = 'interface'
|
21
|
+
|
22
|
+
def on_rbs_interface(decl)
|
23
|
+
check(decl)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RBS
|
6
|
+
module Layout
|
7
|
+
# Checks if empty lines around the bodies of modules match
|
8
|
+
# the configuration.
|
9
|
+
#
|
10
|
+
# @example default
|
11
|
+
# # good
|
12
|
+
#
|
13
|
+
# module Foo
|
14
|
+
# def bar: () -> void
|
15
|
+
# end
|
16
|
+
class EmptyLinesAroundModuleBody < RuboCop::RBS::CopBase
|
17
|
+
include EmptyLinesAroundBody
|
18
|
+
extend AutoCorrector
|
19
|
+
|
20
|
+
KIND = 'module'
|
21
|
+
|
22
|
+
def on_rbs_module(decl)
|
23
|
+
check(decl)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -6,14 +6,13 @@ module RuboCop
|
|
6
6
|
module Layout
|
7
7
|
# @example default
|
8
8
|
# # bad
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
9
|
+
# def foo: () -> void
|
10
|
+
#
|
11
|
+
# | (Integer) -> Integer
|
12
12
|
#
|
13
13
|
# # good
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# end
|
14
|
+
# def foo: () -> void
|
15
|
+
# | (Integer) -> Integer
|
17
16
|
class EmptyLinesAroundOverloads < RuboCop::RBS::CopBase
|
18
17
|
extend AutoCorrector
|
19
18
|
|
data/lib/rubocop/cop/rbs_cops.rb
CHANGED
@@ -3,7 +3,13 @@
|
|
3
3
|
require 'rbs'
|
4
4
|
|
5
5
|
require_relative 'rbs/layout/comment_indentation'
|
6
|
+
require_relative 'rbs/layout/empty_lines_around_access_modifier'
|
7
|
+
require_relative 'rbs/layout/empty_lines_around_body'
|
8
|
+
require_relative 'rbs/layout/empty_lines_around_class_body'
|
9
|
+
require_relative 'rbs/layout/empty_lines_around_interface_body'
|
10
|
+
require_relative 'rbs/layout/empty_lines_around_module_body'
|
6
11
|
require_relative 'rbs/layout/empty_lines_around_overloads'
|
12
|
+
require_relative 'rbs/layout/empty_lines'
|
7
13
|
require_relative 'rbs/layout/end_alignment'
|
8
14
|
require_relative 'rbs/layout/extra_spacing'
|
9
15
|
require_relative 'rbs/layout/indentation_width'
|
data/lib/rubocop/rbs/cop_base.rb
CHANGED
@@ -71,6 +71,8 @@ module RuboCop
|
|
71
71
|
def on_rbs_type_alias(decl); end
|
72
72
|
def on_rbs_def(member); end
|
73
73
|
def on_rbs_attribute(member); end
|
74
|
+
def on_rbs_public(member); end
|
75
|
+
def on_rbs_private(member); end
|
74
76
|
|
75
77
|
def walk(decl)
|
76
78
|
case decl
|
@@ -93,6 +95,10 @@ module RuboCop
|
|
93
95
|
on_rbs_def(decl)
|
94
96
|
when ::RBS::AST::Members::Attribute
|
95
97
|
on_rbs_attribute(decl)
|
98
|
+
when ::RBS::AST::Members::Public
|
99
|
+
on_rbs_public(decl)
|
100
|
+
when ::RBS::AST::Members::Private
|
101
|
+
on_rbs_private(decl)
|
96
102
|
end
|
97
103
|
end
|
98
104
|
|
data/lib/rubocop/rbs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-on-rbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbs
|
@@ -66,6 +66,12 @@ files:
|
|
66
66
|
- config/default.yml
|
67
67
|
- lib/rubocop-on-rbs.rb
|
68
68
|
- lib/rubocop/cop/rbs/layout/comment_indentation.rb
|
69
|
+
- lib/rubocop/cop/rbs/layout/empty_lines.rb
|
70
|
+
- lib/rubocop/cop/rbs/layout/empty_lines_around_access_modifier.rb
|
71
|
+
- lib/rubocop/cop/rbs/layout/empty_lines_around_body.rb
|
72
|
+
- lib/rubocop/cop/rbs/layout/empty_lines_around_class_body.rb
|
73
|
+
- lib/rubocop/cop/rbs/layout/empty_lines_around_interface_body.rb
|
74
|
+
- lib/rubocop/cop/rbs/layout/empty_lines_around_module_body.rb
|
69
75
|
- lib/rubocop/cop/rbs/layout/empty_lines_around_overloads.rb
|
70
76
|
- lib/rubocop/cop/rbs/layout/end_alignment.rb
|
71
77
|
- lib/rubocop/cop/rbs/layout/extra_spacing.rb
|