sevencop 0.11.1 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +16 -0
- data/Gemfile +6 -3
- data/Gemfile.lock +22 -12
- data/README.md +21 -0
- data/config/default.yml +6 -0
- data/lib/rubocop/cop/sevencop/autoload_ordered.rb +87 -0
- data/lib/rubocop/cop/sevencop/factory_bot_create_list.rb +1 -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: adcb3382c32455ca63651bf5593974e773cf00dfd0b3d14955541c6ce219c6c7
|
4
|
+
data.tar.gz: d6f50b292bb6f56c0f6ec36fc4271c931af4c1c46cef9b8c14a2505cf984f8ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 552d6582fc4aa3baa550afd6d27477c822e4f098b470c0c038a36380c6ab74f9962a27e8f04be05cc60586be43376de1ec20a0a5b56587d71b24d3fa36e8e4cb
|
7
|
+
data.tar.gz: 05df622c8de515879b816077ba5fc40cd47858c1666390beac8d2ac29e86c1983921d5d8964b8b7de64106e789f3217032b6338a9988442207dbe5aeb62a8031
|
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'
|
9
|
-
gem 'rspec'
|
10
|
-
gem 'rubocop'
|
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.
|
4
|
+
sevencop (0.12.1)
|
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.
|
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.
|
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.
|
33
|
-
rubocop (1.
|
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.
|
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.
|
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.
|
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.
|
53
|
+
unicode-display_width (2.3.0)
|
47
54
|
|
48
55
|
PLATFORMS
|
49
56
|
x86_64-linux
|
50
57
|
|
51
58
|
DEPENDENCIES
|
52
|
-
rake
|
53
|
-
rspec
|
54
|
-
rubocop
|
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,27 @@ 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 within their section.
|
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
|
+
# good
|
64
|
+
autoload :B, 'b'
|
65
|
+
autoload :D, 'd'
|
66
|
+
|
67
|
+
autoload :A, 'a'
|
68
|
+
autoload :C, 'a'
|
69
|
+
```
|
70
|
+
|
50
71
|
### Sevencop/BelongsToOptional
|
51
72
|
|
52
73
|
Force `belongs_to` with `optional: true` option.
|
data/config/default.yml
CHANGED
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Sevencop
|
6
|
+
# Sort `autoload` in alphabetical order within their section.
|
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
|
+
#
|
17
|
+
# # good
|
18
|
+
# autoload :A, 'a'
|
19
|
+
# autoload :D, 'd'
|
20
|
+
#
|
21
|
+
# autoload :B, 'b'
|
22
|
+
# autoload :C, 'c'
|
23
|
+
class AutoloadOrdered < Base
|
24
|
+
extend AutoCorrector
|
25
|
+
|
26
|
+
include RangeHelp
|
27
|
+
|
28
|
+
MSG = 'Sort `autoload` in alphabetical order within their section.'
|
29
|
+
|
30
|
+
RESTRICT_ON_SEND = %i[
|
31
|
+
autoload
|
32
|
+
].freeze
|
33
|
+
|
34
|
+
# @param node [RuboCop::AST::SendNode]
|
35
|
+
def on_send(node)
|
36
|
+
previous_older_autoload = find_previous_older_autoload(node)
|
37
|
+
return unless previous_older_autoload
|
38
|
+
|
39
|
+
add_offense(node) do |corrector|
|
40
|
+
swap(
|
41
|
+
range_by_whole_lines(
|
42
|
+
previous_older_autoload.location.expression,
|
43
|
+
include_final_newline: true
|
44
|
+
),
|
45
|
+
range_by_whole_lines(
|
46
|
+
node.location.expression,
|
47
|
+
include_final_newline: true
|
48
|
+
),
|
49
|
+
corrector: corrector
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
# @param node [RuboCop::AST::SendNode]
|
57
|
+
# @return [RuboCop::AST::SendNode]
|
58
|
+
def find_previous_older_autoload(node)
|
59
|
+
node.left_siblings.find do |sibling|
|
60
|
+
next unless sibling.send_type?
|
61
|
+
next unless sibling.method?(:autoload)
|
62
|
+
next unless in_same_section?(sibling, node)
|
63
|
+
|
64
|
+
node.first_argument.source < sibling.first_argument.source
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# @param node1 [RuboCop::AST::SendNode]
|
69
|
+
# @param node2 [RuboCop::AST::SendNode]
|
70
|
+
# @return [Boolean]
|
71
|
+
def in_same_section?(node1, node2)
|
72
|
+
!node1.location.expression.with(
|
73
|
+
end_pos: node2.location.expression.end_pos
|
74
|
+
).source.include?("\n\n")
|
75
|
+
end
|
76
|
+
|
77
|
+
# @param range1 [Paresr::Source::Range]
|
78
|
+
# @param range2 [Paresr::Source::Range]
|
79
|
+
# @param corrector [RuboCop::AST::Corrector]
|
80
|
+
def swap(range1, range2, corrector:)
|
81
|
+
corrector.insert_before(range1, range2.source)
|
82
|
+
corrector.remove(range2)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/sevencop/version.rb
CHANGED
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.
|
4
|
+
version: 0.12.1
|
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-
|
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
|