rubocop-on-rbs 1.9.1 → 2.0.0.dev
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 +0 -4
- data/lib/rubocop/cop/rbs/layout/comment_indentation.rb +32 -34
- data/lib/rubocop/cop/rbs/layout/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/rbs/layout/empty_lines_around_overloads.rb +6 -22
- data/lib/rubocop/cop/rbs/layout/overload_indentation.rb +1 -9
- data/lib/rubocop/cop/rbs/layout/space_around_operators.rb +1 -19
- data/lib/rubocop/cop/rbs/layout/space_before_overload.rb +13 -27
- data/lib/rubocop/cop/rbs/style/block_return_boolish.rb +0 -1
- data/lib/rubocop/cop/rbs/style/class_with_singleton.rb +0 -1
- data/lib/rubocop/cop/rbs/style/initialize_return_type.rb +0 -1
- data/lib/rubocop/cop/rbs/style/instance_with_instance.rb +0 -1
- data/lib/rubocop/cop/rbs/style/redundant_parentheses.rb +0 -1
- data/lib/rubocop/cop/rbs_cops.rb +0 -1
- data/lib/rubocop/rbs/version.rb +1 -1
- metadata +6 -7
- data/lib/rubocop/cop/rbs/layout/annotation_indentation.rb +0 -89
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb12bf04d27c5b1e90a4537e696d0f43e3440653244e71ab14bd189ef876ad1d
|
|
4
|
+
data.tar.gz: 265c57dc1917d19594e7175696147db9668a48b57c1b463472488e8bae4eade6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 808e37b431fcbad539a5fc99910816f15d00ccde4f35c9e3139e76c22b458680ab9a3e5130436d7fe4d83d9967cea0c777f07b542b72cc669b6011a9a20e29a6
|
|
7
|
+
data.tar.gz: 9951c42a0f33cdca49d1c580ceecbb0d774b3534794e55ed08e69e274a657f8262f218ed759de4ef93c99ffd1aba79da238225f32f96edc2a4e990e5caaa5a46
|
data/config/default.yml
CHANGED
|
@@ -27,10 +27,6 @@ RBS:
|
|
|
27
27
|
RBS/Layout:
|
|
28
28
|
Enabled: true
|
|
29
29
|
|
|
30
|
-
RBS/Layout/AnnotationIndentation:
|
|
31
|
-
Description: 'Use 2 spaces for annotation indentation'
|
|
32
|
-
Enabled: true
|
|
33
|
-
|
|
34
30
|
RBS/Layout/CommentIndentation:
|
|
35
31
|
Description: 'Use 2 spaces for comment indentation'
|
|
36
32
|
Enabled: true
|
|
@@ -21,47 +21,45 @@ module RuboCop
|
|
|
21
21
|
MSG = "Incorrect indentation detected (column %<expect>s instead of %<actual>s)."
|
|
22
22
|
|
|
23
23
|
def on_rbs_new_investigation
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
indent_start_lines = Set.new
|
|
25
|
+
indent_end_lines = Set.new
|
|
26
|
+
processed_rbs_source.decls.each do |decl|
|
|
27
|
+
walk_decl(decl) do |d|
|
|
28
|
+
indent_start_lines << d.location.start_line
|
|
29
|
+
indent_end_lines << d.location.end_line
|
|
30
|
+
end
|
|
27
31
|
end
|
|
28
|
-
end
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
expected_width = 0
|
|
34
|
+
processed_rbs_source.tokens.each do |token|
|
|
35
|
+
case token.type
|
|
36
|
+
when :kMODULE, :kCLASS, :kINTERFACE
|
|
37
|
+
next unless indent_start_lines.include?(token.location.start_line)
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
expected_width += 2
|
|
40
|
+
when :kEND
|
|
41
|
+
next unless indent_end_lines.include?(token.location.start_line)
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
expected_width -= 2
|
|
44
|
+
when :tLINECOMMENT
|
|
45
|
+
if token.location.start_column != expected_width
|
|
46
|
+
token_range = location_to_range(token.location)
|
|
47
|
+
message = format(MSG, expect: expected_width, actual: token.location.start_column)
|
|
48
|
+
add_offense(token_range, message: message) do |corrector|
|
|
49
|
+
line_start_pos = processed_source.buffer.line_range(token.location.start_line).begin_pos
|
|
50
|
+
indent = range_between(line_start_pos, token.location.start_pos)
|
|
51
|
+
corrector.replace(indent, ' ' * expected_width)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
44
55
|
end
|
|
45
56
|
end
|
|
46
57
|
|
|
47
|
-
def
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def correct_indentation(next_line)
|
|
53
|
-
return 0 unless next_line
|
|
54
|
-
|
|
55
|
-
indentation_of_next_line = next_line =~ /\S/
|
|
56
|
-
indentation_of_next_line + if less_indented?(next_line)
|
|
57
|
-
2
|
|
58
|
-
else
|
|
59
|
-
0
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def less_indented?(line)
|
|
64
|
-
/\A\s*end\b/.match?(line)
|
|
58
|
+
def walk_decl(decl, &block)
|
|
59
|
+
if decl.respond_to?(:members)
|
|
60
|
+
yield decl
|
|
61
|
+
decl.members.each { |member| walk_decl(member, &block) }
|
|
62
|
+
end
|
|
65
63
|
end
|
|
66
64
|
end
|
|
67
65
|
end
|
|
@@ -68,7 +68,7 @@ module RuboCop
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def previous_line_ignoring_comments(processed_source, send_line)
|
|
71
|
-
processed_source[0..
|
|
71
|
+
processed_source[0..send_line - 2].reverse.find { |line| !comment_line?(line) }
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
def previous_line_empty?(send_line)
|
|
@@ -21,35 +21,19 @@ module RuboCop
|
|
|
21
21
|
|
|
22
22
|
MSG = 'Empty line detected around overloads.'
|
|
23
23
|
|
|
24
|
-
# @rbs decl: ::RBS::AST::Members::MethodDefinition
|
|
25
|
-
# @rbs return: void
|
|
26
24
|
def on_rbs_def(decl)
|
|
27
|
-
decl.overloads.
|
|
28
|
-
end_line = overload&.method_type&.location&.end_line || 0
|
|
29
|
-
next_start_line = next_overload&.method_type&.location&.start_line || 0
|
|
30
|
-
check_empty_lines(end_line, next_start_line)
|
|
31
|
-
end
|
|
25
|
+
return unless 1 < decl.overloads.length
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
#
|
|
36
|
-
# | ...
|
|
37
|
-
end_location = decl.overloads.last.method_type.location or return
|
|
38
|
-
slice = processed_source.raw_source[end_location.end_pos..] or return
|
|
39
|
-
bar_index = slice.index('|') or return
|
|
40
|
-
bar_line = slice[0..bar_index]&.count("\n") or return
|
|
41
|
-
check_empty_lines(end_location.end_line, end_location.end_line + bar_line)
|
|
27
|
+
decl.overloads.each_cons(2) do |overload, next_overload|
|
|
28
|
+
check_empty_lines(overload, next_overload)
|
|
42
29
|
end
|
|
43
30
|
end
|
|
44
31
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
# @rbs return: void
|
|
48
|
-
def check_empty_lines(end_line, next_start_line)
|
|
49
|
-
return if end_line + 1 == next_start_line
|
|
32
|
+
def check_empty_lines(overload, next_overload)
|
|
33
|
+
return if overload.method_type.location.end_line + 1 == next_overload.method_type.location.start_line
|
|
50
34
|
|
|
51
35
|
total = 0
|
|
52
|
-
range = end_line...(
|
|
36
|
+
range = overload.method_type.location.end_line...(next_overload.method_type.location.start_line - 1)
|
|
53
37
|
processed_source.raw_source.each_line.each_with_index do |line, lineno|
|
|
54
38
|
if range.cover?(lineno) && line == "\n"
|
|
55
39
|
empty_line = range_between(total, total + 1)
|
|
@@ -39,11 +39,8 @@ module RuboCop
|
|
|
39
39
|
|
|
40
40
|
loc = bar&.location
|
|
41
41
|
next unless loc
|
|
42
|
+
next unless overload_starts.include?(base_pos + after.location.start_pos)
|
|
42
43
|
|
|
43
|
-
# pDOT3 is not included in decl.overloads
|
|
44
|
-
next unless overload_starts.include?(base_pos + after.location.start_pos) || after.type == :pDOT3
|
|
45
|
-
|
|
46
|
-
# () -> void | (Integer) -> void
|
|
47
44
|
if before.location.end_line == bar.location.start_line
|
|
48
45
|
range = range_between(base_pos + bar.location.start_pos, base_pos + bar.location.end_pos)
|
|
49
46
|
add_offense(range, message: "Insert newline before `|`") do |corrector|
|
|
@@ -52,17 +49,12 @@ module RuboCop
|
|
|
52
49
|
end
|
|
53
50
|
end
|
|
54
51
|
|
|
55
|
-
# () -> void
|
|
56
|
-
# |
|
|
57
|
-
# (Integer) -> void
|
|
58
52
|
if bar.location.end_line != after.location.start_line
|
|
59
53
|
range = range_between(base_pos + bar.location.start_pos, base_pos + bar.location.end_pos)
|
|
60
54
|
add_offense(range, message: "Remove newline after `|`") do |corrector|
|
|
61
55
|
space = range_between(base_pos + bar.location.end_pos, base_pos + after.location.start_pos)
|
|
62
56
|
corrector.replace(space, ' ')
|
|
63
57
|
end
|
|
64
|
-
# : () -> void
|
|
65
|
-
# | (Integer) -> void
|
|
66
58
|
elsif bar.location.start_column != first_colon_column
|
|
67
59
|
range = range_between(base_pos + bar.location.start_pos, base_pos + bar.location.end_pos)
|
|
68
60
|
add_offense(range, message: 'Indent the `|` to the first `:`') do |corrector|
|
|
@@ -14,15 +14,8 @@ module RuboCop
|
|
|
14
14
|
class SpaceAroundOperators < RuboCop::RBS::CopBase
|
|
15
15
|
extend AutoCorrector
|
|
16
16
|
|
|
17
|
-
def on_rbs_class(decl)
|
|
18
|
-
check_type_params(decl)
|
|
19
|
-
end
|
|
20
|
-
alias on_rbs_module on_rbs_class
|
|
21
|
-
alias on_rbs_interface on_rbs_class
|
|
22
|
-
|
|
23
17
|
def on_rbs_def(decl)
|
|
24
18
|
decl.overloads.each do |overload|
|
|
25
|
-
check_type_params(overload.method_type)
|
|
26
19
|
overload.method_type.each_type do |type|
|
|
27
20
|
check_type(type)
|
|
28
21
|
end
|
|
@@ -33,14 +26,10 @@ module RuboCop
|
|
|
33
26
|
check_type(decl.type)
|
|
34
27
|
end
|
|
35
28
|
alias on_rbs_global on_rbs_constant
|
|
29
|
+
alias on_rbs_type_alias on_rbs_constant
|
|
36
30
|
alias on_rbs_attribute on_rbs_constant
|
|
37
31
|
alias on_rbs_var on_rbs_constant
|
|
38
32
|
|
|
39
|
-
def on_rbs_type_alias(decl)
|
|
40
|
-
check_type_params(decl)
|
|
41
|
-
check_type(decl.type)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
33
|
def check_type(type)
|
|
45
34
|
case type
|
|
46
35
|
when ::RBS::Types::Union
|
|
@@ -53,13 +42,6 @@ module RuboCop
|
|
|
53
42
|
end
|
|
54
43
|
end
|
|
55
44
|
|
|
56
|
-
def check_type_params(decl)
|
|
57
|
-
decl.type_params.each do |type_param|
|
|
58
|
-
check_type(type_param.default_type) if type_param.default_type
|
|
59
|
-
check_type(type_param.upper_bound_type) if type_param.upper_bound_type
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
45
|
def check_operator(type, operator)
|
|
64
46
|
type.types.each_cons(2) do |before, after|
|
|
65
47
|
next unless before.location.end_line == after.location.start_line
|
|
@@ -17,39 +17,25 @@ module RuboCop
|
|
|
17
17
|
|
|
18
18
|
MSG = 'Use one space before overload.'
|
|
19
19
|
|
|
20
|
-
# @
|
|
20
|
+
# @sig decl: ::RBS::AST::Members::MethodDefinition
|
|
21
21
|
def on_rbs_def(decl)
|
|
22
|
+
source = processed_source.raw_source
|
|
22
23
|
decl.overloads.each_with_index do |overload, i|
|
|
23
|
-
loc = overload.method_type.location
|
|
24
|
+
loc = overload.method_type.location
|
|
24
25
|
overload_char = i == 0 ? ':' : '|'
|
|
25
|
-
check(loc, overload_char)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
if decl.overloading?
|
|
29
|
-
loc = decl.location or return
|
|
30
|
-
overloading_loc = loc[:overloading] or return
|
|
31
|
-
overload_char = decl.overloads.length == 0 ? ':' : '|'
|
|
32
|
-
check(overloading_loc, overload_char)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
private
|
|
37
|
-
|
|
38
|
-
# @rbs loc: ::RBS::Location[bot, bot]
|
|
39
|
-
def check(loc, overload_char)
|
|
40
|
-
source = processed_source.raw_source
|
|
41
26
|
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
char_start_pos = source.rindex(overload_char, loc.start_pos)
|
|
28
|
+
next unless char_start_pos
|
|
44
29
|
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
word_after_char_pos = source.index(/[^\s]/, char_start_pos + 1)
|
|
31
|
+
next unless word_after_char_pos
|
|
47
32
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
33
|
+
if char_start_pos + 2 != word_after_char_pos
|
|
34
|
+
char = range_between(char_start_pos, char_start_pos + 1)
|
|
35
|
+
add_offense(char) do |corrector|
|
|
36
|
+
range = range_between(char_start_pos + 1, word_after_char_pos)
|
|
37
|
+
corrector.replace(range, ' ')
|
|
38
|
+
end
|
|
53
39
|
end
|
|
54
40
|
end
|
|
55
41
|
end
|
data/lib/rubocop/cop/rbs_cops.rb
CHANGED
data/lib/rubocop/rbs/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-on-rbs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0.dev
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ksss
|
|
@@ -27,16 +27,16 @@ dependencies:
|
|
|
27
27
|
name: rbs
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
|
-
- -
|
|
30
|
+
- - '='
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
32
|
+
version: 4.0.0.dev.4
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
|
-
- -
|
|
37
|
+
- - '='
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version:
|
|
39
|
+
version: 4.0.0.dev.4
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: rubocop
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -84,7 +84,6 @@ files:
|
|
|
84
84
|
- README.md
|
|
85
85
|
- config/default.yml
|
|
86
86
|
- lib/rubocop-on-rbs.rb
|
|
87
|
-
- lib/rubocop/cop/rbs/layout/annotation_indentation.rb
|
|
88
87
|
- lib/rubocop/cop/rbs/layout/comment_indentation.rb
|
|
89
88
|
- lib/rubocop/cop/rbs/layout/empty_line_between_declarations.rb
|
|
90
89
|
- lib/rubocop/cop/rbs/layout/empty_lines.rb
|
|
@@ -160,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
160
159
|
- !ruby/object:Gem::Version
|
|
161
160
|
version: '0'
|
|
162
161
|
requirements: []
|
|
163
|
-
rubygems_version:
|
|
162
|
+
rubygems_version: 3.6.9
|
|
164
163
|
specification_version: 4
|
|
165
164
|
summary: RuboCop extension for RBS file.
|
|
166
165
|
test_files: []
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module RuboCop
|
|
4
|
-
module Cop
|
|
5
|
-
module RBS
|
|
6
|
-
module Layout
|
|
7
|
-
# Checks the indentation of annotations in RBS.
|
|
8
|
-
#
|
|
9
|
-
# @example
|
|
10
|
-
# # bad
|
|
11
|
-
# # comment
|
|
12
|
-
# %a{pure}
|
|
13
|
-
# def foo: () -> void
|
|
14
|
-
#
|
|
15
|
-
# # good
|
|
16
|
-
# # comment
|
|
17
|
-
# %a{pure}
|
|
18
|
-
# def foo: () -> void
|
|
19
|
-
#
|
|
20
|
-
class AnnotationIndentation < RuboCop::RBS::CopBase
|
|
21
|
-
extend AutoCorrector
|
|
22
|
-
|
|
23
|
-
MSG = "Incorrect indentation detected (column %<expect>s instead of %<actual>s)."
|
|
24
|
-
|
|
25
|
-
def on_rbs_new_investigation
|
|
26
|
-
indent_start_lines = Set.new
|
|
27
|
-
indent_end_lines = Set.new
|
|
28
|
-
ignore_poses = Set.new
|
|
29
|
-
processed_rbs_source.decls.each do |decl|
|
|
30
|
-
walk_decl(decl) do |d|
|
|
31
|
-
indent_start_lines << d.location.start_line
|
|
32
|
-
indent_end_lines << d.location.end_line
|
|
33
|
-
d.members.each do |member|
|
|
34
|
-
case member
|
|
35
|
-
when ::RBS::AST::Members::MethodDefinition
|
|
36
|
-
member.overloads.each do |overload|
|
|
37
|
-
overload.annotations.each do |annotation|
|
|
38
|
-
ignore_poses << annotation.location.start_pos
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
expected_width = 0
|
|
47
|
-
last_annotation_line = -1
|
|
48
|
-
processed_rbs_source.tokens.each do |token|
|
|
49
|
-
case token.type
|
|
50
|
-
when :kMODULE, :kCLASS, :kINTERFACE
|
|
51
|
-
next unless indent_start_lines.include?(token.location.start_line)
|
|
52
|
-
|
|
53
|
-
expected_width += 2
|
|
54
|
-
when :kEND
|
|
55
|
-
next unless indent_end_lines.include?(token.location.start_line)
|
|
56
|
-
|
|
57
|
-
expected_width -= 2
|
|
58
|
-
when :tANNOTATION
|
|
59
|
-
next if ignore_poses.include?(token.location.start_pos)
|
|
60
|
-
|
|
61
|
-
if token.location.start_column == expected_width
|
|
62
|
-
last_annotation_line = token.location.start_line
|
|
63
|
-
next
|
|
64
|
-
end
|
|
65
|
-
next if last_annotation_line == token.location.start_line
|
|
66
|
-
|
|
67
|
-
token_range = location_to_range(token.location)
|
|
68
|
-
message = format(MSG, expect: expected_width, actual: token.location.start_column)
|
|
69
|
-
last_annotation_line = token.location.start_line
|
|
70
|
-
add_offense(token_range, message: message) do |corrector|
|
|
71
|
-
line_start_pos = processed_source.buffer.line_range(token.location.start_line).begin_pos
|
|
72
|
-
indent = range_between(line_start_pos, token.location.start_pos)
|
|
73
|
-
corrector.replace(indent, ' ' * expected_width)
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def walk_decl(decl, &block)
|
|
80
|
-
if decl.respond_to?(:members)
|
|
81
|
-
yield decl
|
|
82
|
-
decl.members.each { |member| walk_decl(member, &block) }
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|