Skip to content

Commit 98fdc0e

Browse files
authored
[flake8-executables] Allow uv run in shebang line for shebang-missing-python (EXE003) (#16849)
Skip the lint for [shebang-missing-python (EXE003)](https://docs.astral.sh/ruff/rules/shebang-missing-python/#shebang-missing-python-exe003) if we find `uv run` on the shebang line. Closes #13021
1 parent 8619317 commit 98fdc0e

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env -S uv run
2+
print("hello world")
3+

crates/ruff_linter/src/rules/flake8_executable/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mod tests {
2121
#[test_case(Path::new("EXE002_2.py"))]
2222
#[test_case(Path::new("EXE002_3.py"))]
2323
#[test_case(Path::new("EXE003.py"))]
24+
#[test_case(Path::new("EXE003_uv.py"))]
2425
#[test_case(Path::new("EXE004_1.py"))]
2526
#[test_case(Path::new("EXE004_2.py"))]
2627
#[test_case(Path::new("EXE004_3.py"))]

crates/ruff_linter/src/rules/flake8_executable/rules/shebang_missing_python.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ use ruff_macros::{derive_message_formats, ViolationMetadata};
66
use crate::comments::shebang::ShebangDirective;
77

88
/// ## What it does
9-
/// Checks for a shebang directive in `.py` files that does not contain `python`.
9+
/// Checks for a shebang directive in `.py` files that does not contain `python`,
10+
/// `pytest`, or `uv run`.
1011
///
1112
/// ## Why is this bad?
1213
/// In Python, a shebang (also known as a hashbang) is the first line of a
13-
/// script, which specifies the interpreter that should be used to run the
14+
/// script, which specifies the command that should be used to run the
1415
/// script.
1516
///
16-
/// For Python scripts, the shebang must contain `python` to indicate that the
17-
/// script should be executed as a Python script. If the shebang does not
18-
/// contain `python`, then the file will be executed with the default
19-
/// interpreter, which is likely a mistake.
17+
/// For Python scripts, if the shebang does not include a command that explicitly
18+
/// or implicitly specifies an interpreter, then the file will be executed with
19+
/// the default interpreter, which is likely a mistake.
2020
///
2121
/// ## Example
2222
/// ```python
@@ -45,7 +45,7 @@ pub(crate) fn shebang_missing_python(
4545
range: TextRange,
4646
shebang: &ShebangDirective,
4747
) -> Option<Diagnostic> {
48-
if shebang.contains("python") || shebang.contains("pytest") {
48+
if shebang.contains("python") || shebang.contains("pytest") || shebang.contains("uv run") {
4949
return None;
5050
}
5151

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
source: crates/ruff_linter/src/rules/flake8_executable/mod.rs
3+
---
4+

0 commit comments

Comments
 (0)