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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee9785d463d0e83d3f55dc1554e250e826a9cbd5aa6aacb510f11a4bdfb1947a
4
- data.tar.gz: 9ca8456b525226ba8a599c4ef87f08ea208000268fa73ccf9f1501531682d294
3
+ metadata.gz: '0977a1a38e5da28e989cde731824234e1a8aaa2f926cf416d31c4acbe9fb4a3d'
4
+ data.tar.gz: 3bbf77f3ad02d92ed82ca989908deb42cbced1e8ff7b9cd830a8a3b4b46c40e2
5
5
  SHA512:
6
- metadata.gz: edc7f9620eaa81224e47c8e8785df67bc29c51a0c6969f30bd24a3d6869a64be26686ccce7c3b43c89bc89f06b9283b67030587c86eb0b7ef5598d42ee1dc90b
7
- data.tar.gz: 9a3bf2ecc2eed54ae8dd6207d0f0cd93c13f577bbcab69cdc9992e42f87687e416d9612136f1483952cfb51bdf22890727b14d6d66653e9294732dcb1da8d389
6
+ metadata.gz: 327acfe1f5b8d48ec9d11f369e32287b13972efdbe69c7e85f7f7a0ea7dfb520c5ac6d1be803e0b727bff6de6e231096d35c5b6a8e516aa0b3dfd98f1aec0eac
7
+ data.tar.gz: 6eb86ca1c5caa944ad099e556dcbc5d881b8c8be7c63e1d4bd6cccbc14d5fdfadfd4808e03c8461726f5f9e1ba97e0dcc247f0c34874eb8dc01152f6243ad14f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.10.0)
4
+ sevencop (0.11.0)
5
5
  rubocop
6
6
 
7
7
  GEM
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.10.0'
4
+ VERSION = '0.11.0'
5
5
  end
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.10.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-08-30 00:00:00.000000000 Z
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