rubocop-numbered-params 1.0.0 → 1.0.1
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/.vscode/extensions.json +6 -0
- data/.vscode/settings.json +3 -0
- data/CHANGELOG.md +5 -1
- data/README.md +80 -14
- data/Rakefile +25 -1
- data/Steepfile +8 -0
- data/lib/rubocop/cop/style/prefer_numbered_parameter.rb +21 -11
- data/lib/rubocop/numbered/params/plugin.rb +4 -1
- data/lib/rubocop/numbered/params/version.rb +1 -1
- data/rbs_collection.lock.yaml +196 -0
- data/rbs_collection.yaml +19 -0
- data/sig/rubocop/cop/style/prefer_numbered_parameter.rbs +56 -0
- data/sig/rubocop/numbered/params/plugin.rbs +18 -0
- data/sig/rubocop/numbered/params/version.rbs +9 -0
- data/sig/rubocop/numbered/params.rbs +4 -2
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '098abf73a4aa4cbce466348f1c01b9889f7cc7bb8ad27c269b9ddce343bf8e24'
|
|
4
|
+
data.tar.gz: 3b2b371fed2a01626d336770c9898679ad3d44c17ce74f80e72b695ed937fa88
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e4d670c627790c9a519d4dd4b83439e1dd363436292c4b42c8eb7f560341b0f2c690bab8496b02654f9d2c3a2ae3d957a0c2d7f996aec02969c65c5d3ead1f69
|
|
7
|
+
data.tar.gz: a2012d86739213385b9ac1715182d7e900ab5eae42950b070c20d2fcb9420aaa72c86c3633545647d9a2ce4021270d17eb38ea5ee7a0a88c59a670648b08c731
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,28 +1,94 @@
|
|
|
1
|
-
#
|
|
1
|
+
# rubocop-numbered-params
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubocop/numbered/params`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
3
|
+
A RuboCop plugin that recommends using numbered parameters (`_1`, `_2`, ...) instead of named block arguments in single-line blocks.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Install the gem and add to the application's Gemfile by executing:
|
|
7
|
+
Add the gem to your application's Gemfile:
|
|
12
8
|
|
|
13
9
|
```bash
|
|
14
|
-
bundle add
|
|
10
|
+
bundle add rubocop-numbered-params
|
|
15
11
|
```
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
Or install it directly:
|
|
18
14
|
|
|
19
15
|
```bash
|
|
20
|
-
gem install
|
|
16
|
+
gem install rubocop-numbered-params
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then add it to your `.rubocop.yml`:
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
plugins:
|
|
23
|
+
- rubocop-numbered-params
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Cops
|
|
27
|
+
|
|
28
|
+
### Style/PreferNumberedParameter
|
|
29
|
+
|
|
30
|
+
Recommends using numbered parameters (`_1`, `_2`, ...) instead of named block arguments in single-line blocks. This cop supports autocorrection.
|
|
31
|
+
|
|
32
|
+
**Bad:**
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
users.map { |user| user.name }
|
|
36
|
+
items.select { |item| item.active? }
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Good:**
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
users.map { _1.name }
|
|
43
|
+
items.select { _1.active? }
|
|
21
44
|
```
|
|
22
45
|
|
|
23
|
-
|
|
46
|
+
Multi-line blocks are not targeted:
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
# good - multi-line block (not targeted)
|
|
50
|
+
users.map do |user|
|
|
51
|
+
user.name
|
|
52
|
+
end
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Configuration
|
|
56
|
+
|
|
57
|
+
| Option | Default | Description |
|
|
58
|
+
|--------|---------|-------------|
|
|
59
|
+
| `MaxArguments` | `1` | Maximum number of block arguments to target. Blocks with more arguments than this value are ignored. |
|
|
60
|
+
|
|
61
|
+
Example with `MaxArguments: 2`:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
Style/PreferNumberedParameter:
|
|
65
|
+
MaxArguments: 2
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
# bad
|
|
70
|
+
hash.each { |key, value| "#{key}: #{value}" }
|
|
71
|
+
|
|
72
|
+
# good
|
|
73
|
+
hash.each { "#{_1}: #{_2}" }
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### Exceptions
|
|
77
|
+
|
|
78
|
+
The cop does not register an offense in the following cases:
|
|
79
|
+
|
|
80
|
+
- Multi-line blocks
|
|
81
|
+
- Blocks with an empty body
|
|
82
|
+
- Blocks with destructuring arguments: `|(key, value)|`
|
|
83
|
+
- Blocks with splat arguments: `|*args|`
|
|
84
|
+
- Blocks with block arguments: `|&block|`
|
|
85
|
+
- Blocks with shadow variables: `|item; temp|`
|
|
86
|
+
- Outer blocks that contain inner blocks (the inner block is checked separately)
|
|
87
|
+
|
|
88
|
+
## Requirements
|
|
24
89
|
|
|
25
|
-
|
|
90
|
+
- Ruby >= 3.2.0
|
|
91
|
+
- RuboCop >= 1.72.1
|
|
26
92
|
|
|
27
93
|
## Development
|
|
28
94
|
|
|
@@ -32,7 +98,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
32
98
|
|
|
33
99
|
## Contributing
|
|
34
100
|
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
101
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tk0miya/rubocop-numbered-params. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/tk0miya/rubocop-numbered-params/blob/main/CODE_OF_CONDUCT.md).
|
|
36
102
|
|
|
37
103
|
## License
|
|
38
104
|
|
|
@@ -40,4 +106,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
40
106
|
|
|
41
107
|
## Code of Conduct
|
|
42
108
|
|
|
43
|
-
Everyone interacting in the
|
|
109
|
+
Everyone interacting in the rubocop-numbered-params project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/tk0miya/rubocop-numbered-params/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
|
@@ -9,4 +9,28 @@ require "rubocop/rake_task"
|
|
|
9
9
|
|
|
10
10
|
RuboCop::RakeTask.new
|
|
11
11
|
|
|
12
|
-
task default:
|
|
12
|
+
task default: :ci
|
|
13
|
+
|
|
14
|
+
task ci: %i[rubocop spec steep]
|
|
15
|
+
|
|
16
|
+
namespace :rbs do
|
|
17
|
+
desc "Install RBS signatures"
|
|
18
|
+
task :install do
|
|
19
|
+
sh "bundle exec rbs collection install --frozen"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
desc "Generate RBS files"
|
|
23
|
+
task :generate do
|
|
24
|
+
sh "rbs-inline", "--opt-out", "--output=sig", "lib"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
desc "Validate RBS files"
|
|
28
|
+
task validate: "rbs:install" do
|
|
29
|
+
sh "bundle exec rbs -Isig validate"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
desc "Run Steep type checker"
|
|
34
|
+
task steep: "rbs:install" do
|
|
35
|
+
sh "bundle exec steep check"
|
|
36
|
+
end
|
data/Steepfile
ADDED
|
@@ -33,10 +33,12 @@ module RuboCop
|
|
|
33
33
|
MSG = "Use numbered parameters (`_1`, `_2`, ...) instead of named block arguments " \
|
|
34
34
|
"for single-line blocks."
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
# @rbs node: RuboCop::AST::BlockNode
|
|
37
|
+
def on_block(node) #: void # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
37
38
|
return unless node.single_line?
|
|
38
|
-
return if node.
|
|
39
|
-
return if node.arguments.
|
|
39
|
+
return if node.lambda?
|
|
40
|
+
return if node.arguments.argument_list.empty?
|
|
41
|
+
return if node.arguments.argument_list.count > max_arguments
|
|
40
42
|
return if node.body.nil?
|
|
41
43
|
return if special_arguments?(node)
|
|
42
44
|
return if contains_inner_block?(node.body)
|
|
@@ -48,10 +50,13 @@ module RuboCop
|
|
|
48
50
|
|
|
49
51
|
private
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
# @rbs corrector: RuboCop::Cop::Corrector
|
|
54
|
+
# @rbs node: RuboCop::AST::BlockNode
|
|
55
|
+
def autocorrect(corrector, node) #: void # rubocop:disable Metrics/AbcSize
|
|
52
56
|
lvar_nodes = collect_lvar_nodes(node.body)
|
|
53
57
|
|
|
54
|
-
node.arguments.
|
|
58
|
+
argument_list = node.arguments.argument_list #: Array[RuboCop::AST::ArgNode]
|
|
59
|
+
argument_list.each.with_index(1) do |arg, index|
|
|
55
60
|
numbered = "_#{index}"
|
|
56
61
|
lvar_nodes.select { _1.children.first == arg.name }.each do |lvar|
|
|
57
62
|
corrector.replace(lvar.source_range, numbered)
|
|
@@ -62,24 +67,29 @@ module RuboCop
|
|
|
62
67
|
corrector.remove(args_range.resize(args_range.size + 1))
|
|
63
68
|
end
|
|
64
69
|
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
# @rbs node: RuboCop::AST::Node?
|
|
71
|
+
def collect_lvar_nodes(node) #: Array[RuboCop::AST::Node]
|
|
72
|
+
return [] unless node
|
|
73
|
+
|
|
74
|
+
result = [] #: Array[RuboCop::AST::Node]
|
|
67
75
|
result << node if node.lvar_type?
|
|
68
76
|
node.each_descendant(:lvar) { result << _1 }
|
|
69
77
|
result
|
|
70
78
|
end
|
|
71
79
|
|
|
72
|
-
def max_arguments
|
|
80
|
+
def max_arguments #: Integer
|
|
73
81
|
cop_config.fetch("MaxArguments", 1)
|
|
74
82
|
end
|
|
75
83
|
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
# @rbs node: RuboCop::AST::BlockNode
|
|
85
|
+
def special_arguments?(node) #: bool
|
|
86
|
+
node.arguments.argument_list.any? do |arg|
|
|
78
87
|
arg.mlhs_type? || arg.restarg_type? || arg.blockarg_type? || arg.shadowarg_type?
|
|
79
88
|
end
|
|
80
89
|
end
|
|
81
90
|
|
|
82
|
-
|
|
91
|
+
# @rbs node: RuboCop::AST::Node?
|
|
92
|
+
def contains_inner_block?(node) #: bool
|
|
83
93
|
return false unless node
|
|
84
94
|
|
|
85
95
|
node.block_type? || node.numblock_type? || node.each_descendant(:block, :numblock).any?
|
|
@@ -6,6 +6,7 @@ module Rubocop
|
|
|
6
6
|
module Numbered
|
|
7
7
|
module Params
|
|
8
8
|
class Plugin < LintRoller::Plugin
|
|
9
|
+
# @rbs override
|
|
9
10
|
def about
|
|
10
11
|
LintRoller::About.new(
|
|
11
12
|
name: "rubocop-numbered-params",
|
|
@@ -16,15 +17,17 @@ module Rubocop
|
|
|
16
17
|
)
|
|
17
18
|
end
|
|
18
19
|
|
|
20
|
+
# @rbs override
|
|
19
21
|
def supported?(context)
|
|
20
22
|
context.engine == :rubocop
|
|
21
23
|
end
|
|
22
24
|
|
|
25
|
+
# @rbs override
|
|
23
26
|
def rules(_context)
|
|
24
27
|
LintRoller::Rules.new(
|
|
25
28
|
type: :path,
|
|
26
29
|
config_format: :rubocop,
|
|
27
|
-
value: Pathname.new(__dir__).join("../../../../config/default.yml")
|
|
30
|
+
value: Pathname.new(__dir__ || "").join("../../../../config/default.yml")
|
|
28
31
|
)
|
|
29
32
|
end
|
|
30
33
|
end
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
---
|
|
2
|
+
path: ".gem_rbs_collection"
|
|
3
|
+
gems:
|
|
4
|
+
- name: ast
|
|
5
|
+
version: '2.4'
|
|
6
|
+
source:
|
|
7
|
+
type: git
|
|
8
|
+
name: ruby/gem_rbs_collection
|
|
9
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
10
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
11
|
+
repo_dir: gems
|
|
12
|
+
- name: concurrent-ruby
|
|
13
|
+
version: '1.1'
|
|
14
|
+
source:
|
|
15
|
+
type: git
|
|
16
|
+
name: ruby/gem_rbs_collection
|
|
17
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
18
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
19
|
+
repo_dir: gems
|
|
20
|
+
- name: csv
|
|
21
|
+
version: '3.3'
|
|
22
|
+
source:
|
|
23
|
+
type: git
|
|
24
|
+
name: ruby/gem_rbs_collection
|
|
25
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
26
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
27
|
+
repo_dir: gems
|
|
28
|
+
- name: diff-lcs
|
|
29
|
+
version: '1.5'
|
|
30
|
+
source:
|
|
31
|
+
type: git
|
|
32
|
+
name: ruby/gem_rbs_collection
|
|
33
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
34
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
35
|
+
repo_dir: gems
|
|
36
|
+
- name: ffi
|
|
37
|
+
version: 1.17.4
|
|
38
|
+
source:
|
|
39
|
+
type: rubygems
|
|
40
|
+
- name: fileutils
|
|
41
|
+
version: '0'
|
|
42
|
+
source:
|
|
43
|
+
type: stdlib
|
|
44
|
+
- name: forwardable
|
|
45
|
+
version: '0'
|
|
46
|
+
source:
|
|
47
|
+
type: stdlib
|
|
48
|
+
- name: io-console
|
|
49
|
+
version: '0'
|
|
50
|
+
source:
|
|
51
|
+
type: stdlib
|
|
52
|
+
- name: json
|
|
53
|
+
version: '0'
|
|
54
|
+
source:
|
|
55
|
+
type: stdlib
|
|
56
|
+
- name: lint_roller
|
|
57
|
+
version: '1.1'
|
|
58
|
+
source:
|
|
59
|
+
type: git
|
|
60
|
+
name: ruby/gem_rbs_collection
|
|
61
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
62
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
63
|
+
repo_dir: gems
|
|
64
|
+
- name: listen
|
|
65
|
+
version: '3.9'
|
|
66
|
+
source:
|
|
67
|
+
type: git
|
|
68
|
+
name: ruby/gem_rbs_collection
|
|
69
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
70
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
71
|
+
repo_dir: gems
|
|
72
|
+
- name: logger
|
|
73
|
+
version: '1.7'
|
|
74
|
+
source:
|
|
75
|
+
type: git
|
|
76
|
+
name: ruby/gem_rbs_collection
|
|
77
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
78
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
79
|
+
repo_dir: gems
|
|
80
|
+
- name: monitor
|
|
81
|
+
version: '0'
|
|
82
|
+
source:
|
|
83
|
+
type: stdlib
|
|
84
|
+
- name: optparse
|
|
85
|
+
version: '0'
|
|
86
|
+
source:
|
|
87
|
+
type: stdlib
|
|
88
|
+
- name: parallel
|
|
89
|
+
version: '1.20'
|
|
90
|
+
source:
|
|
91
|
+
type: git
|
|
92
|
+
name: ruby/gem_rbs_collection
|
|
93
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
94
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
95
|
+
repo_dir: gems
|
|
96
|
+
- name: parser
|
|
97
|
+
version: '3.2'
|
|
98
|
+
source:
|
|
99
|
+
type: git
|
|
100
|
+
name: ruby/gem_rbs_collection
|
|
101
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
102
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
103
|
+
repo_dir: gems
|
|
104
|
+
- name: pp
|
|
105
|
+
version: '0'
|
|
106
|
+
source:
|
|
107
|
+
type: stdlib
|
|
108
|
+
- name: prettyprint
|
|
109
|
+
version: '0'
|
|
110
|
+
source:
|
|
111
|
+
type: stdlib
|
|
112
|
+
- name: prism
|
|
113
|
+
version: 1.9.0
|
|
114
|
+
source:
|
|
115
|
+
type: rubygems
|
|
116
|
+
- name: rainbow
|
|
117
|
+
version: '3.0'
|
|
118
|
+
source:
|
|
119
|
+
type: git
|
|
120
|
+
name: ruby/gem_rbs_collection
|
|
121
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
122
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
123
|
+
repo_dir: gems
|
|
124
|
+
- name: rake
|
|
125
|
+
version: '13.0'
|
|
126
|
+
source:
|
|
127
|
+
type: git
|
|
128
|
+
name: ruby/gem_rbs_collection
|
|
129
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
130
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
131
|
+
repo_dir: gems
|
|
132
|
+
- name: random-formatter
|
|
133
|
+
version: '0'
|
|
134
|
+
source:
|
|
135
|
+
type: stdlib
|
|
136
|
+
- name: rbs
|
|
137
|
+
version: 4.0.3
|
|
138
|
+
source:
|
|
139
|
+
type: rubygems
|
|
140
|
+
- name: rbs-inline
|
|
141
|
+
version: 0.14.0
|
|
142
|
+
source:
|
|
143
|
+
type: rubygems
|
|
144
|
+
- name: rdoc
|
|
145
|
+
version: '0'
|
|
146
|
+
source:
|
|
147
|
+
type: stdlib
|
|
148
|
+
- name: regexp_parser
|
|
149
|
+
version: '2.8'
|
|
150
|
+
source:
|
|
151
|
+
type: git
|
|
152
|
+
name: ruby/gem_rbs_collection
|
|
153
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
154
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
155
|
+
repo_dir: gems
|
|
156
|
+
- name: rubocop
|
|
157
|
+
version: '1.57'
|
|
158
|
+
source:
|
|
159
|
+
type: git
|
|
160
|
+
name: ruby/gem_rbs_collection
|
|
161
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
162
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
163
|
+
repo_dir: gems
|
|
164
|
+
- name: rubocop-ast
|
|
165
|
+
version: '1.46'
|
|
166
|
+
source:
|
|
167
|
+
type: git
|
|
168
|
+
name: ruby/gem_rbs_collection
|
|
169
|
+
revision: fd96033ab2a1d6d3cbb5a7a993ba3d52877c81d7
|
|
170
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
171
|
+
repo_dir: gems
|
|
172
|
+
- name: rubocop-rbs_inline
|
|
173
|
+
version: 1.5.5
|
|
174
|
+
source:
|
|
175
|
+
type: rubygems
|
|
176
|
+
- name: securerandom
|
|
177
|
+
version: '0'
|
|
178
|
+
source:
|
|
179
|
+
type: stdlib
|
|
180
|
+
- name: stringio
|
|
181
|
+
version: '0'
|
|
182
|
+
source:
|
|
183
|
+
type: stdlib
|
|
184
|
+
- name: strscan
|
|
185
|
+
version: '0'
|
|
186
|
+
source:
|
|
187
|
+
type: stdlib
|
|
188
|
+
- name: tsort
|
|
189
|
+
version: '0'
|
|
190
|
+
source:
|
|
191
|
+
type: stdlib
|
|
192
|
+
- name: uri
|
|
193
|
+
version: '0'
|
|
194
|
+
source:
|
|
195
|
+
type: stdlib
|
|
196
|
+
gemfile_lock_path: Gemfile.lock
|
data/rbs_collection.yaml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Download sources
|
|
2
|
+
sources:
|
|
3
|
+
- type: git
|
|
4
|
+
name: ruby/gem_rbs_collection
|
|
5
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
6
|
+
revision: main
|
|
7
|
+
repo_dir: gems
|
|
8
|
+
|
|
9
|
+
# You can specify local directories as sources also.
|
|
10
|
+
# - type: local
|
|
11
|
+
# path: path/to/your/local/repository
|
|
12
|
+
|
|
13
|
+
# A directory to install the downloaded RBSs
|
|
14
|
+
path: .gem_rbs_collection
|
|
15
|
+
|
|
16
|
+
# gems:
|
|
17
|
+
# # If you want to avoid installing rbs files for gems, you can specify them here.
|
|
18
|
+
# - name: GEM_NAME
|
|
19
|
+
# ignore: true
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Generated from lib/rubocop/cop/style/prefer_numbered_parameter.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Style
|
|
6
|
+
# Recommends using numbered parameters (`_1`, `_2`) instead of
|
|
7
|
+
# named block arguments in single-line blocks with few arguments.
|
|
8
|
+
#
|
|
9
|
+
# @example
|
|
10
|
+
# # bad
|
|
11
|
+
# users.map { |user| user.name }
|
|
12
|
+
# items.select { |item| item.active? }
|
|
13
|
+
#
|
|
14
|
+
# # good
|
|
15
|
+
# users.map { _1.name }
|
|
16
|
+
# items.select { _1.active? }
|
|
17
|
+
#
|
|
18
|
+
# # good - multi-line block (not targeted)
|
|
19
|
+
# users.map do |user|
|
|
20
|
+
# user.name
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
# @example MaxArguments: 2
|
|
24
|
+
# # bad
|
|
25
|
+
# hash.each { |key, value| "#{key}: #{value}" }
|
|
26
|
+
#
|
|
27
|
+
# # good
|
|
28
|
+
# hash.each { "#{_1}: #{_2}" }
|
|
29
|
+
class PreferNumberedParameter < Base
|
|
30
|
+
extend AutoCorrector
|
|
31
|
+
|
|
32
|
+
MSG: ::String
|
|
33
|
+
|
|
34
|
+
# @rbs node: RuboCop::AST::BlockNode
|
|
35
|
+
def on_block: (RuboCop::AST::BlockNode node) -> void
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
# @rbs corrector: RuboCop::Cop::Corrector
|
|
40
|
+
# @rbs node: RuboCop::AST::BlockNode
|
|
41
|
+
def autocorrect: (RuboCop::Cop::Corrector corrector, RuboCop::AST::BlockNode node) -> void
|
|
42
|
+
|
|
43
|
+
# @rbs node: RuboCop::AST::Node?
|
|
44
|
+
def collect_lvar_nodes: (RuboCop::AST::Node? node) -> Array[RuboCop::AST::Node]
|
|
45
|
+
|
|
46
|
+
def max_arguments: () -> Integer
|
|
47
|
+
|
|
48
|
+
# @rbs node: RuboCop::AST::BlockNode
|
|
49
|
+
def special_arguments?: (RuboCop::AST::BlockNode node) -> bool
|
|
50
|
+
|
|
51
|
+
# @rbs node: RuboCop::AST::Node?
|
|
52
|
+
def contains_inner_block?: (RuboCop::AST::Node? node) -> bool
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Generated from lib/rubocop/numbered/params/plugin.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Rubocop
|
|
4
|
+
module Numbered
|
|
5
|
+
module Params
|
|
6
|
+
class Plugin < LintRoller::Plugin
|
|
7
|
+
# @rbs override
|
|
8
|
+
def about: ...
|
|
9
|
+
|
|
10
|
+
# @rbs override
|
|
11
|
+
def supported?: ...
|
|
12
|
+
|
|
13
|
+
# @rbs override
|
|
14
|
+
def rules: ...
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
# Generated from lib/rubocop/numbered/params.rb with RBS::Inline
|
|
2
|
+
|
|
1
3
|
module Rubocop
|
|
2
4
|
module Numbered
|
|
3
5
|
module Params
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
class Error < StandardError
|
|
7
|
+
end
|
|
6
8
|
end
|
|
7
9
|
end
|
|
8
10
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-numbered-params
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Takeshi KOMIYA
|
|
@@ -46,17 +46,25 @@ extra_rdoc_files: []
|
|
|
46
46
|
files:
|
|
47
47
|
- ".claude/hooks/session-start.sh"
|
|
48
48
|
- ".claude/settings.json"
|
|
49
|
+
- ".vscode/extensions.json"
|
|
50
|
+
- ".vscode/settings.json"
|
|
49
51
|
- CHANGELOG.md
|
|
50
52
|
- CODE_OF_CONDUCT.md
|
|
51
53
|
- LICENSE.txt
|
|
52
54
|
- README.md
|
|
53
55
|
- Rakefile
|
|
56
|
+
- Steepfile
|
|
54
57
|
- config/default.yml
|
|
55
58
|
- lib/rubocop/cop/style/prefer_numbered_parameter.rb
|
|
56
59
|
- lib/rubocop/numbered/params.rb
|
|
57
60
|
- lib/rubocop/numbered/params/plugin.rb
|
|
58
61
|
- lib/rubocop/numbered/params/version.rb
|
|
62
|
+
- rbs_collection.lock.yaml
|
|
63
|
+
- rbs_collection.yaml
|
|
64
|
+
- sig/rubocop/cop/style/prefer_numbered_parameter.rbs
|
|
59
65
|
- sig/rubocop/numbered/params.rbs
|
|
66
|
+
- sig/rubocop/numbered/params/plugin.rbs
|
|
67
|
+
- sig/rubocop/numbered/params/version.rbs
|
|
60
68
|
homepage: https://github.com/tk0miya/rubocop-numbered-params
|
|
61
69
|
licenses:
|
|
62
70
|
- MIT
|
|
@@ -80,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
80
88
|
- !ruby/object:Gem::Version
|
|
81
89
|
version: '0'
|
|
82
90
|
requirements: []
|
|
83
|
-
rubygems_version: 4.0.
|
|
91
|
+
rubygems_version: 4.0.10
|
|
84
92
|
specification_version: 4
|
|
85
93
|
summary: A RuboCop plugin to lint numbered parameters
|
|
86
94
|
test_files: []
|