barsoom_utils 0.3.0.82 → 0.3.0.87

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: 1757860af2eca9a71fffa1fa0c47a42e572314816f4dcf02d752d60c713ace67
4
- data.tar.gz: 54eb7e03409786d5eb87c34affad0a363b2ac3d17ee19ec22c75c800fd171c6d
3
+ metadata.gz: a02d928edb9379ea59949efe3e710c4aaf1f867c0883e55613993ce5336fa3d4
4
+ data.tar.gz: 16eb4d51434cb817299d0253378bcea888f19dc4399550a257de1edb1bee4115
5
5
  SHA512:
6
- metadata.gz: 66619d39cab01f97f5da75ab364f6f5f215f1c7755683518e71fa5d91bd7c3c3689828e0088b2ee562b07cf891a852378e6ee5f1533e4ee6c40103cd28db2f25
7
- data.tar.gz: ae669cd31bb669333412b0ea3f1bb6ebca0c584ed602685acf750f32106716fddd412ac657335ba7fc5b0ca32aa20bc4a0d11770746bf0ea8eddef37ddc1908c
6
+ metadata.gz: 6fdf14056334b818e37957035a1bacf74f1404866b972adfabd17d3f2dd3077ba47e710f918a03dc824a6ddfda8e1019506855f1186b93432985984e4567fda6
7
+ data.tar.gz: bb74fc226d9033348fd53362a3a5fbc6450537dabb9ab0d370e34645b8ffd8cb1b05a61370563baaf33661fd343c821a363d2c0b515d9969e4acc18e5917ee3e
data/.rubocop.yml CHANGED
@@ -1 +1,7 @@
1
1
  inherit_from: "./shared_rubocop.yml"
2
+
3
+ Style/FrozenStringLiteralComment:
4
+ Enabled: true
5
+
6
+ Layout/EmptyLineAfterMagicComment:
7
+ Enabled: true
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  source "https://rubygems.org"
3
4
 
4
5
  # Specify your gem's dependencies in barsoom_utils.gemspec
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "rspec/core/rake_task"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0.82
1
+ 0.3.0.87
@@ -1,5 +1,6 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  lib = File.expand_path("lib", __dir__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
6
  require "barsoom_utils/version"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Notify devs about an exception without necessarily
3
4
  # letting it appear to the user as a 500 error.
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "attr_extras"
3
4
  require "redis"
4
5
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Custom cops, loaded by shared_rubocop.yml.
3
4
  require "rubocop"
4
5
  require_relative "../rubocop/cop/barsoom/attr_extras_initialize"
5
6
  require_relative "../rubocop/cop/barsoom/inline_private_class_method"
7
+ require_relative "../rubocop/cop/barsoom/space_inside_percent_literal_delimiters"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "lolcat"
3
4
 
4
5
  module BarsoomUtils
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module BarsoomUtils
3
4
  # Use SEMVER in VERSION, build number gets appended on release.
4
5
  VERSION = File.read(File.join(__dir__, "../../VERSION"))
data/lib/barsoom_utils.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "barsoom_utils/version"
3
4
 
4
5
  module BarsoomUtils
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module RuboCop
3
4
  module Cop
4
5
  module Barsoom
@@ -19,8 +20,8 @@ module RuboCop
19
20
  # pattr_initialize :user, [ :notify! ]
20
21
  class AttrExtrasInitialize < Base
21
22
  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
23
+ SUPPORTED_ARGUMENT_TYPES = %i[ arg kwarg kwoptarg ].freeze
24
+ IMMUTABLE_DEFAULT_TYPES = %i[ nil true false sym int float ].freeze
24
25
 
25
26
  requires_gem "attr_extras"
26
27
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module RuboCop
3
4
  module Cop
4
5
  module Barsoom
@@ -22,7 +23,7 @@ module RuboCop
22
23
  extend AutoCorrector
23
24
 
24
25
  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
26
+ RESTRICT_ON_SEND = %i[ private_class_method ].freeze
26
27
 
27
28
  def on_send(node)
28
29
  return if node.receiver || node.arguments.empty? || !node.arguments.all?(&:sym_type?)
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Barsoom
6
+ # Checks for one space inside the delimiters of single-line array percent literals, matching the `[ a, b ]` style of `Layout/SpaceInsideArrayLiteralBrackets`.
7
+ #
8
+ # Empty and multi-line literals are accepted.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # %w[da de en]
13
+ # %i[ foo bar ]
14
+ #
15
+ # # good
16
+ # %w[ da de en ]
17
+ # %i[ foo bar ]
18
+ # %w[]
19
+ class SpaceInsidePercentLiteralDelimiters < Base
20
+ extend AutoCorrector
21
+
22
+ MSG = "Use one space inside percent literal delimiters."
23
+
24
+ def on_array(node)
25
+ return unless node.percent_literal? && node.single_line?
26
+
27
+ body = node.source_range.with(begin_pos: node.loc.begin.end_pos, end_pos: node.loc.end.begin_pos)
28
+ source = body.source
29
+ return if source.strip.empty?
30
+
31
+ leading = source[/\A */].length
32
+ trailing = source[/ *\z/].length
33
+
34
+ # In e.g. `%w[a\ ]`, the escaped space belongs to the element.
35
+ trailing -= 1 if trailing.positive? && source[...-trailing][/\\*\z/].length.odd?
36
+
37
+ return if leading == 1 && trailing == 1
38
+
39
+ add_offense(body) do |corrector|
40
+ corrector.replace(body, " #{source[leading...(source.length - trailing)]} ")
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ 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
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "barsoom_utils/exception_notifier"
3
4
  require "sentry-ruby"
4
5
  require "fixme"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "barsoom_utils/feature_toggle"
3
4
 
4
5
  RSpec.describe BarsoomUtils::FeatureToggle, ".turn_on" do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "rubocop_helper"
3
4
 
4
5
  RSpec.describe RuboCop::Cop::Barsoom::AttrExtrasInitialize, :config do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "rubocop_helper"
3
4
 
4
5
  RSpec.describe RuboCop::Cop::Barsoom::InlinePrivateClassMethod, :config do
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop_helper"
4
+
5
+ RSpec.describe RuboCop::Cop::Barsoom::SpaceInsidePercentLiteralDelimiters, :config do
6
+ let(:ruby_version) { 3.4 }
7
+
8
+ it "registers an offense for missing spaces, and adds them" do
9
+ expect_offense(<<~'RUBY')
10
+ %w[da de en]
11
+ ^^^^^^^^ Use one space inside percent literal delimiters.
12
+ %I[#{foo} bar]
13
+ ^^^^^^^^^^ Use one space inside percent literal delimiters.
14
+ RUBY
15
+
16
+ expect_correction(<<~'RUBY')
17
+ %w[ da de en ]
18
+ %I[ #{foo} bar ]
19
+ RUBY
20
+ end
21
+
22
+ it "registers an offense for extra or one-sided spaces, and evens them out" do
23
+ expect_offense(<<~RUBY)
24
+ %i[ foo bar ]
25
+ ^^^^^^^^^^^ Use one space inside percent literal delimiters.
26
+ %i[foo bar ]
27
+ ^^^^^^^^ Use one space inside percent literal delimiters.
28
+ RUBY
29
+
30
+ expect_correction(<<~RUBY)
31
+ %i[ foo bar ]
32
+ %i[ foo bar ]
33
+ RUBY
34
+ end
35
+
36
+ it "keeps an escaped space at the end as part of the last element" do
37
+ expect_offense(<<~'RUBY')
38
+ %w[a b\ ]
39
+ ^^^^^ Use one space inside percent literal delimiters.
40
+ RUBY
41
+
42
+ expect_correction(<<~'RUBY')
43
+ %w[ a b\ ]
44
+ RUBY
45
+ end
46
+
47
+ it "accepts one space, empty and multi-line literals, and regular arrays" do
48
+ expect_no_offenses(<<~RUBY)
49
+ %w[ da de en ]
50
+ %w( da de en )
51
+ %w[]
52
+ %w[
53
+ da
54
+ de
55
+ ]
56
+ [ 1, 2 ]
57
+ RUBY
58
+ end
59
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "rubocop"
3
4
  require "rubocop/rspec/support"
4
5
  require "barsoom_utils/rubocop"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "barsoom_utils/spec/debug_helpers"
3
4
 
4
5
  RSpec.describe BarsoomUtils::Spec::DebugHelpers do
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  RSpec.configure do |config|
3
4
  config.disable_monkey_patching!
4
5
  config.order = "random"
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.82
4
+ version: 0.3.0.87
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