sevencop 0.4.1 → 0.5.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 +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +2 -2
- data/README.md +22 -4
- data/config/default.yml +8 -1
- data/lib/rubocop/cop/sevencop/belongs_to_optional.rb +58 -0
- data/lib/sevencop/version.rb +1 -1
- data/lib/sevencop.rb +1 -0
- data/sevencop.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 319d9ad3cd53f54122dd36a4d53d4ba2b1e496831c3c26022b2a8494f5a95fdc
|
4
|
+
data.tar.gz: b54dd12e0177a48827cb87f35fa6af902e256f996c96a990933c08c22e8b91f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07d68c578fa6807867b0caa213706484ff8c04475e1f17ce0f3121a37307f0cb48962a1ee7c1782dcbaedbff34748a075a41522e8d9c79dcdf24e9d4b8aa581a
|
7
|
+
data.tar.gz: e47791134b21b41a4d9fcae6503db43cefb2d377391b7e3c5a7537bd5944fecd444164931df15035d628b939ce6fe5e6fac50694aef76c856c66c3a97763b04a
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,20 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 0.5.0 - 2022-06-27
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Add `Sevencop/BelongsToOptional` cop.
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- Make `Sevencop/RedundantExistenceCheck` cop disabled by default.
|
14
|
+
|
15
|
+
### Removed
|
16
|
+
|
17
|
+
- Remove rubocop version dependency.
|
18
|
+
|
5
19
|
## 0.4.1 - 2022-06-23
|
6
20
|
|
7
21
|
### Fixed
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -35,6 +35,28 @@ require:
|
|
35
35
|
|
36
36
|
## Cops
|
37
37
|
|
38
|
+
All cops are `Enabled: false` by default.
|
39
|
+
|
40
|
+
### Sevencop/BelongsToOptional
|
41
|
+
|
42
|
+
Force `belongs_to` with `optional: true` option.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# bad
|
46
|
+
belongs_to :group
|
47
|
+
|
48
|
+
# good
|
49
|
+
belongs_to :group, optional: true
|
50
|
+
|
51
|
+
# good
|
52
|
+
belongs_to :group, optional: false
|
53
|
+
|
54
|
+
# good
|
55
|
+
belongs_to :group, options
|
56
|
+
```
|
57
|
+
|
58
|
+
This is useful for migration of `config.active_record.belongs_to_required_by_default`.
|
59
|
+
|
38
60
|
### Sevencop/OrderField
|
39
61
|
|
40
62
|
Identifies a String including "field" is passed to `order` or `reorder`.
|
@@ -53,8 +75,6 @@ reorder('field(id, ?)', a)
|
|
53
75
|
reorder(Arel.sql('field(id, ?)'), a)
|
54
76
|
```
|
55
77
|
|
56
|
-
`Enabled: false` by default.
|
57
|
-
|
58
78
|
### Sevencop/RedundantExistenceCheck
|
59
79
|
|
60
80
|
Identifies redundant existent check before file operation.
|
@@ -95,5 +115,3 @@ validates :name, uniqueness: { allow_nil: true, scope: :user_id, case_sensitive:
|
|
95
115
|
```
|
96
116
|
|
97
117
|
Useful to keep the same behavior between Rails 6.0 and 6.1 where case insensitive collation is used in MySQL.
|
98
|
-
|
99
|
-
`Enabled: false` by default.
|
data/config/default.yml
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
Sevencop/BelongsToOptional:
|
2
|
+
Description: |
|
3
|
+
Force `belongs_to` with `optional: true` option.
|
4
|
+
Enabled: false
|
5
|
+
Safe: false
|
6
|
+
VersionAdded: '0.5'
|
7
|
+
|
1
8
|
Sevencop/OrderField:
|
2
9
|
Description: Wrap safe SQL String by `Arel.sql`.
|
3
10
|
Enabled: false
|
@@ -6,7 +13,7 @@ Sevencop/OrderField:
|
|
6
13
|
|
7
14
|
Sevencop/RedundantExistenceCheck:
|
8
15
|
Description: Avoid redundant existent check before file operation.
|
9
|
-
Enabled:
|
16
|
+
Enabled: false
|
10
17
|
Safe: false
|
11
18
|
VersionAdded: '0.1'
|
12
19
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Sevencop
|
6
|
+
# Force `belongs_to` with `optional: true` option.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# belongs_to :group
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# belongs_to :group, optional: true
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# belongs_to :group, optional: false
|
18
|
+
#
|
19
|
+
# # good (We cannot identify offenses in this case.)
|
20
|
+
# belongs_to :group, options
|
21
|
+
#
|
22
|
+
class BelongsToOptional < Base
|
23
|
+
extend AutoCorrector
|
24
|
+
|
25
|
+
MSG = 'Specify :optional option.'
|
26
|
+
|
27
|
+
RESTRICT_ON_SEND = %i[
|
28
|
+
belongs_to
|
29
|
+
].freeze
|
30
|
+
|
31
|
+
def_node_matcher :without_options?, <<~PATTERN
|
32
|
+
(send _ _ _)
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
def_node_matcher :with_hash_options?, <<~PATTERN
|
36
|
+
(send _ _ _ (hash ...))
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
def_node_matcher :with_optional?, <<~PATTERN
|
40
|
+
(send _ _ _ (hash <(pair (sym :optional) _) ...>))
|
41
|
+
PATTERN
|
42
|
+
|
43
|
+
# @param [RuboCop::AST::SendNode] node
|
44
|
+
def on_send(node)
|
45
|
+
return unless without_options?(node) || (with_hash_options?(node) && !with_optional?(node))
|
46
|
+
|
47
|
+
add_offense(node) do |corrector|
|
48
|
+
if node.arguments[-1].hash_type?
|
49
|
+
corrector.insert_after(node.arguments[-1], ', optional: true')
|
50
|
+
elsif node.arguments.length == 1
|
51
|
+
corrector.insert_after(node.arguments.first, ', optional: true')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/sevencop/version.rb
CHANGED
data/lib/sevencop.rb
CHANGED
@@ -6,6 +6,7 @@ require 'yaml'
|
|
6
6
|
require_relative 'sevencop/inject'
|
7
7
|
require_relative 'sevencop/version'
|
8
8
|
|
9
|
+
require_relative 'rubocop/cop/sevencop/belongs_to_optional'
|
9
10
|
require_relative 'rubocop/cop/sevencop/order_field'
|
10
11
|
require_relative 'rubocop/cop/sevencop/redundant_existence_check'
|
11
12
|
require_relative 'rubocop/cop/sevencop/uniqueness_validator_explicit_case_sensitivity'
|
data/sevencop.gemspec
CHANGED
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.5.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-06-
|
11
|
+
date: 2022-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
description:
|
28
28
|
email:
|
29
29
|
- r7kamura@gmail.com
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- README.md
|
42
42
|
- Rakefile
|
43
43
|
- config/default.yml
|
44
|
+
- lib/rubocop/cop/sevencop/belongs_to_optional.rb
|
44
45
|
- lib/rubocop/cop/sevencop/order_field.rb
|
45
46
|
- lib/rubocop/cop/sevencop/redundant_existence_check.rb
|
46
47
|
- lib/rubocop/cop/sevencop/uniqueness_validator_explicit_case_sensitivity.rb
|