sevencop 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +20 -0
- data/config/default.yml +6 -0
- data/lib/rubocop/cop/sevencop/method_definition_multiline_arguments.rb +71 -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: '0977a1a38e5da28e989cde731824234e1a8aaa2f926cf416d31c4acbe9fb4a3d'
|
4
|
+
data.tar.gz: 3bbf77f3ad02d92ed82ca989908deb42cbced1e8ff7b9cd830a8a3b4b46c40e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 327acfe1f5b8d48ec9d11f369e32287b13972efdbe69c7e85f7f7a0ea7dfb520c5ac6d1be803e0b727bff6de6e231096d35c5b6a8e516aa0b3dfd98f1aec0eac
|
7
|
+
data.tar.gz: 6eb86ca1c5caa944ad099e556dcbc5d881b8c8be7c63e1d4bd6cccbc14d5fdfadfd4808e03c8461726f5f9e1ba97e0dcc247f0c34874eb8dc01152f6243ad14f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -124,6 +124,26 @@ RSpec.describe User
|
|
124
124
|
RSpec.describe User, type: :request
|
125
125
|
```
|
126
126
|
|
127
|
+
### Sevencop/MethodDefinitionMultilineArguments
|
128
|
+
|
129
|
+
Inserts new lines between method definition parameters.
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
# bad
|
133
|
+
def foo(a, b)
|
134
|
+
end
|
135
|
+
|
136
|
+
# good
|
137
|
+
def foo(
|
138
|
+
a,
|
139
|
+
b
|
140
|
+
)
|
141
|
+
|
142
|
+
# good
|
143
|
+
def foo(a)
|
144
|
+
end
|
145
|
+
```
|
146
|
+
|
127
147
|
### Sevencop/OrderField
|
128
148
|
|
129
149
|
Identifies a String including "field" is passed to `order` or `reorder`.
|
data/config/default.yml
CHANGED
@@ -23,6 +23,12 @@ Sevencop/InferredSpecType:
|
|
23
23
|
Enabled: false
|
24
24
|
VersionAdded: '0.9'
|
25
25
|
|
26
|
+
Sevencop/MethodDefinitionMultilineArguments:
|
27
|
+
Description: |
|
28
|
+
Inserts new lines between method definition parameters.
|
29
|
+
Enabled: false
|
30
|
+
VersionAdded: '0.11'
|
31
|
+
|
26
32
|
Sevencop/OrderField:
|
27
33
|
Description: |
|
28
34
|
Wrap safe SQL String by `Arel.sql`.
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Sevencop
|
6
|
+
# Inserts new lines between method definition parameters.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# def foo(a, b)
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# def foo(
|
15
|
+
# a,
|
16
|
+
# b
|
17
|
+
# )
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# def foo(a)
|
21
|
+
# end
|
22
|
+
class MethodDefinitionMultilineArguments < Base
|
23
|
+
extend AutoCorrector
|
24
|
+
|
25
|
+
MSG = 'Insert new lines between method definition parameters.'
|
26
|
+
|
27
|
+
# @param node [RuboCop::AST::ArgsNode]
|
28
|
+
def on_args(node)
|
29
|
+
return if method_args?(node) && multilined?(node)
|
30
|
+
|
31
|
+
add_offense(node) do |corrector|
|
32
|
+
autocorrect(corrector, node)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# @param corrector [RuboCop::AST::Corrector]
|
39
|
+
# @param node [RuboCop::AST::ArgsNode]
|
40
|
+
# @return [String]
|
41
|
+
def autocorrect(corrector, node)
|
42
|
+
indent = ' ' * node.parent.location.expression.column
|
43
|
+
|
44
|
+
corrector.replace(
|
45
|
+
node.location.expression.with(
|
46
|
+
begin_pos: node.parent.location.name.end_pos
|
47
|
+
),
|
48
|
+
[
|
49
|
+
"(\n#{indent} ",
|
50
|
+
node.children.map(&:source).join(",\n#{indent} "),
|
51
|
+
"\n#{indent})"
|
52
|
+
].join
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param node [RuboCop::AST::ArgsNode]
|
57
|
+
# @return [Boolean]
|
58
|
+
def multilined?(node)
|
59
|
+
node.children.map do |child|
|
60
|
+
child.location.expression.line
|
61
|
+
end.uniq.length == node.children.length
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [Boolean]
|
65
|
+
def method_args?(node)
|
66
|
+
!node.parent.nil? && node.parent.def_type?
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/sevencop/version.rb
CHANGED
data/lib/sevencop.rb
CHANGED
@@ -7,6 +7,7 @@ require_relative 'rubocop/cop/sevencop/belongs_to_optional'
|
|
7
7
|
require_relative 'rubocop/cop/sevencop/factory_bot_create_list'
|
8
8
|
require_relative 'rubocop/cop/sevencop/hash_literal_order'
|
9
9
|
require_relative 'rubocop/cop/sevencop/inferred_spec_type'
|
10
|
+
require_relative 'rubocop/cop/sevencop/method_definition_multiline_arguments'
|
10
11
|
require_relative 'rubocop/cop/sevencop/order_field'
|
11
12
|
require_relative 'rubocop/cop/sevencop/redundant_existence_check'
|
12
13
|
require_relative 'rubocop/cop/sevencop/to_s_with_argument'
|
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.11.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-
|
11
|
+
date: 2022-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/rubocop/cop/sevencop/factory_bot_create_list.rb
|
46
46
|
- lib/rubocop/cop/sevencop/hash_literal_order.rb
|
47
47
|
- lib/rubocop/cop/sevencop/inferred_spec_type.rb
|
48
|
+
- lib/rubocop/cop/sevencop/method_definition_multiline_arguments.rb
|
48
49
|
- lib/rubocop/cop/sevencop/order_field.rb
|
49
50
|
- lib/rubocop/cop/sevencop/redundant_existence_check.rb
|
50
51
|
- lib/rubocop/cop/sevencop/to_s_with_argument.rb
|