rubocop-numbered-params 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e6736396b22b8136265688409f5eedf51499d99c5ef1d99a40dfd8586f383073
4
+ data.tar.gz: 9419b0424fe92cd303431ff7504840cbce5d7c3b7622a6ea08f8d5a28bf73a98
5
+ SHA512:
6
+ metadata.gz: d0275feb564c675a59df04a64c6a0302b1ec8c80df289538061d85796c59f36b4fb784404459149c5842d482fdde7dca78c8a687e75ad25335d209e486f107e5
7
+ data.tar.gz: 6a97e1375d9432a61128490604886955e8c37319535fe652ac0d7ffd05adfab87490f1fb109d90b349d1008278779058139cb5d4ca31eab52ab6118eecf47075
@@ -0,0 +1,15 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+
4
+ # Only run in Claude Code on the web (remote environment)
5
+ if [ "${CLAUDE_CODE_REMOTE:-}" != "true" ]; then
6
+ exit 0
7
+ fi
8
+
9
+ # Bundler 4.0 + Ruby 3.3 compatibility workaround:
10
+ # Bundler 4.0's vendored net-http-persistent uses CGI.unescape which
11
+ # references @@accept_charset before it's initialized in Ruby 3.3.
12
+ # Pre-loading the CGI library via RUBYOPT resolves this.
13
+ echo 'export RUBYOPT="-rcgi"' >> "$CLAUDE_ENV_FILE"
14
+
15
+ RUBYOPT="-rcgi" bundle install
@@ -0,0 +1,14 @@
1
+ {
2
+ "hooks": {
3
+ "SessionStart": [
4
+ {
5
+ "hooks": [
6
+ {
7
+ "type": "command",
8
+ "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh"
9
+ }
10
+ ]
11
+ }
12
+ ]
13
+ }
14
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-02-22
4
+
5
+ - Initial release
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "rubocop-numbered-params" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["i.tkomiya@gmail.com"](mailto:"i.tkomiya@gmail.com").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Takeshi KOMIYA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Rubocop::Numbered::Params
2
+
3
+ TODO: Delete this and the text below, and describe your gem
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.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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/[USERNAME]/rubocop-numbered-params/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ 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/[USERNAME]/rubocop-numbered-params/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ Style/PreferNumberedParameter:
2
+ Description: 'Prefer numbered parameters (`_1`, `_2`) for single-line blocks.'
3
+ Enabled: true
4
+ VersionAdded: '1.0'
5
+ MaxArguments: 1
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
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
+ #
30
+ class PreferNumberedParameter < Base
31
+ extend AutoCorrector
32
+
33
+ MSG = "Use numbered parameters (`_1`, `_2`, ...) instead of named block arguments " \
34
+ "for single-line blocks."
35
+
36
+ def on_block(node)
37
+ return unless node.single_line?
38
+ return if node.arguments.empty?
39
+ return if node.arguments.count > max_arguments
40
+ return if node.body.nil?
41
+ return if special_arguments?(node)
42
+ return if contains_inner_block?(node.body)
43
+
44
+ add_offense(node) do |corrector|
45
+ autocorrect(corrector, node)
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def autocorrect(corrector, node) # rubocop:disable Metrics/AbcSize
52
+ lvar_nodes = collect_lvar_nodes(node.body)
53
+
54
+ node.arguments.each.with_index(1) do |arg, index|
55
+ numbered = "_#{index}"
56
+ lvar_nodes.select { _1.children.first == arg.name }.each do |lvar|
57
+ corrector.replace(lvar.source_range, numbered)
58
+ end
59
+ end
60
+
61
+ args_range = node.arguments.source_range
62
+ corrector.remove(args_range.resize(args_range.size + 1))
63
+ end
64
+
65
+ def collect_lvar_nodes(node)
66
+ result = []
67
+ result << node if node.lvar_type?
68
+ node.each_descendant(:lvar) { result << _1 }
69
+ result
70
+ end
71
+
72
+ def max_arguments
73
+ cop_config.fetch("MaxArguments", 1)
74
+ end
75
+
76
+ def special_arguments?(node)
77
+ node.arguments.any? do |arg|
78
+ arg.mlhs_type? || arg.restarg_type? || arg.blockarg_type? || arg.shadowarg_type?
79
+ end
80
+ end
81
+
82
+ def contains_inner_block?(node)
83
+ return false unless node
84
+
85
+ node.block_type? || node.numblock_type? || node.each_descendant(:block, :numblock).any?
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lint_roller"
4
+
5
+ module Rubocop
6
+ module Numbered
7
+ module Params
8
+ class Plugin < LintRoller::Plugin
9
+ def about
10
+ LintRoller::About.new(
11
+ name: "rubocop-numbered-params",
12
+ version: VERSION,
13
+ homepage: "https://github.com/tk0miya/rubocop-numbered-params",
14
+ description: "A RuboCop plugin that recommends using numbered parameters (_1, _2) " \
15
+ "instead of named block arguments in short blocks."
16
+ )
17
+ end
18
+
19
+ def supported?(context)
20
+ context.engine == :rubocop
21
+ end
22
+
23
+ def rules(_context)
24
+ LintRoller::Rules.new(
25
+ type: :path,
26
+ config_format: :rubocop,
27
+ value: Pathname.new(__dir__).join("../../../../config/default.yml")
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubocop
4
+ module Numbered
5
+ module Params
6
+ VERSION = "1.0.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ require_relative "params/version"
6
+ require_relative "params/plugin"
7
+ require_relative "../cop/style/prefer_numbered_parameter"
8
+
9
+ module Rubocop
10
+ module Numbered
11
+ module Params
12
+ class Error < StandardError; end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ module Rubocop
2
+ module Numbered
3
+ module Params
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-numbered-params
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Takeshi KOMIYA
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: lint_roller
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rubocop
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.72.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 1.72.1
40
+ description: A RuboCop plugin to lint numbered parameters
41
+ email:
42
+ - i.tkomiya@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".claude/hooks/session-start.sh"
48
+ - ".claude/settings.json"
49
+ - CHANGELOG.md
50
+ - CODE_OF_CONDUCT.md
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - config/default.yml
55
+ - lib/rubocop/cop/style/prefer_numbered_parameter.rb
56
+ - lib/rubocop/numbered/params.rb
57
+ - lib/rubocop/numbered/params/plugin.rb
58
+ - lib/rubocop/numbered/params/version.rb
59
+ - sig/rubocop/numbered/params.rbs
60
+ homepage: https://github.com/tk0miya/rubocop-numbered-params
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ rubygems_mfa_required: 'true'
65
+ homepage_uri: https://github.com/tk0miya/rubocop-numbered-params
66
+ source_code_uri: https://github.com/tk0miya/rubocop-numbered-params
67
+ changelog_uri: https://github.com/tk0miya/rubocop-numbered-params/blob/main/CHANGELOG.md
68
+ default_lint_roller_plugin: Rubocop::Numbered::Params::Plugin
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 3.2.0
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 4.0.3
84
+ specification_version: 4
85
+ summary: A RuboCop plugin to lint numbered parameters
86
+ test_files: []