sevencop 0.4.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/Gemfile.lock +3 -3
- data/README.md +24 -6
- data/Rakefile +1 -1
- data/config/default.yml +8 -1
- data/lib/rubocop/cop/sevencop/belongs_to_optional.rb +54 -0
- data/lib/rubocop/cop/sevencop/order_field.rb +4 -1
- data/lib/sevencop/version.rb +1 -1
- data/lib/sevencop.rb +1 -0
- data/{rubocop-rails_deprecation.gemspec → sevencop.gemspec} +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db281c40f5207dfc9759c52c60d4e2799d772e8d612364c4afa9b72eb935c90a
|
4
|
+
data.tar.gz: f84b8ca1a7d8cdb598c170b9c04b98b2358750ced29a8d3b3fb011b8a629449c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4597d82f8b5dd02a575d4720c10f495e6ebf16bfe47ef88c9557e5cb474c83bc35505861e2a1e5fdbc3b1d062fac6a06d3cfe94a05593ee9638a0aecf1034125
|
7
|
+
data.tar.gz: 3e9c4206cec1f67a0ab9176814f4405fe6d7fbe83c8571d0759788206b67569a8ad144f0cb934dbc2ddf30df29d529906f7160c5b029fbc13a60464229f2a8d6
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,32 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 0.5.1 - 2022-06-28
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
- Fix `Sevencop/BelongsToOptional` scope bug.
|
10
|
+
|
11
|
+
## 0.5.0 - 2022-06-27
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- Add `Sevencop/BelongsToOptional` cop.
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
- Make `Sevencop/RedundantExistenceCheck` cop disabled by default.
|
20
|
+
|
21
|
+
### Removed
|
22
|
+
|
23
|
+
- Remove rubocop version dependency.
|
24
|
+
|
25
|
+
## 0.4.1 - 2022-06-23
|
26
|
+
|
27
|
+
### Fixed
|
28
|
+
|
29
|
+
- Fix `Sevencop/OrderField` on dstr.
|
30
|
+
|
5
31
|
## 0.4.0 - 2022-06-18
|
6
32
|
|
7
33
|
### Added
|
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,9 +75,7 @@ reorder('field(id, ?)', a)
|
|
53
75
|
reorder(Arel.sql('field(id, ?)'), a)
|
54
76
|
```
|
55
77
|
|
56
|
-
|
57
|
-
|
58
|
-
### `Sevencop/RedundantExistenceCheck`
|
78
|
+
### Sevencop/RedundantExistenceCheck
|
59
79
|
|
60
80
|
Identifies redundant existent check before file operation.
|
61
81
|
|
@@ -73,7 +93,7 @@ FileUtils.rm(a) if FileTest.exist?(a)
|
|
73
93
|
FileUtils.rm_f(a)
|
74
94
|
```
|
75
95
|
|
76
|
-
###
|
96
|
+
### Sevencop/UniquenessValidatorExplicitCaseSensitivity
|
77
97
|
|
78
98
|
Identifies use of UniquenessValidator without :case_sensitive option.
|
79
99
|
|
@@ -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/Rakefile
CHANGED
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,54 @@
|
|
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 _ _ _ (block ...)?)
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
def_node_matcher :with_hash_options?, <<~PATTERN
|
36
|
+
(send _ _ _ (block ...)? (hash ...))
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
def_node_matcher :with_optional?, <<~PATTERN
|
40
|
+
(send _ _ _ (block ...)? (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
|
+
corrector.insert_after(node.arguments[-1], ', optional: true')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
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'
|
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.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-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,13 +41,14 @@ 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
|
47
48
|
- lib/sevencop.rb
|
48
49
|
- lib/sevencop/inject.rb
|
49
50
|
- lib/sevencop/version.rb
|
50
|
-
-
|
51
|
+
- sevencop.gemspec
|
51
52
|
homepage: https://github.com/r7kamura/sevencop
|
52
53
|
licenses:
|
53
54
|
- MIT
|