Add RuboCop - #22
Merged
Merged
Add RuboCop#22
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds RuboCop and brings the tree in line with it. The config is kept to what this repository actually needs.
Three deliberate departures from what
bundle gemgenerates:TargetRubyVersion.RuboCop::TargetRuby::SOURCESordersGemspecFileaboveRubyVersionFile, sorequired_ruby_versionin the gemspec wins over.ruby-version.rubocop -Vconfirms it:analyzing as Ruby 3.3, not 4.0.6. Writing the version here would duplicate the gemspec and quietly drift from it.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/StringLiteralsis 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/JSONLoadis an unsafe autocorrection and it broke the gem:JSON.loadaccepts an IO,JSON.parsedoes not. The dictionary is read withFile.readinstead, which also closes the handleFile.openwas leaking. Every public method raisedTypeErrorbefore this was corrected.Not addressed here
Style/TrailingCommaInArrayLiteralremoved the trailing comma intasks/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) andgem bumpis unaffected — gem-release matchesVERSION\s*=\s*("|)anywhere in the file, so the added magic comment does not interfere.