Skip to content

Add RuboCop - #22

Merged
d-mato merged 2 commits into
masterfrom
add-rubocop
Aug 28, 2026
Merged

d-mato merged 2 commits into
masterfrom
add-rubocop

Conversation

@d-mato

@d-mato d-mato commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Adds RuboCop and brings the tree in line with it. The config is kept to what this repository actually needs.

# TargetRubyVersion is left unset on purpose: RuboCop reads it from
# required_ruby_version in the gemspec, which ranks above .ruby-version.
AllCops:
  NewCops: enable

Style/StringLiterals:
  EnforcedStyle: double_quotes

Metrics/BlockLength:
  Exclude:
    - spec/**/*

Three deliberate departures from what bundle gem generates:

  • No TargetRubyVersion. RuboCop::TargetRuby::SOURCES orders GemspecFile above RubyVersionFile, so required_ruby_version in the gemspec wins over .ruby-version. rubocop -V confirms it: analyzing as Ruby 3.3, not 4.0.6. Writing the version here would duplicate the gemspec and quietly drift from it.
  • No Style/StringLiteralsInInterpolation. There is no interpolated string literal in the tree for it to govern.
  • NewCops: enable. Without it every run prints a growing list of pending cops. With it the config never needs editing to stay current; a RuboCop bump that introduces failures shows up in its own Dependabot PR.

Style/StringLiterals is set to double quotes because the tree is already 72 double to 19 single. RuboCop defaults to single, which would have rewritten the gemspec added in #21.

RuboCop got one wrong

Security/JSONLoad is an unsafe autocorrection and it broke the gem:

JSON.parse(File.open(File.join(__dir__, "data", "emoji_ja.json")))
# => TypeError: no implicit conversion of File into String

JSON.load accepts an IO, JSON.parse does not. The dictionary is read with File.read instead, which also closes the handle File.open was leaking. Every public method raised TypeError before this was corrected.

Not addressed here

Style/TrailingCommaInArrayLiteral removed the trailing comma in tasks/data.rake, leaving the commented-out entries below it comma-fragile — uncommenting one now yields a syntax error. Those entries have been commented out since 2020; deleting them is probably better than configuring around them, but that is a separate call.

Verification

rubocop: 9 files inspected, no offenses. Suite green locally (11 examples) and gem bump is unaffected — gem-release matches VERSION\s*=\s*("|) anywhere in the file, so the added magic comment does not interfere.

d-mato added 2 commits August 29, 2026 00:59
TargetRubyVersion is deliberately left out of .rubocop.yml. RuboCop
resolves it from a gemspec's required_ruby_version before it looks at
.ruby-version, so the supported range stays declared in one place and
cannot drift.

Style/StringLiterals is set to double quotes because that is what most
of the tree already uses; RuboCop defaults to single. NewCops is
enabled so the config does not need editing to stay current.

Metrics/BlockLength is excluded for spec/, where a describe block is
always over the limit.
Mostly autocorrections: double quoted strings, frozen_string_literal
comments, each_value in place of each with an unused argument, to_h
with a block, a blank line after a guard clause.

A few needed a hand:

- The gemspec description ran one line over the length limit.
- Style/Documentation wanted a comment on Emoja and on Dictionary.
- Security/JSONLoad rewrote JSON.load to JSON.parse, but JSON.parse
  does not accept an IO and the gem raised TypeError on first use. The
  dictionary is read with File.read now, which also closes the handle
  File.open was leaking.
@d-mato
d-mato merged commit 77c16ff into master Aug 28, 2026
4 checks passed
@d-mato
d-mato deleted the add-rubocop branch August 28, 2026 16:10
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