rubocop-fourshark 0.11.2 → 0.12.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: ff1f92dab1c4c499529e7729afcfe28e449879582f476e2a911952ec3140f8df
4
- data.tar.gz: 17f2ab8e91dd9392f74bc0cf333dcf58b54b847e67bd05224ad4394857b583b8
3
+ metadata.gz: 2e6ff1114154e4093f52449659fb89bd30418cfcf6057a2175d38a97898e1ef7
4
+ data.tar.gz: a487773631597cee69880424b2c137f7c201e580e67b73eb44d79e1cd1be0dab
5
5
  SHA512:
6
- metadata.gz: ad46dc84d1c4930addcb691f17b405685d684eaaa2fe12eb45353ce366ad352e9bc2c79ed65bc9e5b8da4c94579bebcaba65e1170ac809df467dde62d69c8196
7
- data.tar.gz: f7a40f52df08988e967789e44bd7d74271a9074e14819bfc3e3c315afb7b07a6c0fdc9bba256a021b579c480158956aec9ef5066ba05c5210463d0c53fd1695d
6
+ metadata.gz: 2b23d8a3fc8cc19fe27f04b371ee824ae9688c26a1b0938bc47e0ec47421215913772562f0cc005ed4db3bf6121e37a999e4aa8b5a2116971b31d676ef516e37
7
+ data.tar.gz: d051ae90d627a60471da2ffaf31e7cc031c05027de6b9272db3c6e00fac9027d2efa44c09b4e75a06866ca28015183d4cf096d0248b185eee8e21c1dd079e756
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [0.12.0] - 2026-10-07
2
+
3
+ ### Changed
4
+
5
+ - Bump Dependencies
6
+
7
+ ### Fixed
8
+
9
+ - `Style/OrderedConstants` — a constant that references one declared above it is no longer flagged
10
+
1
11
  ## [0.11.2] - 2026-10-07
2
12
 
3
13
  ### Added
@@ -7,9 +7,10 @@ module RuboCop
7
7
  module Style
8
8
  # Requires a run of consecutive constant assignments to be sorted
9
9
  # alphabetically by name. A lone constant is never flagged; a run is
10
- # broken by any non-constant statement. Flags without autocorrecting — a
11
- # constant may reference one declared above it, so a human decides the
12
- # order. Experimental: if it flags more than it helps, drop it.
10
+ # broken by any non-constant statement. A constant whose value references
11
+ # one declared above it in the run is not flagged, since Ruby cannot load
12
+ # it any earlier. Flags without autocorrecting. Experimental: if it flags
13
+ # more than it helps, drop it.
13
14
  class OrderedConstants < ::RuboCop::Cop::Base
14
15
  MSG = 'Sort constant assignments alphabetically (`%<name>s` should come before `%<previous>s`).'
15
16
 
@@ -22,16 +23,25 @@ module RuboCop
22
23
  private
23
24
 
24
25
  def flag_unsorted(run)
25
- run.each_cons(2) do |previous, current|
26
+ run.each_cons(2).with_index do |(previous, current), index|
26
27
  previous_name = constant_name(previous)
27
28
  current_name = constant_name(current)
28
29
 
29
30
  next if current_name >= previous_name
31
+ next if references_earlier_constant?(current, run.first(index + 1))
30
32
 
31
33
  add_offense(current.loc.name, message: format(MSG, name: current_name, previous: previous_name))
32
34
  end
33
35
  end
34
36
 
37
+ def references_earlier_constant?(node, earlier_constants)
38
+ earlier_names = earlier_constants.map { |constant| constant_name(constant) }
39
+
40
+ node.expression.each_node(:const).any? do |reference|
41
+ reference.namespace.nil? && earlier_names.include?(reference.short_name.to_s)
42
+ end
43
+ end
44
+
35
45
  def constant_assignment?(node)
36
46
  node.is_a?(::RuboCop::AST::Node) && node.casgn_type?
37
47
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Fourshark
5
- VERSION = '0.11.2'
5
+ VERSION = '0.12.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-fourshark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Ribeiro