[flake8-gettext] Fix false negatives for plural argument of ngettext (INT001, INT002, INT003)
#21078
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.
Summary
Fixes #21062. Extends the
INT001,INT002, andINT003lint rules to check both the singular and plural arguments ofngettextfunction 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, andprintf-in-get-text-func-call) only checked the first argument (singular) ofngettextcalls 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:
args.first()ngettextvsgettextargs.get(1)(the second argument)Example of the bug:
Approach
funcparameteris_ngettext_call()helper that checks:ngettext(...))ngettext(e.g.,gettext_mod.ngettext(...))ngettextcalls, now check both first and second argumentshelpers.rsmodule to eliminate duplicationfuncparameter