mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
Avoid EXE001 and EXE002 errors from stdin input (#3218)
This commit is contained in:
parent
a17b5c134a
commit
0694aee1b6
3 changed files with 11 additions and 15 deletions
|
@ -1,4 +1,6 @@
|
|||
#[cfg(target_family = "unix")]
|
||||
use anyhow::Result;
|
||||
#[cfg(target_family = "unix")]
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
#[cfg(target_family = "unix")]
|
||||
use std::path::Path;
|
||||
|
@ -39,13 +41,11 @@ pub fn extract_shebang(line: &str) -> ShebangDirective {
|
|||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn is_executable(filepath: &Path) -> bool {
|
||||
pub fn is_executable(filepath: &Path) -> Result<bool> {
|
||||
{
|
||||
let Ok(metadata) = filepath.metadata() else {
|
||||
return false;
|
||||
};
|
||||
let metadata = filepath.metadata()?;
|
||||
let permissions = metadata.permissions();
|
||||
permissions.mode() & 0o111 != 0
|
||||
Ok(permissions.mode() & 0o111 != 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,11 @@ impl Violation for ShebangMissingExecutableFile {
|
|||
/// EXE002
|
||||
#[cfg(target_family = "unix")]
|
||||
pub fn shebang_missing(filepath: &Path) -> Option<Diagnostic> {
|
||||
if is_executable(filepath) {
|
||||
if let Ok(true) = is_executable(filepath) {
|
||||
let diagnostic = Diagnostic::new(ShebangMissingExecutableFile, Range::default());
|
||||
Some(diagnostic)
|
||||
} else {
|
||||
None
|
||||
return Some(diagnostic);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(not(target_family = "unix"))]
|
||||
|
|
|
@ -31,9 +31,7 @@ pub fn shebang_not_executable(
|
|||
shebang: &ShebangDirective,
|
||||
) -> Option<Diagnostic> {
|
||||
if let ShebangDirective::Match(_, start, end, _) = shebang {
|
||||
if is_executable(filepath) {
|
||||
None
|
||||
} else {
|
||||
if let Ok(false) = is_executable(filepath) {
|
||||
let diagnostic = Diagnostic::new(
|
||||
ShebangNotExecutable,
|
||||
Range::new(
|
||||
|
@ -41,11 +39,10 @@ pub fn shebang_not_executable(
|
|||
Location::new(lineno + 1, *end),
|
||||
),
|
||||
);
|
||||
Some(diagnostic)
|
||||
return Some(diagnostic);
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(not(target_family = "unix"))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue