Skip to content

fix(ruby): read parenthesised add_dependency calls in a .gemspec - #685

Open
hamid-digitalmarketer wants to merge 1 commit into
vibgrate:mainfrom
hamid-digitalmarketer:fix/gemspec-parenthesised-dependencies
Open

hamid-digitalmarketer wants to merge 1 commit into
vibgrate:mainfrom
hamid-digitalmarketer:fix/gemspec-parenthesised-dependencies

Conversation

@hamid-digitalmarketer

Copy link
Copy Markdown
Contributor

What

parseGemspec in src/core-open/scanners/ruby-scanner.ts only matched the whitespace call style:

spec.add_dependency "rails", "~> 7.1"      # read
spec.add_dependency("rails", "~> 7.1")     # silently dropped

Both forms are valid Ruby and the parenthesised one is common in generated and RuboCop-formatted gemspecs. Because the regex required \s+ between the method name and the first quote, every parenthesised dependency produced no row at all — it never reached drift, exposure or the runtime rows.

Fix

Accept either style after the method name:

-  /\.add_(runtime_|development_)?dependency\s+['"]([^'"]+)['"]/
+  /\.add_(runtime_|development_)?dependency(?:\s+|\s*\(\s*)['"]([^'"]+)['"]/

quotedVersionConstraints already stops at the closing paren, so every quoted bound is still kept and drift still resolves from the lower bound. No behaviour change for the whitespace style.

Tests

New test/ruby-gemspec-parenthesised.test.ts (4 tests) covers a gemspec mixing both styles:

  • all five dependency rows are present (add_dependency, add_runtime_dependency, add_development_dependency, with and without a version)
  • multi-bound parenthesised specs are kept and joined: >= 2.2, < 4 → resolves 2.2.0, major-behind
  • a parenthesised add_development_dependency lands in devDependencies
  • a parenthesised call with no constraint still creates a row (unknown drift)

Before the change all 4 tests fail (rows missing); after it they pass.

npx vitest run test/ruby-gemfile-groups.test.ts test/ruby-gemfile-inline-groups.test.ts \
  test/ruby-gemfile-nested-blocks.test.ts test/ruby-runtime-pin.test.ts \
  test/ruby-version-constraints.test.ts test/ruby-gemspec-parenthesised.test.ts
→ Test Files 6 passed (6) | Tests 22 passed (22)

npx eslint src/core-open/scanners/ruby-scanner.ts is clean. npx tsc --noEmit reports only the pre-existing onnxruntime-node typing gap in src/vendor/fastembed/index.ts (optional dependency not installed locally), nothing from this change.

Fixes #623.

Contributor contact: +92 316 7417135

parseGemspec only matched the whitespace call style
(`spec.add_dependency "rails", "~> 7.1"`), so a gemspec that uses the
equally valid parenthesised style (`spec.add_dependency("rails", "~> 7.1")`)
produced no dependency rows at all: no drift, no exposure, no runtime.

Accept either whitespace or a parenthesised argument list after the method
name. quotedVersionConstraints already skips a closing paren, so every
quoted bound is still kept and drift still resolves from the lower bound.

Refs vibgrate#623
hamid-digitalmarketer pushed a commit to hamid-digitalmarketer/hamid-digitalmarketer that referenced this pull request Nov 14, 2026
- merged 43 (was 39), open 67 (was 70), closed-unmerged 52 (was 51)
- upstream projects 22 (was 20): added markline-dev/markline#56 and
  adbar/trafilatura#1086 to the table and the recent-merges list
- in-review section points at the current queue (vibgrate/cli#685)
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.

Bug: gemspec dependencies written with parentheses, like add_dependency("rails", ">= 7"), are dropped

2 participants