Skip to content

fix(ruby): fix RuboCop Lint/Void and Naming/VariableNumber offenses in generated SDKs#14115

Open
fern-support wants to merge 6 commits intomainfrom
devin/1774538295-fix-ruby-sdk-rubocop-offenses
Open

fix(ruby): fix RuboCop Lint/Void and Naming/VariableNumber offenses in generated SDKs#14115
fern-support wants to merge 6 commits intomainfrom
devin/1774538295-fix-ruby-sdk-rubocop-offenses

Conversation

@fern-support
Copy link
Copy Markdown
Collaborator

@fern-support fern-support commented Mar 26, 2026

Description

Fixes RuboCop violations in generated Ruby SDKs that cause CI lint failures (e.g., fern-demo/schematic-test-ruby).

Changes Made

1. Fix Lint/Void offenses in template files

  • boolean.Template.rb: Added return before bare value in the when TrueClass, FalseClass branch (line 20). Other branches already used explicit return, making this one fall into void context.
  • utils.Template.rb: Added return before bare value on the else branches of the pattern-matching case (lines 84, 87). Without return, these are dead expressions since the method continues to the raise and final value below.

2. Fix Naming/VariableNumber offenses in field name generation

  • The generated .rubocop.yml enforces Naming/VariableNumber: normalcase (since v1.0.0-rc86), which disallows underscores before digits (e.g., account_last_4 should be account_last4).
  • The IR's snakeCase.safeName can produce names like account_last_4 when the casing generator doesn't use smart casing, or the input triggers word-boundary splitting before digits.
  • Added normalizeVariableNumber() using regex /([a-zA-Z\d])_(?=\d)/g to strip underscores before digit sequences, applied in:
    • generateFields.ts — model field symbols
    • DynamicSnippetsGeneratorContext.ts — property names in generated snippets
    • DynamicToLiteralMapper.ts — object property names in snippet literal conversion
  • Wire values (api_name) are unaffected, preserving correct serialization.
  • The regex uses a lookahead (?=\d) to correctly handle consecutive digit groups (e.g., test_1_2_3test123) and preserves leading underscores and digit-preceded underscores (e.g., _3_d stays _3_d).

3. Version bump

  • Added v1.1.4 entry to generators/ruby-v2/sdk/versions.yml with changelog entries for both fixes.

Human Review Checklist

  • Regex /([a-zA-Z\d])_(?=\d)/g breadth: This strips underscores before digits when preceded by a letter or digit. This matches RuboCop's normalcase expectation, but verify edge cases (e.g., v_2v2, x_1_2x12).
  • normalizeVariableNumber is duplicated 3 times across packages. Consider whether it should be extracted into a shared utility (e.g., @fern-api/ruby-base).
  • getMethodName in DynamicSnippetsGeneratorContext.ts was intentionally NOT updated — only getPropertyName was. Confirm method names don't need the same normalization.
  • No unit tests were added for normalizeVariableNumber. Consider adding tests for edge cases (_3_d, account_last_4, test_1_2_3, names with no digits).

Testing

  • Unit tests added/updated
  • pnpm run check (biome lint) passes
  • Seed test snapshots may need regeneration — initial run showed reserved-keywords fixture failure due to overly aggressive regex (fixed in subsequent commit)

Link to Devin session: https://app.devin.ai/sessions/d1bd30a5218f438db2821cdb6222fcd0
Requested by: @cdonel707

…n generated SDKs

Co-Authored-By: Chris McDonnell <chris@buildwithfern.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review.

Tip: disable this comment in your organization's Code Review settings.

@github-actions
Copy link
Copy Markdown
Contributor

🌱 Seed Test Selector

Select languages to run seed tests for:

  • Python
  • TypeScript
  • Java
  • Go
  • Ruby
  • C#
  • PHP
  • Swift
  • Rust
  • OpenAPI
  • Postman

How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR.

… style names

Co-Authored-By: Chris McDonnell <chris@buildwithfern.com>
Comment on lines +17 to +19
function normalizeVariableNumber(name: string): string {
return name.replace(/([a-zA-Z])_(\d)/g, "$1$2");
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normalizeVariableNumber regex only removes the underscore before the first digit in a sequence, not all underscores before digits. For example:

  • test_1_2_3 becomes test1_2_3 (only first _1 normalized, _2_3 remain)
  • account_id_123_test becomes account_id123_test (only d_1 normalized)

This creates inconsistent normalization and may still trigger RuboCop violations. The regex needs to handle multiple digit groups:

return name.replace(/([a-zA-Z])_(?=\d)/g, "$1");

This uses a lookahead (?=\d) instead of capturing the digit, allowing the regex engine to continue matching subsequent letter-underscore-digit patterns in the same string.

Suggested change
function normalizeVariableNumber(name: string): string {
return name.replace(/([a-zA-Z])_(\d)/g, "$1$2");
}
function normalizeVariableNumber(name: string): string {
return name.replace(/([a-zA-Z\d])_(?=\d)/g, "$1");
}

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Updated the regex to ([a-zA-Z\d])_(?=\d) in all three files — this handles consecutive digit groups like test_1_2_3test123 correctly. Pushed in cc5483a.

devin-ai-integration Bot and others added 4 commits March 26, 2026 16:04
…e digit groups

Co-Authored-By: Chris McDonnell <chris@buildwithfern.com>
Co-Authored-By: Chris McDonnell <chris@buildwithfern.com>
Co-Authored-By: Chris McDonnell <chris@buildwithfern.com>
Co-Authored-By: Chris McDonnell <chris@buildwithfern.com>
Comment on lines 3 to 26
@@ -8,7 +24,6 @@
type: chore
createdAt: "2026-03-27"
irVersion: 61
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version chronology is incorrect. Version 1.1.7 shows createdAt: "2026-03-26" while version 1.1.6 shows createdAt: "2026-03-27". Since 1.1.7 is a higher version number than 1.1.6, it should have been created after, not before.

This will cause issues:

  • Semantic versioning violation (newer version created earlier)
  • Potential confusion in release ordering and changelogs
  • Breaking assumptions about version progression

Fix: Change 1.1.7's createdAt to "2026-03-27" or later, or reconsider the version numbering if 1.1.6 was meant to be the newer release.

Suggested change
- version: 1.1.7
changelogEntry:
- summary: |
Fix RuboCop `Lint/Void` offenses in generated `boolean.rb` and `utils.rb` internal
type files. Bare `value` expressions in `case/when` branches and fallthrough paths
now use explicit `return value` to avoid void-context warnings.
type: fix
- summary: |
Fix RuboCop `Naming/VariableNumber` offenses for model field names containing digits.
Field names like `account_last_4` are now normalized to `account_last4` to match
the `normalcase` style enforced by the generated `.rubocop.yml`. The wire value
is preserved via the `api_name` parameter for correct serialization.
type: fix
createdAt: "2026-03-27"
irVersion: 61
- version: 1.1.6
changelogEntry:
- summary: |
type: chore
createdAt: "2026-03-27"
irVersion: 61

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants