Skip to content

Enforce parentheses on method calls with arguments - #761

Merged
anakinj merged 1 commit into
jwt:mainfrom
anakinj:style/method-call-parentheses
Sep 5, 2026
Merged

Enforce parentheses on method calls with arguments#761
anakinj merged 1 commit into
jwt:mainfrom
anakinj:style/method-call-parentheses

Conversation

@anakinj

@anakinj anakinj commented Sep 5, 2026

Copy link
Copy Markdown
Member

Description

Style/MethodCallWithArgsParentheses is off by default, so the codebase had drifted both ways — JWT.encode payload, nil, alg sitting next to JWT.encode(payload, nil, alg), with the paren-less form concentrated in the older specs. This enables the cop and applies it.

Style/MethodCallWithArgsParentheses:
  Enabled: true
  Exclude:
    - "*.gemspec"
  AllowedMethods:
    - raise
    - fail
    - yield
    - to
    - not_to
    - to_not
    - describe
    - context
    - it
    - specify

What is deliberately left alone

raise and fail. raise Foo, 'msg' is about as idiomatic as paren-less Ruby gets, and enforcing parentheses on it accounted for 67 of the 100 changed lines in lib/ — all of it in the claims and crypto files, for a style nobody asked for. The codebase is already mixed here (crit.rb and jwt_id.rb use parentheses, audience.rb and expiration.rb do not) and stays that way, unenforced. Exempting these is what takes lib/ from 100 changed lines down to 7.

yield. A keyword that reads like one; yield('msg') is no clearer than yield 'msg'.

The gemspec. spec.add_dependency 'base64' is the universal form and the whole file is a DSL. Metrics/BlockLength already excludes it.

The RSpec matcher DSL. Without the exemptions the autocorrect produces RSpec.describe(JWT) and expect(x).to(eq(y)), which is worse than what it replaces.

Scope

21 files, 226 insertions / 225 deletions. lib/ is down to four calls:

exported.reject! { |k, _| EC_PRIVATE_KEY_ELEMENTS.include? k }   ->  .include?(k)   (x3)
l = a.unpack "C#{a.bytesize}"                                    ->  a.unpack("C#{a.bytesize}")

The one hand-written part

Everything else is rubocop -a output, except five arrays in spec/integration/readme_examples_spec.rb. Adding parentheses there made Layout/FirstArrayElementIndentation push the elements out to a 36 column hanging indent:

expect(decoded_token).to eq([
                              { 'data' => 'test' },
                              { 'alg' => 'none' }
                            ])

They are collapsed onto one line instead. Switching Layout/FirstArrayElementIndentation to consistent was the other way to fix that, but it restyles 14 places to fix 5.

Verification

  • 644 examples, 0 failures. RuboCop clean, 93 files, no offenses.
  • Syntactic only: no method call changes arity, receiver or arguments.

Checklist

Before the PR can be merged be sure the following are checked:

  • There are tests for the fix or feature added/changed — n/a, no behaviour change
  • A description of the changes and a reference to the PR has been added to CHANGELOG.md — skipped, style-only with no effect on the published gem

@anakinj
anakinj force-pushed the style/method-call-parentheses branch from c5f053b to 5568365 Compare September 5, 2026 19:44
Style/MethodCallWithArgsParentheses is off by default, so the codebase
had drifted both ways: JWT.encode payload, nil, alg next to
JWT.encode(payload, nil, alg), with the paren-less form concentrated in
the older specs.

Exempted rather than normalised:

raise and fail, because raise Foo, 'msg' is about as idiomatic as
paren-less Ruby gets, and enforcing parentheses there accounted for 67 of
the 100 changed lines in lib, all of it in the claims and crypto files.
The codebase is already mixed on this and stays that way.

yield, which is a keyword and reads like one.

The gemspec, because add_dependency 'base64' is the universal form and
the whole file is a DSL. Metrics/BlockLength already excludes it.

The RSpec matcher DSL, so expect(x).to eq(y) does not become
expect(x).to(eq(y)).

What is left in lib is four calls: three include? k and one unpack.
Everything is rubocop -a output apart from five arrays in
readme_examples_spec, where the added parentheses pushed the elements out
to a 36 column hanging indent; those are collapsed onto one line.
@anakinj
anakinj force-pushed the style/method-call-parentheses branch from 5568365 to 44fec9d Compare September 5, 2026 19:47
@anakinj
anakinj merged commit 6cdacc3 into jwt:main Sep 5, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant