rubocop-on-rbs 0.8.0 → 1.0.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: 4d260d64881cb68a460632386ff5707ab99717fd56b2ac7ff1824a1cbc55680e
4
- data.tar.gz: 353ef7d2b3b583d65880995d4eac7e72cca2f591953a747a826a2c0e55152601
3
+ metadata.gz: 8f5b6281c999414ec9c0c147ae2f49e1eb89374b7b159319ae867248305e87be
4
+ data.tar.gz: dfe65d9221973785fdf15d78fd011e3f3b27410ae329f6830f3f9074f04dc2fe
5
5
  SHA512:
6
- metadata.gz: a77a462af68842c31f3cea245770215819515062faeaf24b6ef5f2d9c87ba0544dbf07f9cd6abc728955d4a67b77fa595baaad3e92c2f3fa7bfb780954a9018b
7
- data.tar.gz: 496f22af11da44e34c72c558738a86f1eda45c3afeba5b629d893cf2be6f665b3f477bc8189e32d78e49d5da49e2ce868ce6ab87f4b2652fc4e80fca71764dc4
6
+ metadata.gz: 2e3828108b1e14abbbc491f19bb4b9d96211e46449e536ecd64a4b1d2310933e91f5b12ee8ad06b6ffd1dbf45134c2f87d1836868d9a5885072a47fa16018042
7
+ data.tar.gz: 174bf5a55e04b90c63c0e5d2c3b7164c4be900dd547214e12e67e376077f7c06b6e7c41ee206bfa4f77fe1af59119663f5a85732b6f38241b58467d79252303f
data/config/default.yml CHANGED
@@ -31,10 +31,26 @@ RBS/Layout/CommentIndentation:
31
31
  Description: 'Use 2 spaces for comment indentation'
32
32
  Enabled: true
33
33
 
34
- RBS/Layout/EmptyLineAroundOverloads:
34
+ RBS/Layout/EmptyLinesAroundClassBody:
35
+ Description: "Keeps track of empty lines around class bodies."
36
+ Enabled: true
37
+
38
+ RBS/Layout/EmptyLinesAroundInterfaceBody:
39
+ Description: "Keeps track of empty lines around interface bodies."
40
+ Enabled: true
41
+
42
+ RBS/Layout/EmptyLinesAroundModuleBody:
43
+ Description: "Keeps track of empty lines around module bodies."
44
+ Enabled: true
45
+
46
+ RBS/Layout/EmptyLinesAroundOverloads:
35
47
  Description: 'No empty line between overload'
36
48
  Enabled: true
37
49
 
50
+ RBS/Layout/EmptyLines:
51
+ Description: "Don't use several empty lines in a row."
52
+ Enabled: true
53
+
38
54
  RBS/Layout/EndAlignment:
39
55
  Description: 'Align `end` keyword'
40
56
  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,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
- # class Foo
10
- # def foo: () -> void
11
- # end
9
+ # def foo: () -> void
10
+ #
11
+ # | (Integer) -> Integer
12
12
  #
13
13
  # # good
14
- # class Foo
15
- # def foo: () -> void
16
- # end
14
+ # def foo: () -> void
15
+ # | (Integer) -> Integer
17
16
  class EmptyLinesAroundOverloads < RuboCop::RBS::CopBase
18
17
  extend AutoCorrector
19
18
 
@@ -22,13 +22,13 @@ module RuboCop
22
22
  def on_rbs_new_investigation
23
23
  total = 0
24
24
  processed_source.raw_source.each_line do |line|
25
- total += line.bytesize
25
+ total += line.length
26
26
  chomped = line.chomp
27
27
  next unless chomped.end_with?(' ', "\t")
28
28
 
29
29
  range = range_between(
30
- total - line.bytesize + chomped.rstrip.bytesize,
31
- total - line.bytesize + chomped.bytesize,
30
+ total - line.length + chomped.rstrip.length,
31
+ total - line.length + chomped.length,
32
32
  )
33
33
  add_offense(range) do |corrector|
34
34
  corrector.remove(range)
@@ -3,7 +3,12 @@
3
3
  require 'rbs'
4
4
 
5
5
  require_relative 'rbs/layout/comment_indentation'
6
+ require_relative 'rbs/layout/empty_lines_around_body'
7
+ require_relative 'rbs/layout/empty_lines_around_class_body'
8
+ require_relative 'rbs/layout/empty_lines_around_interface_body'
9
+ require_relative 'rbs/layout/empty_lines_around_module_body'
6
10
  require_relative 'rbs/layout/empty_lines_around_overloads'
11
+ require_relative 'rbs/layout/empty_lines'
7
12
  require_relative 'rbs/layout/end_alignment'
8
13
  require_relative 'rbs/layout/extra_spacing'
9
14
  require_relative 'rbs/layout/indentation_width'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module RBS
5
- VERSION = '0.8.0'
5
+ VERSION = '1.0.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: 0.8.0
4
+ version: 1.0.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-08-06 00:00:00.000000000 Z
11
+ date: 2024-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs
@@ -66,6 +66,11 @@ 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_body.rb
71
+ - lib/rubocop/cop/rbs/layout/empty_lines_around_class_body.rb
72
+ - lib/rubocop/cop/rbs/layout/empty_lines_around_interface_body.rb
73
+ - lib/rubocop/cop/rbs/layout/empty_lines_around_module_body.rb
69
74
  - lib/rubocop/cop/rbs/layout/empty_lines_around_overloads.rb
70
75
  - lib/rubocop/cop/rbs/layout/end_alignment.rb
71
76
  - lib/rubocop/cop/rbs/layout/extra_spacing.rb