rubocop-on-rbs 1.8.0 → 1.9.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/config/default.yml +4 -0
- data/lib/rubocop/cop/rbs/layout/annotation_indentation.rb +89 -0
- data/lib/rubocop/cop/rbs/layout/comment_indentation.rb +34 -32
- data/lib/rubocop/cop/rbs/layout/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/rbs/layout/space_around_operators.rb +19 -1
- data/lib/rubocop/cop/rbs/style/block_return_boolish.rb +1 -0
- data/lib/rubocop/cop/rbs/style/class_with_singleton.rb +1 -0
- data/lib/rubocop/cop/rbs/style/initialize_return_type.rb +1 -0
- data/lib/rubocop/cop/rbs/style/instance_with_instance.rb +1 -0
- data/lib/rubocop/cop/rbs/style/redundant_parentheses.rb +1 -0
- data/lib/rubocop/cop/rbs_cops.rb +1 -0
- data/lib/rubocop/rbs/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af5e7c84d5044bb2a7d6e95b4de88a076e9624c96011d0eb41dae6f2de20fec6
|
|
4
|
+
data.tar.gz: 6270af5147ea7981766721a24b70e6cb5adcf82c82c82ba91c5dbe8f0409de43
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7b66215eae031a7c9f9cf95498b57998d0942da9a96920684d34227230ab250868e5a3d75cb5bbbf15a90ce8b43dcf0e8a9dd532b4fb41edf486eecdd2df411f
|
|
7
|
+
data.tar.gz: 477c78f1eacc84844b52bf1e2626597d3304a97ed47f4a7641a0be9fff7ddd6f00789aa0953c54cc9dc802419919997206531dffa0ef42f615ea49001a3fb40b
|
data/config/default.yml
CHANGED
|
@@ -27,6 +27,10 @@ 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
|
+
|
|
30
34
|
RBS/Layout/CommentIndentation:
|
|
31
35
|
Description: 'Use 2 spaces for comment indentation'
|
|
32
36
|
Enabled: true
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
|
@@ -21,45 +21,47 @@ 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
|
-
|
|
27
|
-
walk_decl(decl) do |d|
|
|
28
|
-
indent_start_lines << d.location.start_line
|
|
29
|
-
indent_end_lines << d.location.end_line
|
|
30
|
-
end
|
|
24
|
+
comments = processed_rbs_source.tokens.select { |token| token.type == :tLINECOMMENT }
|
|
25
|
+
comments.each_with_index do |token, comment_index|
|
|
26
|
+
check(token, comment_index)
|
|
31
27
|
end
|
|
28
|
+
end
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
next unless indent_start_lines.include?(token.location.start_line)
|
|
30
|
+
def check(comment_token, _comment_index)
|
|
31
|
+
next_line = line_after_comment(comment_token)
|
|
32
|
+
correct_comment_indentation = correct_indentation(next_line)
|
|
33
|
+
column = comment_token.location.start_column
|
|
38
34
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
next unless indent_end_lines.include?(token.location.start_line)
|
|
35
|
+
column_delta = correct_comment_indentation - column
|
|
36
|
+
return if column_delta.zero?
|
|
42
37
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
38
|
+
token_range = location_to_range(comment_token.location)
|
|
39
|
+
message = format(MSG, expect: correct_comment_indentation, actual: column)
|
|
40
|
+
add_offense(token_range, message: message) do |corrector|
|
|
41
|
+
line_start_pos = processed_source.buffer.line_range(comment_token.location.start_line).begin_pos
|
|
42
|
+
indent = range_between(line_start_pos, comment_token.location.start_pos)
|
|
43
|
+
corrector.replace(indent, ' ' * correct_comment_indentation)
|
|
55
44
|
end
|
|
56
45
|
end
|
|
57
46
|
|
|
58
|
-
def
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
47
|
+
def line_after_comment(comment)
|
|
48
|
+
lines = processed_source.lines
|
|
49
|
+
lines[comment.location.start_line..].find { |line| !line.blank? }
|
|
50
|
+
end
|
|
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)
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
67
|
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..send_line - 2].reverse.find { |line| !comment_line?(line) }
|
|
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)
|
|
@@ -14,8 +14,15 @@ 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
|
+
|
|
17
23
|
def on_rbs_def(decl)
|
|
18
24
|
decl.overloads.each do |overload|
|
|
25
|
+
check_type_params(overload.method_type)
|
|
19
26
|
overload.method_type.each_type do |type|
|
|
20
27
|
check_type(type)
|
|
21
28
|
end
|
|
@@ -26,10 +33,14 @@ module RuboCop
|
|
|
26
33
|
check_type(decl.type)
|
|
27
34
|
end
|
|
28
35
|
alias on_rbs_global on_rbs_constant
|
|
29
|
-
alias on_rbs_type_alias on_rbs_constant
|
|
30
36
|
alias on_rbs_attribute on_rbs_constant
|
|
31
37
|
alias on_rbs_var on_rbs_constant
|
|
32
38
|
|
|
39
|
+
def on_rbs_type_alias(decl)
|
|
40
|
+
check_type_params(decl)
|
|
41
|
+
check_type(decl.type)
|
|
42
|
+
end
|
|
43
|
+
|
|
33
44
|
def check_type(type)
|
|
34
45
|
case type
|
|
35
46
|
when ::RBS::Types::Union
|
|
@@ -42,6 +53,13 @@ module RuboCop
|
|
|
42
53
|
end
|
|
43
54
|
end
|
|
44
55
|
|
|
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
|
+
|
|
45
63
|
def check_operator(type, operator)
|
|
46
64
|
type.types.each_cons(2) do |before, after|
|
|
47
65
|
next unless before.location.end_line == after.location.start_line
|
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: 1.
|
|
4
|
+
version: 1.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ksss
|
|
@@ -84,6 +84,7 @@ 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
|
|
87
88
|
- lib/rubocop/cop/rbs/layout/comment_indentation.rb
|
|
88
89
|
- lib/rubocop/cop/rbs/layout/empty_line_between_declarations.rb
|
|
89
90
|
- lib/rubocop/cop/rbs/layout/empty_lines.rb
|
|
@@ -159,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
159
160
|
- !ruby/object:Gem::Version
|
|
160
161
|
version: '0'
|
|
161
162
|
requirements: []
|
|
162
|
-
rubygems_version:
|
|
163
|
+
rubygems_version: 4.0.3
|
|
163
164
|
specification_version: 4
|
|
164
165
|
summary: RuboCop extension for RBS file.
|
|
165
166
|
test_files: []
|