rubocop-on-rbs 1.0.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f5b6281c999414ec9c0c147ae2f49e1eb89374b7b159319ae867248305e87be
4
- data.tar.gz: dfe65d9221973785fdf15d78fd011e3f3b27410ae329f6830f3f9074f04dc2fe
3
+ metadata.gz: 501f65e78ff030f4d111a08793afa70a614c28715e9d9fa4caa95e24bbcc48dd
4
+ data.tar.gz: 5600ce340c99239465721d201d75881e3bcd8343787659bbf18faaaf8f51f58f
5
5
  SHA512:
6
- metadata.gz: 2e3828108b1e14abbbc491f19bb4b9d96211e46449e536ecd64a4b1d2310933e91f5b12ee8ad06b6ffd1dbf45134c2f87d1836868d9a5885072a47fa16018042
7
- data.tar.gz: 174bf5a55e04b90c63c0e5d2c3b7164c4be900dd547214e12e67e376077f7c06b6e7c41ee206bfa4f77fe1af59119663f5a85732b6f38241b58467d79252303f
6
+ metadata.gz: 9506a4022805eeaabedd6de962bc91812f34176e40251cb902b4abaee2a5b7fc45dd962946032dcf5cedea397f88daec6d46cae9e54ccc8d9c3f35a6b9941b15
7
+ data.tar.gz: 3b0176a6d2aa9fc2a85c21445720b9571e8881d6cd742c9b1b534ca76ff5103bc340e38a417e0bf6aec32259b5818aa24872553bdff3e6e47096eba19291cc9f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.1.0] - 2024-10-01
4
+
5
+ * Add RBS/Layout/EmptyLinesAroundAccessModifier by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/39
6
+ * Fix error when same line with `RBS/Layout/EndAlignment` by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/40
7
+
8
+ ## [1.0.0] - 2024-09-17
9
+
10
+ * Add RBS/Layout/EmptyLines by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/35
11
+ * Fix doc for EmptyLinesAroundOverloads by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/36
12
+ * Add Layout/EmptyLinesAround{Class,Module}Body by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/37
13
+ * Add RBS/Layout/EmptyLinesAroundInterfaceBody by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/38
14
+
15
+ ## [0.9.0] - 2024-08-07
16
+
17
+ * Fix error if includes multibyte characters by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/31
18
+
19
+ ## [0.8.0] - 2024-08-06
20
+
21
+ * Fix use of argument in upper_bound by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/24
22
+ * Security update by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/29
23
+
3
24
  ## [0.7.0] - 2024-06-27
4
25
 
5
26
  * Add RBS/Lint/AmbiguousOperatorPrecedence by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/22
data/config/default.yml CHANGED
@@ -31,6 +31,10 @@ RBS/Layout/CommentIndentation:
31
31
  Description: 'Use 2 spaces for comment indentation'
32
32
  Enabled: true
33
33
 
34
+ RBS/Layout/EmptyLinesAroundAccessModifier:
35
+ Description: "Keeps track of empty lines around access modifiers."
36
+ Enabled: true
37
+
34
38
  RBS/Layout/EmptyLinesAroundClassBody:
35
39
  Description: "Keeps track of empty lines around class bodies."
36
40
  Enabled: true
@@ -114,6 +118,16 @@ RBS/Lint/Syntax:
114
118
  Description: 'Check RBS syntax'
115
119
  Enabled: true
116
120
 
121
+ RBS/Lint/TopLevelInterface:
122
+ Description: 'Check top level interface'
123
+ Enabled: pending
124
+ VersionAdded: '1.2.0'
125
+
126
+ RBS/Lint/TopLevelTypeAlias:
127
+ Description: 'Check top level type alias'
128
+ Enabled: pending
129
+ VersionAdded: '1.2.0'
130
+
117
131
  RBS/Lint/UselessAccessModifier:
118
132
  AutoCorrect: contextual
119
133
  Description: 'Check useless access modifier'
@@ -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
@@ -12,6 +12,7 @@ module RuboCop
12
12
  def check(decl)
13
13
  first_line = decl.location.start_line
14
14
  last_line = decl.location.end_line
15
+ return if last_line == first_line
15
16
 
16
17
  check_beginning(first_line)
17
18
  check_ending(last_line)
@@ -29,7 +30,6 @@ module RuboCop
29
30
  return unless line_no.positive?
30
31
  return unless processed_source.lines[line_no]
31
32
  return unless processed_source.lines[line_no].empty?
32
- return unless processed_source.lines[line_no + 1]
33
33
 
34
34
  range = source_range(processed_source.buffer, line_no + 1, 0)
35
35
  message = message(MSG_EXTRA, desc)
@@ -34,6 +34,8 @@ module RuboCop
34
34
  end
35
35
 
36
36
  def check(decl, expect:)
37
+ return if decl.location.start_line == decl.location.end_line
38
+
37
39
  end_loc = decl.location[:end]
38
40
  actual = end_loc.start_column
39
41
  if actual != expect
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module RBS
6
6
  module Lint
7
- # Checks that there are no repeated overload bodies
7
+ # Checks for ambiguity of Union and Intersection operators.
8
8
  #
9
9
  # @example default
10
10
  # # bad
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RBS
6
+ module Lint
7
+ # Top-level namespaces are likely to conflict and should be avoided.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # interface _Option
12
+ # def option: () -> untyped
13
+ # end
14
+ #
15
+ # # good
16
+ # class Foo
17
+ # interface _Option
18
+ # def option: () -> untyped
19
+ # end
20
+ # end
21
+ #
22
+ class TopLevelInterface < RuboCop::RBS::CopBase
23
+ MSG = 'Top level interface detected.'
24
+
25
+ def on_rbs_new_investigation
26
+ @last_end = nil
27
+ end
28
+
29
+ def on_rbs_class(decl)
30
+ return unless @last_end_pos.nil? || (@last_end_pos < decl.location.end_pos)
31
+
32
+ @last_end_pos = decl.location.end_pos
33
+ end
34
+ alias on_rbs_module on_rbs_class
35
+
36
+ def on_rbs_interface(decl)
37
+ return unless @last_end_pos.nil? || (@last_end_pos < decl.location.start_pos)
38
+
39
+ range = location_to_range(decl.location)
40
+ add_offense(range)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RBS
6
+ module Lint
7
+ # Top-level namespaces are likely to conflict and should be avoided.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # type foo = String
12
+ #
13
+ # # good
14
+ # class Foo
15
+ # type bar = Integer
16
+ # end
17
+ #
18
+ class TopLevelTypeAlias < RuboCop::RBS::CopBase
19
+ MSG = 'Top level type alias detected.'
20
+
21
+ def on_rbs_new_investigation
22
+ @last_end = nil
23
+ end
24
+
25
+ def on_rbs_class(decl)
26
+ return unless @last_end_pos.nil? || (@last_end_pos < decl.location.end_pos)
27
+
28
+ @last_end_pos = decl.location.end_pos
29
+ end
30
+ alias on_rbs_module on_rbs_class
31
+ alias on_rbs_interface on_rbs_class
32
+
33
+ def on_rbs_type_alias(decl)
34
+ return unless @last_end_pos.nil? || (@last_end_pos < decl.location.start_pos)
35
+
36
+ range = location_to_range(decl.location)
37
+ add_offense(range)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -3,6 +3,7 @@
3
3
  require 'rbs'
4
4
 
5
5
  require_relative 'rbs/layout/comment_indentation'
6
+ require_relative 'rbs/layout/empty_lines_around_access_modifier'
6
7
  require_relative 'rbs/layout/empty_lines_around_body'
7
8
  require_relative 'rbs/layout/empty_lines_around_class_body'
8
9
  require_relative 'rbs/layout/empty_lines_around_interface_body'
@@ -24,6 +25,8 @@ require_relative 'rbs/lint/ambiguous_operator_precedence'
24
25
  require_relative 'rbs/lint/duplicate_overload'
25
26
  require_relative 'rbs/lint/literal_intersection'
26
27
  require_relative 'rbs/lint/syntax'
28
+ require_relative 'rbs/lint/top_level_interface'
29
+ require_relative 'rbs/lint/top_level_type_alias'
27
30
  require_relative 'rbs/lint/useless_access_modifier'
28
31
  require_relative 'rbs/lint/useless_overload_type_params'
29
32
  require_relative 'rbs/lint/will_syntax_error'
@@ -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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module RBS
5
- VERSION = '1.0.0'
5
+ VERSION = '1.2.0'
6
6
  end
7
7
  end
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: 1.0.0
4
+ version: 1.2.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-09-17 00:00:00.000000000 Z
11
+ date: 2024-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs
@@ -67,6 +67,7 @@ files:
67
67
  - lib/rubocop-on-rbs.rb
68
68
  - lib/rubocop/cop/rbs/layout/comment_indentation.rb
69
69
  - lib/rubocop/cop/rbs/layout/empty_lines.rb
70
+ - lib/rubocop/cop/rbs/layout/empty_lines_around_access_modifier.rb
70
71
  - lib/rubocop/cop/rbs/layout/empty_lines_around_body.rb
71
72
  - lib/rubocop/cop/rbs/layout/empty_lines_around_class_body.rb
72
73
  - lib/rubocop/cop/rbs/layout/empty_lines_around_interface_body.rb
@@ -86,6 +87,8 @@ files:
86
87
  - lib/rubocop/cop/rbs/lint/duplicate_overload.rb
87
88
  - lib/rubocop/cop/rbs/lint/literal_intersection.rb
88
89
  - lib/rubocop/cop/rbs/lint/syntax.rb
90
+ - lib/rubocop/cop/rbs/lint/top_level_interface.rb
91
+ - lib/rubocop/cop/rbs/lint/top_level_type_alias.rb
89
92
  - lib/rubocop/cop/rbs/lint/useless_access_modifier.rb
90
93
  - lib/rubocop/cop/rbs/lint/useless_overload_type_params.rb
91
94
  - lib/rubocop/cop/rbs/lint/will_syntax_error.rb
@@ -127,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
130
  - !ruby/object:Gem::Version
128
131
  version: '0'
129
132
  requirements: []
130
- rubygems_version: 3.5.11
133
+ rubygems_version: 3.5.16
131
134
  signing_key:
132
135
  specification_version: 4
133
136
  summary: RuboCop extension for RBS file.