sevencop 0.45.0 → 0.46.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +8 -6
- data/README.md +1 -0
- data/config/default.yml +10 -0
- data/lib/rubocop/cop/sevencop/bundler_gem_group_ordered.rb +87 -0
- data/lib/sevencop/version.rb +1 -1
- data/lib/sevencop.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f3da941ce26e523263ae349b642de04f08c6fafb25c65ee87a1552700336a59
|
4
|
+
data.tar.gz: 57c17da50da92c2fc735ea23b1acaf216885069afc651a14386a288ce93f400c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5b76d4613a1d575720c9aa07cc3253608ef19cd0cf9e7c25fedebbb8355d0af46a2701b3282147b4058646b4ef9123f7c39b34eb217a53cadd93a6947556fea
|
7
|
+
data.tar.gz: 139c3d03d5ed0441d78564bbe21e7037273bab082e72c47c530e631869f4654fbc070b31a6d82a194c76f98a27ac5c8db5170993a584bec0f4a0f87656c7e4f0
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sevencop (0.
|
4
|
+
sevencop (0.46.0)
|
5
5
|
activesupport
|
6
6
|
rubocop
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (7.2.
|
11
|
+
activesupport (7.2.2)
|
12
12
|
base64
|
13
|
+
benchmark (>= 0.3)
|
13
14
|
bigdecimal
|
14
15
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
15
16
|
connection_pool (>= 2.2.5)
|
@@ -21,17 +22,18 @@ GEM
|
|
21
22
|
tzinfo (~> 2.0, >= 2.0.5)
|
22
23
|
ast (2.4.2)
|
23
24
|
base64 (0.2.0)
|
25
|
+
benchmark (0.4.0)
|
24
26
|
bigdecimal (3.1.8)
|
25
27
|
concurrent-ruby (1.3.4)
|
26
28
|
connection_pool (2.4.1)
|
27
29
|
diff-lcs (1.5.1)
|
28
30
|
drb (2.2.1)
|
29
|
-
i18n (1.14.
|
31
|
+
i18n (1.14.6)
|
30
32
|
concurrent-ruby (~> 1.0)
|
31
33
|
json (2.7.2)
|
32
34
|
language_server-protocol (3.17.0.3)
|
33
|
-
logger (1.6.
|
34
|
-
minitest (5.25.
|
35
|
+
logger (1.6.2)
|
36
|
+
minitest (5.25.2)
|
35
37
|
parallel (1.26.3)
|
36
38
|
parser (3.3.5.0)
|
37
39
|
ast (~> 2.4.1)
|
@@ -73,7 +75,7 @@ GEM
|
|
73
75
|
rubocop-rspec (3.0.4)
|
74
76
|
rubocop (~> 1.61)
|
75
77
|
ruby-progressbar (1.13.0)
|
76
|
-
securerandom (0.
|
78
|
+
securerandom (0.4.0)
|
77
79
|
tzinfo (2.0.6)
|
78
80
|
concurrent-ruby (~> 1.0)
|
79
81
|
unicode-display_width (2.5.0)
|
data/README.md
CHANGED
@@ -29,6 +29,7 @@ Note that all cops are `Enabled: false` by default.
|
|
29
29
|
## Cops
|
30
30
|
|
31
31
|
- [Sevencop/AutoloadOrdered](lib/rubocop/cop/sevencop/autoload_ordered.rb)
|
32
|
+
- [Sevencop/BundlerGemGroupOrdered](lib/rubocop/cop/sevencop/bundler_gem_group_ordered.rb)
|
32
33
|
- [Sevencop/HashElementOrdered](lib/rubocop/cop/sevencop/hash_element_ordered.rb)
|
33
34
|
- [Sevencop/MapMethodChain](lib/rubocop/cop/sevencop/map_method_chain.rb)
|
34
35
|
- [Sevencop/MethodDefinitionArgumentsMultiline](lib/rubocop/cop/sevencop/method_definition_arguments_multiline.rb)
|
data/config/default.yml
CHANGED
@@ -4,6 +4,16 @@ Sevencop/AutoloadOrdered:
|
|
4
4
|
Enabled: false
|
5
5
|
Safe: false
|
6
6
|
|
7
|
+
Sevencop/BundlerGemGroupOrdered:
|
8
|
+
Description: |
|
9
|
+
Sort `group` in alphabetical order.
|
10
|
+
Enabled: false
|
11
|
+
Safe: false
|
12
|
+
Include:
|
13
|
+
- '**/*.gemfile'
|
14
|
+
- '**/Gemfile'
|
15
|
+
- '**/gems.rb'
|
16
|
+
|
7
17
|
Sevencop/HashElementOrdered:
|
8
18
|
Description: |
|
9
19
|
Sort Hash elements by key.
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Sevencop
|
6
|
+
# Sort `group` in alphabetical order.
|
7
|
+
#
|
8
|
+
# Note that the sort key is computed from the sorted and concatenated `group` arguments.
|
9
|
+
# For example, the sort key for `group :test, :development` is `development-test`.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# # bad
|
13
|
+
# group :test do
|
14
|
+
# gem 'rspec'
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# group :development do
|
18
|
+
# gem 'better_errors'
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# # good
|
22
|
+
# group :development do
|
23
|
+
# gem 'better_errors'
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# group :test do
|
27
|
+
# gem 'rspec'
|
28
|
+
# end
|
29
|
+
class BundlerGemGroupOrdered < Base
|
30
|
+
extend AutoCorrector
|
31
|
+
|
32
|
+
include RangeHelp
|
33
|
+
|
34
|
+
include ::Sevencop::CopConcerns::Ordered
|
35
|
+
|
36
|
+
MSG = 'Sort `group` in alphabetical order.'
|
37
|
+
|
38
|
+
RESTRICT_ON_SEND = %i[
|
39
|
+
group
|
40
|
+
].freeze
|
41
|
+
|
42
|
+
# @param [RuboCop::AST::SendNode] node
|
43
|
+
# @return [void]
|
44
|
+
def on_send(node)
|
45
|
+
block_node = node.block_node
|
46
|
+
return unless block_node
|
47
|
+
|
48
|
+
previous_older_sibling = find_previous_older_sibling(block_node)
|
49
|
+
return unless previous_older_sibling
|
50
|
+
|
51
|
+
add_offense(block_node) do |corrector|
|
52
|
+
corrector.swap(
|
53
|
+
range_with_comments_and_lines(previous_older_sibling),
|
54
|
+
range_with_comments_and_lines(block_node)
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# @param [RuboCop::AST::BlockNode] node
|
62
|
+
# @return [String, nil]
|
63
|
+
def calculate_sort_key(node)
|
64
|
+
return unless node.send_node.arguments.all? { |argument| argument.respond_to?(:value) }
|
65
|
+
|
66
|
+
node.send_node.arguments.map(&:value).sort.join('-')
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param [RuboCop::AST::BlockNode] node
|
70
|
+
# @return [RuboCop::AST::BlockNode, nil]
|
71
|
+
def find_previous_older_sibling(node)
|
72
|
+
node.left_siblings.grep(::RuboCop::AST::Node).reverse.find do |sibling|
|
73
|
+
break unless sibling.block_type?
|
74
|
+
break unless sibling.method?(:group)
|
75
|
+
|
76
|
+
current_sort_key = calculate_sort_key(node)
|
77
|
+
sibling_sort_key = calculate_sort_key(sibling)
|
78
|
+
break unless current_sort_key
|
79
|
+
break unless sibling_sort_key
|
80
|
+
|
81
|
+
calculate_sort_key(node) < calculate_sort_key(sibling)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/sevencop/version.rb
CHANGED
data/lib/sevencop.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative 'sevencop/rubocop_extension'
|
|
5
5
|
require_relative 'sevencop/version'
|
6
6
|
|
7
7
|
require_relative 'rubocop/cop/sevencop/autoload_ordered'
|
8
|
+
require_relative 'rubocop/cop/sevencop/bundler_gem_group_ordered'
|
8
9
|
require_relative 'rubocop/cop/sevencop/hash_element_ordered'
|
9
10
|
require_relative 'rubocop/cop/sevencop/map_method_chain'
|
10
11
|
require_relative 'rubocop/cop/sevencop/method_definition_arguments_multiline'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sevencop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.46.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- config/default.yml
|
58
58
|
- data/reserved_words_mysql.txt
|
59
59
|
- lib/rubocop/cop/sevencop/autoload_ordered.rb
|
60
|
+
- lib/rubocop/cop/sevencop/bundler_gem_group_ordered.rb
|
60
61
|
- lib/rubocop/cop/sevencop/hash_element_ordered.rb
|
61
62
|
- lib/rubocop/cop/sevencop/map_method_chain.rb
|
62
63
|
- lib/rubocop/cop/sevencop/method_definition_arguments_multiline.rb
|