barsoom_utils 0.3.0.82 → 0.3.0.84
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/VERSION +1 -1
- data/lib/barsoom_utils/rubocop.rb +1 -0
- data/lib/rubocop/cop/barsoom/attr_extras_initialize.rb +2 -2
- data/lib/rubocop/cop/barsoom/inline_private_class_method.rb +1 -1
- data/lib/rubocop/cop/barsoom/space_inside_percent_literal_delimiters.rb +45 -0
- data/shared_rubocop.yml +4 -0
- data/spec/rubocop/cop/barsoom/space_inside_percent_literal_delimiters_spec.rb +58 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a17821003c2a66932a782d681677fd072f6877a59721b2202a4df8f0eaeb5037
|
|
4
|
+
data.tar.gz: 86b0f1dc0a38793fd819e70ead45898e522d4ab13cc00c845b09224a2fa2c882
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 128e1465550c40cf9afe0d371cf72c009f9158e81114ab452c7d597e2b398bdc6cf189e690e86c00edd9ddad23a1b970e2ade65b75847f106b87dfa44ba858c1
|
|
7
|
+
data.tar.gz: bf33b33b7b9c858fc9d7d5dcf2ac7e00743cafb5bba062a35759e55a587512a6e943cc94e4628e6041307d33e3cf25548c86688c780500cbb942622cae03a3e8
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.3.0.
|
|
1
|
+
0.3.0.84
|
|
@@ -19,8 +19,8 @@ module RuboCop
|
|
|
19
19
|
# pattr_initialize :user, [ :notify! ]
|
|
20
20
|
class AttrExtrasInitialize < Base
|
|
21
21
|
MSG = "Use attr_extras, e.g. `pattr_initialize`, instead of an `initialize` that only assigns its arguments."
|
|
22
|
-
SUPPORTED_ARGUMENT_TYPES = %i[arg kwarg kwoptarg].freeze
|
|
23
|
-
IMMUTABLE_DEFAULT_TYPES = %i[nil true false sym int float].freeze
|
|
22
|
+
SUPPORTED_ARGUMENT_TYPES = %i[ arg kwarg kwoptarg ].freeze
|
|
23
|
+
IMMUTABLE_DEFAULT_TYPES = %i[ nil true false sym int float ].freeze
|
|
24
24
|
|
|
25
25
|
requires_gem "attr_extras"
|
|
26
26
|
|
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
|
22
22
|
extend AutoCorrector
|
|
23
23
|
|
|
24
24
|
MSG = "Use `private_class_method \\` before each `def self.` instead of listing the methods by name."
|
|
25
|
-
RESTRICT_ON_SEND = %i[private_class_method].freeze
|
|
25
|
+
RESTRICT_ON_SEND = %i[ private_class_method ].freeze
|
|
26
26
|
|
|
27
27
|
def on_send(node)
|
|
28
28
|
return if node.receiver || node.arguments.empty? || !node.arguments.all?(&:sym_type?)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module RuboCop
|
|
3
|
+
module Cop
|
|
4
|
+
module Barsoom
|
|
5
|
+
# Checks for one space inside the delimiters of single-line array percent literals, matching the `[ a, b ]` style of `Layout/SpaceInsideArrayLiteralBrackets`.
|
|
6
|
+
#
|
|
7
|
+
# Empty and multi-line literals are accepted.
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
# # bad
|
|
11
|
+
# %w[da de en]
|
|
12
|
+
# %i[ foo bar ]
|
|
13
|
+
#
|
|
14
|
+
# # good
|
|
15
|
+
# %w[ da de en ]
|
|
16
|
+
# %i[ foo bar ]
|
|
17
|
+
# %w[]
|
|
18
|
+
class SpaceInsidePercentLiteralDelimiters < Base
|
|
19
|
+
extend AutoCorrector
|
|
20
|
+
|
|
21
|
+
MSG = "Use one space inside percent literal delimiters."
|
|
22
|
+
|
|
23
|
+
def on_array(node)
|
|
24
|
+
return unless node.percent_literal? && node.single_line?
|
|
25
|
+
|
|
26
|
+
body = node.source_range.with(begin_pos: node.loc.begin.end_pos, end_pos: node.loc.end.begin_pos)
|
|
27
|
+
source = body.source
|
|
28
|
+
return if source.strip.empty?
|
|
29
|
+
|
|
30
|
+
leading = source[/\A */].length
|
|
31
|
+
trailing = source[/ *\z/].length
|
|
32
|
+
|
|
33
|
+
# In e.g. `%w[a\ ]`, the escaped space belongs to the element.
|
|
34
|
+
trailing -= 1 if trailing.positive? && source[...-trailing][/\\*\z/].length.odd?
|
|
35
|
+
|
|
36
|
+
return if leading == 1 && trailing == 1
|
|
37
|
+
|
|
38
|
+
add_offense(body) do |corrector|
|
|
39
|
+
corrector.replace(body, " #{source[leading...(source.length - trailing)]} ")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/shared_rubocop.yml
CHANGED
|
@@ -394,3 +394,7 @@ Barsoom/AttrExtrasInitialize:
|
|
|
394
394
|
# Allow e.g. `private_class_method \` before `def self.parse` and disallow `private_class_method :parse` further down.
|
|
395
395
|
Barsoom/InlinePrivateClassMethod:
|
|
396
396
|
Enabled: true
|
|
397
|
+
|
|
398
|
+
# Allow e.g. `%w[ a b ]` and disallow `%w[a b]`, matching our `[ a, b ]` array format for this array-producing syntax.
|
|
399
|
+
Barsoom/SpaceInsidePercentLiteralDelimiters:
|
|
400
|
+
Enabled: true
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require "rubocop_helper"
|
|
3
|
+
|
|
4
|
+
RSpec.describe RuboCop::Cop::Barsoom::SpaceInsidePercentLiteralDelimiters, :config do
|
|
5
|
+
let(:ruby_version) { 3.4 }
|
|
6
|
+
|
|
7
|
+
it "registers an offense for missing spaces, and adds them" do
|
|
8
|
+
expect_offense(<<~'RUBY')
|
|
9
|
+
%w[da de en]
|
|
10
|
+
^^^^^^^^ Use one space inside percent literal delimiters.
|
|
11
|
+
%I[#{foo} bar]
|
|
12
|
+
^^^^^^^^^^ Use one space inside percent literal delimiters.
|
|
13
|
+
RUBY
|
|
14
|
+
|
|
15
|
+
expect_correction(<<~'RUBY')
|
|
16
|
+
%w[ da de en ]
|
|
17
|
+
%I[ #{foo} bar ]
|
|
18
|
+
RUBY
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "registers an offense for extra or one-sided spaces, and evens them out" do
|
|
22
|
+
expect_offense(<<~RUBY)
|
|
23
|
+
%i[ foo bar ]
|
|
24
|
+
^^^^^^^^^^^ Use one space inside percent literal delimiters.
|
|
25
|
+
%i[foo bar ]
|
|
26
|
+
^^^^^^^^ Use one space inside percent literal delimiters.
|
|
27
|
+
RUBY
|
|
28
|
+
|
|
29
|
+
expect_correction(<<~RUBY)
|
|
30
|
+
%i[ foo bar ]
|
|
31
|
+
%i[ foo bar ]
|
|
32
|
+
RUBY
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "keeps an escaped space at the end as part of the last element" do
|
|
36
|
+
expect_offense(<<~'RUBY')
|
|
37
|
+
%w[a b\ ]
|
|
38
|
+
^^^^^ Use one space inside percent literal delimiters.
|
|
39
|
+
RUBY
|
|
40
|
+
|
|
41
|
+
expect_correction(<<~'RUBY')
|
|
42
|
+
%w[ a b\ ]
|
|
43
|
+
RUBY
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "accepts one space, empty and multi-line literals, and regular arrays" do
|
|
47
|
+
expect_no_offenses(<<~RUBY)
|
|
48
|
+
%w[ da de en ]
|
|
49
|
+
%w( da de en )
|
|
50
|
+
%w[]
|
|
51
|
+
%w[
|
|
52
|
+
da
|
|
53
|
+
de
|
|
54
|
+
]
|
|
55
|
+
[ 1, 2 ]
|
|
56
|
+
RUBY
|
|
57
|
+
end
|
|
58
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: barsoom_utils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.0.
|
|
4
|
+
version: 0.3.0.84
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tomas Skogberg
|
|
@@ -34,6 +34,7 @@ files:
|
|
|
34
34
|
- lib/barsoom_utils/version.rb
|
|
35
35
|
- lib/rubocop/cop/barsoom/attr_extras_initialize.rb
|
|
36
36
|
- lib/rubocop/cop/barsoom/inline_private_class_method.rb
|
|
37
|
+
- lib/rubocop/cop/barsoom/space_inside_percent_literal_delimiters.rb
|
|
37
38
|
- script/test
|
|
38
39
|
- shared_rubocop.yml
|
|
39
40
|
- shared_rubocop_rails.yml
|
|
@@ -41,6 +42,7 @@ files:
|
|
|
41
42
|
- spec/feature_toggle_spec.rb
|
|
42
43
|
- spec/rubocop/cop/barsoom/attr_extras_initialize_spec.rb
|
|
43
44
|
- spec/rubocop/cop/barsoom/inline_private_class_method_spec.rb
|
|
45
|
+
- spec/rubocop/cop/barsoom/space_inside_percent_literal_delimiters_spec.rb
|
|
44
46
|
- spec/rubocop_helper.rb
|
|
45
47
|
- spec/spec/debug_helpers_spec.rb
|
|
46
48
|
- spec/spec_helper.rb
|