mirror of https://github.com/astral-sh/ruff
Enable executable checks on Windows (#2133)
This commit is contained in:
parent
ff63da9f52
commit
7b81f36e54
|
|
@ -984,6 +984,15 @@ dependencies = [
|
|||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_executable"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa9acdc6d67b75e626ad644734e8bc6df893d9cd2a834129065d3dd6158ea9c8"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
|
|
@ -1847,6 +1856,7 @@ dependencies = [
|
|||
"ignore",
|
||||
"imperative",
|
||||
"insta",
|
||||
"is_executable",
|
||||
"itertools",
|
||||
"js-sys",
|
||||
"libcst",
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ strum_macros = { version = "0.24.3" }
|
|||
textwrap = { version = "0.16.0" }
|
||||
thiserror = { version = "1.0" }
|
||||
titlecase = { version = "2.2.1" }
|
||||
toml = { version = "0.6.0", features= ["parse"] }
|
||||
toml = { version = "0.6.0" }
|
||||
|
||||
# https://docs.rs/getrandom/0.2.7/getrandom/#webassembly-support
|
||||
# For (future) wasm-pack support
|
||||
|
|
@ -73,6 +73,9 @@ serde-wasm-bindgen = { version = "0.4" }
|
|||
js-sys = { version = "0.3.60" }
|
||||
wasm-bindgen = { version = "0.2.83" }
|
||||
|
||||
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
||||
is_executable = "1.0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
insta = { version = "1.19.1", features = ["yaml"] }
|
||||
test-case = { version = "2.2.2" }
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ serde = { version = "1.0.147", features = ["derive"] }
|
|||
serde_json = { version = "1.0.87" }
|
||||
strum = { version = "0.24.1", features = ["strum_macros"] }
|
||||
strum_macros = { version = "0.24.3" }
|
||||
toml = { version = "0.6.0", features = ["parse"] }
|
||||
toml = { version = "0.6.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#[cfg(not(target_family = "wasm"))]
|
||||
use std::os::unix::prelude::MetadataExt;
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
use is_executable::IsExecutable;
|
||||
use ruff_macros::derive_message_formats;
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
|
|
@ -23,14 +23,9 @@ impl Violation for ShebangMissingExecutableFile {
|
|||
/// EXE002
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub fn shebang_missing(filepath: &Path) -> Option<Diagnostic> {
|
||||
if let Ok(metadata) = filepath.metadata() {
|
||||
// Check if file is executable by anyone
|
||||
if metadata.mode() & 0o111 == 0 {
|
||||
None
|
||||
} else {
|
||||
let diagnostic = Diagnostic::new(ShebangMissingExecutableFile, Range::default());
|
||||
Some(diagnostic)
|
||||
}
|
||||
if filepath.is_executable() {
|
||||
let diagnostic = Diagnostic::new(ShebangMissingExecutableFile, Range::default());
|
||||
Some(diagnostic)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#[cfg(not(target_family = "wasm"))]
|
||||
use std::os::unix::prelude::MetadataExt;
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
use is_executable::IsExecutable;
|
||||
use ruff_macros::derive_message_formats;
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
use rustpython_ast::Location;
|
||||
|
|
@ -31,22 +31,17 @@ pub fn shebang_not_executable(
|
|||
shebang: &ShebangDirective,
|
||||
) -> Option<Diagnostic> {
|
||||
if let ShebangDirective::Match(_, start, end, _) = shebang {
|
||||
if let Ok(metadata) = filepath.metadata() {
|
||||
// Check if file is executable by anyone
|
||||
if metadata.mode() & 0o111 == 0 {
|
||||
let diagnostic = Diagnostic::new(
|
||||
ShebangNotExecutable,
|
||||
Range::new(
|
||||
Location::new(lineno + 1, *start),
|
||||
Location::new(lineno + 1, *end),
|
||||
),
|
||||
);
|
||||
Some(diagnostic)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
if filepath.is_executable() {
|
||||
None
|
||||
} else {
|
||||
let diagnostic = Diagnostic::new(
|
||||
ShebangNotExecutable,
|
||||
Range::new(
|
||||
Location::new(lineno + 1, *start),
|
||||
Location::new(lineno + 1, *end),
|
||||
),
|
||||
);
|
||||
Some(diagnostic)
|
||||
}
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
Loading…
Reference in New Issue