Modernize chronic for the current Ruby ecosystem#433
Open
dior001 wants to merge 1 commit into
Open
Conversation
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.
NecroRuby has revived
chronicNecroRuby is a bot that brings quality open-source Ruby libraries
up-to-date with the modern Ruby ecosystem — upgrading dependencies,
restoring test coverage, tightening security, and improving documentation
for gems whose last release is over a year old.
NecroRuby is a fully autonomous process and is capable of mistakes. If you
disagree with any of these changes, just say so on this PR (or close it) and
NecroRuby will move on. If you have questions, ask here — NecroRuby monitors
this PR and will respond.
Modernized and tested on Ruby 4.0.6, the latest Ruby release.
Chronic Modernization Report
This pull request modernizes Chronic (natural-language date/time parser)
so it installs, runs, tests clean, and lints clean on Ruby 4.0.6 while
keeping the public API and parsing behavior unchanged.
Everything below was verified on Ruby 4.0.6 (
ruby -v→ruby 4.0.6).Summary
minimum_coverage)required_ruby_version >= 3.0,.ruby-version= 4.0.61. Dependencies
Runtime and development dependencies were moved to current, maintained
versions and the gemspec was cleaned of removed/deprecated RubyGems APIs.
~> 0.2~> 0.2add_dependency.>= 10>= 13.0~> 5.0>= 5.19~> 0~> 0.22>= 4.0>= 6.0~> 1.79(added)~> 0.9(added, Gemfile dev/test group)Gemspec hygiene:
s.rubyforge_project=— the setter was removed from modern RubyGemsand made the gemspec unloadable.
s.test_files=— deprecated and warned on every gem operation.add_runtime_dependency→add_dependency.required_ruby_version = '>= 3.0',require_paths, and ametadatablock (
source_code_uri,changelog_uri,bug_tracker_uri,rubygems_mfa_required).s.filesnow splits on"\n"instead of the$/global.bundle installandgem build chronic.gemspecboth succeed cleanly.2. Ruby 4.0.6 compatibility fixes
MiniTest→Minitest. minitest 6 removed the long-deprecatedMiniTestconstant; the test base class now subclassesMinitest::Test.# frozen_string_literal: trueto everyRuby file. The
#to_shelpers built strings by mutating string literals(
super << '-day','(' << ... << ')'), which raises under frozen stringliterals; these were rewritten with interpolation (
"#{super}-day").Chronic.constructdropped the unreachableRUBY_VERSION.to_f < 1.9condition (kept the
ActiveSupport::TimeZone/#localpath).Spandroppedalias cover? include? if RUBY_VERSION =~ /^1.8/(
Range#cover?is native on all supported Rubies).Parser#pre_normalizedropped a deadelsebranch in the two-digit-yearexpansion (a two-digit capture is always a plausible year).
(which
requireschronic/version), soChronicis already defined beforethe tests run. The old
unless defined? Chronicguard intest/helper.rbtherefore skipped loading the real library. The helper now requires
chronicunconditionally, andSimpleCov.startruns before the library isloaded so coverage is actually measured.
Rake::TestTaskinstead of hand-rolledDir.globrequires (the old version pre-required
chronic, which defeated coverage).-w) intags/scalar.rb.Explicit target declaration
.ruby-version→4.0.6.required_ruby_version→>= 3.0(the genuine floor: no 3.x/4.0-onlysyntax is used, and the suite passes across the range).
.github/workflows/test.yaml) to3.0, 3.1, 3.2, 3.3, 3.4, 4.0plus JRuby/TruffleRuby, and two new jobs were added: RuboCopand bundler-audit.
3. Tests & coverage
SimpleCov.minimum_coverage line: 100intest/helper.rb(branch coverageis also tracked for information; the ~12% of unhit branches are unreachable
implicit
elsearms ofcase pointerstatements).test/test_coverage.rb— tokenizer/token/season/date helpers, theabstract-method guards (
Tag.scan,Repeater#width,Definitions),handler pattern errors, the unknown-grabber guard, and every handler's
"invalid date" rescue path (driven by a stub time class whose
constructors raise).
test/test_to_s.rb— the#to_sdebug representation of every Tag andRepeater subclass.
test/test_repeater_branches.rb— repeater widths, offsets, and theless-common
this/nextpointers.TestChronic#test_activesupport, which had been commented outwith a stale note about a MiniTest 4.2 conflict; it now runs against
ActiveSupport 8.x and exercises the
Chronic.time_class = Time.zonepath.The full suite passes in multiple time zones (
TZ=UTC, default).4. Documentation
install snippet, a Development section (test/lint/audit commands),
modernized all
:key => valueexamples tokey:syntax, and turned thetime-zone example into runnable Ruby.
lacked it (
MiniDate,Season,Chronic::Date,Chronic::Time,Token,Tokenizer,Handler) and documented the behavior-affecting code changes.5. Lint / formatting
.rubocop.yml(TargetRubyVersion: 3.0,NewCops: enable). Complexity/size metrics are disabled because Chronic'stokenizer/handlers are inherently long and branchy — enforcing them would
require a rewrite out of scope for a compatibility pass. A few cops that
would force breaking API changes (
Style/OptionalBooleanParameter,Naming/PredicatePrefix) or noisy churn (Naming/VariableNumber) aredisabled with rationale in the config.
(converted two
@@class_varsto class instance variables, documented oneintentional
Lint/MissingSuper, broke a long line).bundle exec rubocopnow reports no offenses, and the suite still passes at 100% coverage
after autocorrection.
6. Security
bundle exec bundle-audit check --updateagainst the currentruby-advisory-db (1,224 advisories): no vulnerabilities found.
is not applicable to a pure parsing library; it was not added.
Chronic.const_get,Object#sendin
handler.rb/dictionary.rb/tags/repeater.rb): all operate oninternal, developer-defined constant/method names from the handler
definitions and fixed lookup tables — never on user-supplied input — so
there is no injection surface.
Design notes
return types are identical. All edits are compatibility, formatting,
documentation, or test additions.
branches; the residual branches are defensive
case/whenarms that cannotbe reached with the values the parser actually produces.
🤖 Opened automatically by NecroRuby, an UpWoof.ai service.