sevencop 0.11.1 → 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: f5145711881e4ff729c76af2973e3c7af5c4ad5d7a72318dc28ea4346b7530e0
4
- data.tar.gz: 3bade2432dfd3a659d4c689c005cc36c0ecb16da14dd99d338a815876ec8951f
3
+ metadata.gz: 2fc5d0adbf2ac9b5c3aa8ac43e1e375f82efa0906710ca38bd41c145c3a2bb41
4
+ data.tar.gz: fd8b73bcc7ea73410c6634a3dbd5fcb3b38f3af26570482b22a2d05b2f42f6b3
5
5
  SHA512:
6
- metadata.gz: 8011ea16ecaf3d1e8eb34156ca6b30f1f545d3d01406a4a1fa189b5cfb5bd74a4b0a6d177762c750023ac50c645e1ef8378028d44f4c710ea6744577fa7c5a64
7
- data.tar.gz: '0392eb84b36bff0120d79e637d84fa3d893935d10c4dfd5dbd004bacdff75bf524137dc38976705e69aaa6c420fe4ad01160b89c36a49bc6c764d8cccae4079c'
6
+ metadata.gz: 9024936b3ef659bae3242f40c793e72249edde9d6838f65edf570039077aad0abebe18ad8e2be52dad270ef4322bce2b841ffc33d42323a151b55b97d86cdc5a
7
+ data.tar.gz: 19450fde029f352c3bba68362bb8a0db0c2ec01ceb319702565083768d281613b9bd123b34345f1096350a6bd3eab7efdb89079cd0f63526406f8d6b0b404b9c
data/.rubocop.yml CHANGED
@@ -1,5 +1,8 @@
1
1
  require:
2
2
  - rubocop/cop/internal_affairs
3
+ - rubocop-performance
4
+ - rubocop-rake
5
+ - rubocop-rspec
3
6
 
4
7
  AllCops:
5
8
  NewCops: enable
@@ -9,5 +12,18 @@ AllCops:
9
12
  Metrics:
10
13
  Enabled: false
11
14
 
15
+ RSpec:
16
+ Language:
17
+ Expectations:
18
+ - expect_correction
19
+ - expect_no_offenses
20
+ - expect_offense
21
+
22
+ RSpec/ExampleLength:
23
+ Enabled: false
24
+
25
+ RSpec/MultipleExpectations:
26
+ Enabled: false
27
+
12
28
  Style/Documentation:
13
29
  Enabled: false
data/Gemfile CHANGED
@@ -5,6 +5,9 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in sevencop.gemspec
6
6
  gemspec
7
7
 
8
- gem 'rake', '~> 13.0'
9
- gem 'rspec', '~> 3.0'
10
- gem 'rubocop', '~> 1.21'
8
+ gem 'rake'
9
+ gem 'rspec'
10
+ gem 'rubocop'
11
+ gem 'rubocop-performance'
12
+ gem 'rubocop-rake'
13
+ gem 'rubocop-rspec'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.11.1)
4
+ sevencop (0.12.0)
5
5
  rubocop
6
6
 
7
7
  GEM
@@ -11,7 +11,7 @@ GEM
11
11
  diff-lcs (1.5.0)
12
12
  json (2.6.2)
13
13
  parallel (1.22.1)
14
- parser (3.1.2.0)
14
+ parser (3.1.2.1)
15
15
  ast (~> 2.4.1)
16
16
  rainbow (3.1.1)
17
17
  rake (13.0.6)
@@ -23,35 +23,45 @@ GEM
23
23
  rspec-mocks (~> 3.11.0)
24
24
  rspec-core (3.11.0)
25
25
  rspec-support (~> 3.11.0)
26
- rspec-expectations (3.11.0)
26
+ rspec-expectations (3.11.1)
27
27
  diff-lcs (>= 1.2.0, < 2.0)
28
28
  rspec-support (~> 3.11.0)
29
29
  rspec-mocks (3.11.1)
30
30
  diff-lcs (>= 1.2.0, < 2.0)
31
31
  rspec-support (~> 3.11.0)
32
- rspec-support (3.11.0)
33
- rubocop (1.31.2)
32
+ rspec-support (3.11.1)
33
+ rubocop (1.36.0)
34
34
  json (~> 2.3)
35
35
  parallel (~> 1.10)
36
- parser (>= 3.1.0.0)
36
+ parser (>= 3.1.2.1)
37
37
  rainbow (>= 2.2.2, < 4.0)
38
38
  regexp_parser (>= 1.8, < 3.0)
39
39
  rexml (>= 3.2.5, < 4.0)
40
- rubocop-ast (>= 1.18.0, < 2.0)
40
+ rubocop-ast (>= 1.20.1, < 2.0)
41
41
  ruby-progressbar (~> 1.7)
42
42
  unicode-display_width (>= 1.4.0, < 3.0)
43
- rubocop-ast (1.19.1)
43
+ rubocop-ast (1.21.0)
44
44
  parser (>= 3.1.1.0)
45
+ rubocop-performance (1.15.0)
46
+ rubocop (>= 1.7.0, < 2.0)
47
+ rubocop-ast (>= 0.4.0)
48
+ rubocop-rake (0.6.0)
49
+ rubocop (~> 1.0)
50
+ rubocop-rspec (2.13.1)
51
+ rubocop (~> 1.33)
45
52
  ruby-progressbar (1.11.0)
46
- unicode-display_width (2.2.0)
53
+ unicode-display_width (2.3.0)
47
54
 
48
55
  PLATFORMS
49
56
  x86_64-linux
50
57
 
51
58
  DEPENDENCIES
52
- rake (~> 13.0)
53
- rspec (~> 3.0)
54
- rubocop (~> 1.21)
59
+ rake
60
+ rspec
61
+ rubocop
62
+ rubocop-performance
63
+ rubocop-rake
64
+ rubocop-rspec
55
65
  sevencop!
56
66
 
57
67
  BUNDLED WITH
data/README.md CHANGED
@@ -47,6 +47,20 @@ Sevencop/BelongsToOptional:
47
47
 
48
48
  All cops are `Enabled: false` by default.
49
49
 
50
+ ### Sevencop/AutoloadOrdered
51
+
52
+ Sort `autoload` in alphabetical order.
53
+
54
+ ```ruby
55
+ # bad
56
+ autoload :B, 'b'
57
+ autoload :A, 'a'
58
+
59
+ # good
60
+ autoload :A, 'a'
61
+ autoload :B, 'b'
62
+ ```
63
+
50
64
  ### Sevencop/BelongsToOptional
51
65
 
52
66
  Force `belongs_to` with `optional: true` option.
data/config/default.yml CHANGED
@@ -1,3 +1,9 @@
1
+ Sevencop/AutoloadOrdered:
2
+ Description: |
3
+ Sort `autoload` in alphabetical order.
4
+ Enabled: false
5
+ VersionAdded: '0.12.0'
6
+
1
7
  Sevencop/BelongsToOptional:
2
8
  Description: |
3
9
  Force `belongs_to` with `optional: true` option.
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Sevencop
6
+ # Sort `autoload` in alphabetical order.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # autoload :B, 'b'
11
+ # autoload :A, 'a'
12
+ #
13
+ # # good
14
+ # autoload :A, 'a'
15
+ # autoload :B, 'b'
16
+ class AutoloadOrdered < Base
17
+ extend AutoCorrector
18
+
19
+ include RangeHelp
20
+
21
+ MSG = 'Sort `autoload` in alphabetical order.'
22
+
23
+ RESTRICT_ON_SEND = %i[
24
+ autoload
25
+ ].freeze
26
+
27
+ # @param node [RuboCop::AST::SendNode]
28
+ def on_send(node)
29
+ previous_older_autoload = find_previous_older_autoload(node)
30
+ return unless previous_older_autoload
31
+
32
+ add_offense(node) do |corrector|
33
+ swap(
34
+ range_by_whole_lines(
35
+ previous_older_autoload.location.expression,
36
+ include_final_newline: true
37
+ ),
38
+ range_by_whole_lines(
39
+ node.location.expression,
40
+ include_final_newline: true
41
+ ),
42
+ corrector: corrector
43
+ )
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ # @param node [RuboCop::AST::SendNode]
50
+ # @return [RuboCop::AST::SendNode]
51
+ def find_previous_older_autoload(node)
52
+ node.left_siblings.find do |sibling|
53
+ next unless sibling.send_type?
54
+ next unless sibling.method?(:autoload)
55
+
56
+ node.first_argument.source < sibling.first_argument.source
57
+ end
58
+ end
59
+
60
+ # @param range1 [Paresr::Source::Range]
61
+ # @param range2 [Paresr::Source::Range]
62
+ # @param corrector [RuboCop::AST::Corrector]
63
+ def swap(range1, range2, corrector:)
64
+ corrector.insert_before(range1, range2.source)
65
+ corrector.remove(range2)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -49,6 +49,7 @@ module RuboCop
49
49
  )
50
50
  end
51
51
  end
52
+ alias on_numblock on_block
52
53
 
53
54
  private
54
55
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.11.1'
4
+ VERSION = '0.12.0'
5
5
  end
data/lib/sevencop.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative 'sevencop/rubocop_extension'
4
4
  require_relative 'sevencop/version'
5
5
 
6
+ require_relative 'rubocop/cop/sevencop/autoload_ordered'
6
7
  require_relative 'rubocop/cop/sevencop/belongs_to_optional'
7
8
  require_relative 'rubocop/cop/sevencop/factory_bot_create_list'
8
9
  require_relative 'rubocop/cop/sevencop/hash_literal_order'
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.11.1
4
+ version: 0.12.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: 2022-09-21 00:00:00.000000000 Z
11
+ date: 2022-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -41,6 +41,7 @@ files:
41
41
  - README.md
42
42
  - Rakefile
43
43
  - config/default.yml
44
+ - lib/rubocop/cop/sevencop/autoload_ordered.rb
44
45
  - lib/rubocop/cop/sevencop/belongs_to_optional.rb
45
46
  - lib/rubocop/cop/sevencop/factory_bot_create_list.rb
46
47
  - lib/rubocop/cop/sevencop/hash_literal_order.rb