Skip to content

Conversation

@danparizher
Copy link
Contributor

@danparizher danparizher commented Oct 26, 2025

Summary

Fixes #21062. Extends the INT001, INT002, and INT003 lint rules to check both the singular and plural arguments of ngettext function calls, fixing false negatives where formatting issues in the plural argument were not being detected.

Problem Analysis

The three rules (f-string-in-get-text-func-call, format-in-get-text-func-call, and printf-in-get-text-func-call) only checked the first argument (singular) of ngettext calls but ignored the second argument (plural). This caused false negatives when f-strings, .format() calls, or % formatting were used in the plural argument.

The root cause was:

  1. Rule functions only examined args.first()
  2. No logic to determine if a function call was specifically ngettext vs gettext
  3. Missing checks for args.get(1) (the second argument)

Example of the bug:

ngettext(f"one item", f"{n} items", n)  # Only flagged first f-string, not second

Approach

  1. Modified function signatures: Updated all three rule functions to accept the func parameter
  2. Added ngettext detection: Created is_ngettext_call() helper that checks:
    • Direct name references (e.g., ngettext(...))
    • Qualified names ending with ngettext (e.g., gettext_mod.ngettext(...))
  3. Extended argument checking: For ngettext calls, now check both first and second arguments
  4. Code refactoring: Created shared helpers.rs module to eliminate duplication
  5. Updated main checker: Modified expression analyzer to pass func parameter

@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

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.

INT false negatives for the plural argument of ngettext

1 participant