Compare commits

..

3 Commits

Author SHA1 Message Date
Charlie Marsh
605416922d Bump version to 0.0.233 2023-01-24 10:46:49 -05:00
Charlie Marsh
7b81f36e54 Enable executable checks on Windows (#2133) 2023-01-24 10:46:27 -05:00
Eric Roberts
ff63da9f52 Move compare to helpers file (#2131)
From discussion on https://github.com/charliermarsh/ruff/pull/2123

I didn't originally have a helpers file so I put the function in both
places but now that a helpers file exists it seems logical for it to be
there.
2023-01-24 10:30:56 -05:00
15 changed files with 66 additions and 71 deletions

View File

@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.232
rev: v0.0.233
hooks:
- id: ruff

20
Cargo.lock generated
View File

@@ -719,7 +719,7 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]]
name = "flake8-to-ruff"
version = "0.0.232"
version = "0.0.233"
dependencies = [
"anyhow",
"clap 4.0.32",
@@ -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"
@@ -1828,7 +1837,7 @@ dependencies = [
[[package]]
name = "ruff"
version = "0.0.232"
version = "0.0.233"
dependencies = [
"anyhow",
"bitflags",
@@ -1847,6 +1856,7 @@ dependencies = [
"ignore",
"imperative",
"insta",
"is_executable",
"itertools",
"js-sys",
"libcst",
@@ -1882,7 +1892,7 @@ dependencies = [
[[package]]
name = "ruff_cli"
version = "0.0.232"
version = "0.0.233"
dependencies = [
"annotate-snippets 0.9.1",
"anyhow",
@@ -1919,7 +1929,7 @@ dependencies = [
[[package]]
name = "ruff_dev"
version = "0.0.232"
version = "0.0.233"
dependencies = [
"anyhow",
"clap 4.0.32",
@@ -1940,7 +1950,7 @@ dependencies = [
[[package]]
name = "ruff_macros"
version = "0.0.232"
version = "0.0.233"
dependencies = [
"once_cell",
"proc-macro2",

View File

@@ -8,7 +8,7 @@ default-members = [".", "ruff_cli"]
[package]
name = "ruff"
version = "0.0.232"
version = "0.0.233"
authors = ["Charlie Marsh <charlie.r.marsh@gmail.com>"]
edition = "2021"
rust-version = "1.65.0"
@@ -46,7 +46,7 @@ num-traits = "0.2.15"
once_cell = { version = "1.16.0" }
path-absolutize = { version = "3.0.14", features = ["once_cell_cache", "use_unix_paths_on_wasm"] }
regex = { version = "1.6.0" }
ruff_macros = { version = "0.0.232", path = "ruff_macros" }
ruff_macros = { version = "0.0.233", path = "ruff_macros" }
rustc-hash = { version = "1.1.0" }
rustpython-ast = { features = ["unparse"], git = "https://github.com/RustPython/RustPython.git", rev = "4f38cb68e4a97aeea9eb19673803a0bd5f655383" }
rustpython-common = { git = "https://github.com/RustPython/RustPython.git", rev = "4f38cb68e4a97aeea9eb19673803a0bd5f655383" }
@@ -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" }

View File

@@ -212,7 +212,7 @@ Ruff also works with [pre-commit](https://pre-commit.com):
```yaml
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.232'
rev: 'v0.0.233'
hooks:
- id: ruff
```

View File

@@ -771,7 +771,7 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]]
name = "flake8_to_ruff"
version = "0.0.232"
version = "0.0.233"
dependencies = [
"anyhow",
"clap",
@@ -1975,7 +1975,7 @@ dependencies = [
[[package]]
name = "ruff"
version = "0.0.232"
version = "0.0.233"
dependencies = [
"anyhow",
"bincode",

View File

@@ -1,6 +1,6 @@
[package]
name = "flake8-to-ruff"
version = "0.0.232"
version = "0.0.233"
edition = "2021"
[dependencies]
@@ -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]

View File

@@ -7,7 +7,7 @@ build-backend = "maturin"
[project]
name = "ruff"
version = "0.0.232"
version = "0.0.233"
description = "An extremely fast Python linter, written in Rust."
authors = [
{ name = "Charlie Marsh", email = "charlie.r.marsh@gmail.com" },

View File

@@ -1,6 +1,6 @@
[package]
name = "ruff_cli"
version = "0.0.232"
version = "0.0.233"
authors = ["Charlie Marsh <charlie.r.marsh@gmail.com>"]
edition = "2021"
rust-version = "1.65.0"

View File

@@ -1,6 +1,6 @@
[package]
name = "ruff_dev"
version = "0.0.232"
version = "0.0.233"
edition = "2021"
[dependencies]

View File

@@ -1,6 +1,6 @@
[package]
name = "ruff_macros"
version = "0.0.232"
version = "0.0.233"
edition = "2021"
[lib]

View File

@@ -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
}

View File

@@ -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

View File

@@ -1,3 +1,19 @@
use rustpython_parser::ast::{Cmpop, Expr, ExprKind};
use crate::ast::helpers::{create_expr, unparse_expr};
use crate::source_code::Stylist;
pub fn is_ambiguous_name(name: &str) -> bool {
name == "l" || name == "I" || name == "O"
}
pub fn compare(left: &Expr, ops: &[Cmpop], comparators: &[Expr], stylist: &Stylist) -> String {
unparse_expr(
&create_expr(ExprKind::Compare {
left: Box::new(left.clone()),
ops: ops.to_vec(),
comparators: comparators.to_vec(),
}),
stylist,
)
}

View File

@@ -4,12 +4,11 @@ use rustpython_ast::Constant;
use rustpython_parser::ast::{Cmpop, Expr, ExprKind};
use crate::ast::helpers;
use crate::ast::helpers::{create_expr, unparse_expr};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::source_code::Stylist;
use crate::rules::pycodestyle::helpers::compare;
use crate::violations;
/// E711, E712
@@ -193,14 +192,3 @@ pub fn literal_comparisons(
checker.diagnostics.extend(diagnostics);
}
pub fn compare(left: &Expr, ops: &[Cmpop], comparators: &[Expr], stylist: &Stylist) -> String {
unparse_expr(
&create_expr(ExprKind::Compare {
left: Box::new(left.clone()),
ops: ops.to_vec(),
comparators: comparators.to_vec(),
}),
stylist,
)
}

View File

@@ -1,12 +1,11 @@
use rustpython_ast::Unaryop;
use rustpython_parser::ast::{Cmpop, Expr, ExprKind};
use crate::ast::helpers::{create_expr, unparse_expr};
use crate::ast::types::Range;
use crate::checkers::ast::Checker;
use crate::fix::Fix;
use crate::registry::Diagnostic;
use crate::source_code::Stylist;
use crate::rules::pycodestyle::helpers::compare;
use crate::violations;
/// E713, E714
@@ -67,14 +66,3 @@ pub fn not_tests(
}
}
}
pub fn compare(left: &Expr, ops: &[Cmpop], comparators: &[Expr], stylist: &Stylist) -> String {
unparse_expr(
&create_expr(ExprKind::Compare {
left: Box::new(left.clone()),
ops: ops.to_vec(),
comparators: comparators.to_vec(),
}),
stylist,
)
}