Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
preview gate
  • Loading branch information
ntBre committed Feb 9, 2026
commit 1a4471c7ea34a97e9e5f1efef9d374ed21499e29
5 changes: 5 additions & 0 deletions crates/ruff_linter/src/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,8 @@ pub(crate) const fn is_standalone_mock_non_existent_enabled(settings: &LinterSet
pub(crate) const fn is_up024_precise_highlighting_enabled(settings: &LinterSettings) -> bool {
settings.preview.is_enabled()
}

// https://github.com/astral-sh/ruff/pull/21078
pub(crate) const fn is_plural_ngettext_check_enabled(settings: &LinterSettings) -> bool {
settings.preview.is_enabled()
}
8 changes: 7 additions & 1 deletion crates/ruff_linter/src/rules/flake8_gettext/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Rules from [flake8-gettext](https://pypi.org/project/flake8-gettext/).
use crate::checkers::ast::Checker;
use crate::preview::is_extended_i18n_function_matching_enabled;
use crate::preview::{
is_extended_i18n_function_matching_enabled, is_plural_ngettext_check_enabled,
};
use ruff_python_ast::name::Name;
use ruff_python_ast::{self as ast, Expr};
use ruff_python_semantic::Modules;
Expand All @@ -10,6 +12,10 @@ pub mod settings;

/// Returns true if the function call is ngettext
pub(crate) fn is_ngettext_call(checker: &Checker, func: &Expr) -> bool {
if !is_plural_ngettext_check_enabled(checker.settings()) {
return false;
}

// Check direct name reference first (e.g., `ngettext(...)`)
if let Some(name) = func.as_name_expr() {
if name.id == "ngettext" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ INT001 f-string is resolved before function call; consider `_("string %s") % arg
9 | _gettext(f"{'value'}") # no lint
|

INT001 f-string in plural argument is resolved before function call
--> INT001.py:7:24
|
6 | gettext(f"{'value'}")
7 | ngettext(f"{'value'}", f"{'values'}", 2)
| ^^^^^^^^^^^^^
8 |
9 | _gettext(f"{'value'}") # no lint
|

INT001 f-string is resolved before function call; consider `_("string %s") % arg`
--> INT001.py:31:14
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ INT002 `format` method argument is resolved before function call; consider `_("s
5 | _gettext("{}".format("line")) # no lint
|

INT002 `format` method in plural argument is resolved before function call
--> INT002.py:3:31
|
1 | _("{}".format("line"))
2 | gettext("{}".format("line"))
3 | ngettext("{}".format("line"), "{}".format("lines"), 2)
| ^^^^^^^^^^^^^^^^^^^^
4 |
5 | _gettext("{}".format("line")) # no lint
|

INT002 `format` method argument is resolved before function call; consider `_("string %s") % arg`
--> INT002.py:27:14
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ INT003 printf-style format is resolved before function call; consider `_("string
5 | _gettext("%s" % "line") # no lint
|

INT003 printf-style format in plural argument is resolved before function call
--> INT003.py:3:25
|
1 | _("%s" % "line")
2 | gettext("%s" % "line")
3 | ngettext("%s" % "line", "%s" % "lines", 2)
| ^^^^^^^^^^^^^^
4 |
5 | _gettext("%s" % "line") # no lint
|

INT003 printf-style format is resolved before function call; consider `_("string %s") % arg`
--> INT003.py:27:14
|
Expand Down
Loading