Skip to content

Commit

Permalink
Merge branch 'main' into arbitrary-cli-overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Feb 9, 2024
2 parents 789d1d0 + d387d0b commit 0f8a583
Show file tree
Hide file tree
Showing 172 changed files with 5,347 additions and 1,786 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ jobs:
tool: cargo-insta
- uses: Swatinem/rust-cache@v2
- name: "Run tests"
run: cargo insta test --all --exclude ruff_dev --all-features --unreferenced reject
- name: "Run dev tests"
# e.g. generating the schema — these should not run with all features enabled
run: cargo insta test -p ruff_dev --unreferenced reject
run: cargo insta test --all --all-features --unreferenced reject
# Check for broken links in the documentation.
- run: cargo doc --all --no-deps
env:
Expand Down
42 changes: 12 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ argfile = { version = "0.1.6" }
assert_cmd = { version = "2.0.13" }
bincode = { version = "1.3.3" }
bitflags = { version = "2.4.1" }
bstr = { version = "1.9.0" }
cachedir = { version = "0.3.1" }
chrono = { version = "0.4.33", default-features = false, features = ["clock"] }
clap = { version = "4.4.18", features = ["derive"] }
Expand Down Expand Up @@ -65,7 +66,7 @@ pathdiff = { version = "0.2.1" }
pep440_rs = { version = "0.4.0", features = ["serde"] }
pretty_assertions = "1.3.0"
proc-macro2 = { version = "1.0.78" }
pyproject-toml = { version = "0.8.2" }
pyproject-toml = { version = "0.9.0" }
quick-junit = { version = "0.3.5" }
quote = { version = "1.0.23" }
rand = { version = "0.8.5" }
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/commands/show_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ pub(crate) fn show_settings(

let settings = resolver.resolve(&path);

writeln!(writer, "Resolved settings for: {path:?}")?;
writeln!(writer, "Resolved settings for: \"{}\"", path.display())?;
if let Some(settings_path) = pyproject_config.path.as_ref() {
writeln!(writer, "Settings path: {settings_path:?}")?;
writeln!(writer, "Settings path: \"{}\"", settings_path.display())?;
}
write!(writer, "{settings}")?;

Expand Down
38 changes: 21 additions & 17 deletions crates/ruff/tests/show_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@ use std::process::Command;

const BIN_NAME: &str = "ruff";

#[cfg(not(target_os = "windows"))]
const TEST_FILTERS: &[(&str, &str)] = &[
("\"[^\\*\"]*/pyproject.toml", "\"[BASEPATH]/pyproject.toml"),
("\".*/crates", "\"[BASEPATH]/crates"),
("\".*/\\.ruff_cache", "\"[BASEPATH]/.ruff_cache"),
("\".*/ruff\"", "\"[BASEPATH]\""),
];
#[cfg(target_os = "windows")]
const TEST_FILTERS: &[(&str, &str)] = &[
(r#""[^\*"]*\\pyproject.toml"#, "\"[BASEPATH]/pyproject.toml"),
(r#"".*\\crates"#, "\"[BASEPATH]/crates"),
(r#"".*\\\.ruff_cache"#, "\"[BASEPATH]/.ruff_cache"),
(r#"".*\\ruff""#, "\"[BASEPATH]\""),
(r#"\\+(\w\w|\s|")"#, "/$1"),
];

#[test]
fn display_default_settings() {
insta::with_settings!({ filters => TEST_FILTERS.to_vec() }, {
// Navigate from the crate directory to the workspace root.
let base_path = Path::new(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.parent()
.unwrap();
let base_path = base_path.to_string_lossy();

// Escape the backslashes for the regex.
let base_path = regex::escape(&base_path);

#[cfg(not(target_os = "windows"))]
let test_filters = &[(base_path.as_ref(), "[BASEPATH]")];

#[cfg(target_os = "windows")]
let test_filters = &[
(base_path.as_ref(), "[BASEPATH]"),
(r#"\\+(\w\w|\s|\.|")"#, "/$1"),
];

insta::with_settings!({ filters => test_filters.to_vec() }, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(["check", "--show-settings", "unformatted.py"]).current_dir(Path::new("./resources/test/fixtures")));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ linter.external = []
linter.ignore_init_module_imports = false
linter.logger_objects = []
linter.namespace_packages = []
linter.src = ["[BASEPATH]"]
linter.src = [
"[BASEPATH]",
]
linter.tab_size = 4
linter.line_length = 88
linter.task_tags = [
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff_formatter/src/printer/line_suffixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ impl<'a> LineSuffixes<'a> {
/// Takes all the pending line suffixes.
pub(super) fn take_pending<'l>(
&'l mut self,
) -> impl Iterator<Item = LineSuffixEntry<'a>> + DoubleEndedIterator + 'l + ExactSizeIterator
{
) -> impl DoubleEndedIterator<Item = LineSuffixEntry<'a>> + 'l + ExactSizeIterator {
self.suffixes.drain(..)
}

Expand Down
22 changes: 22 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/flake8_bandit/S308.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.utils.safestring import mark_safe


def some_func():
return mark_safe('<script>alert("evil!")</script>')


@mark_safe
def some_func():
return '<script>alert("evil!")</script>'


from django.utils.html import mark_safe


def some_func():
return mark_safe('<script>alert("evil!")</script>')


@mark_safe
def some_func():
return '<script>alert("evil!")</script>'
17 changes: 13 additions & 4 deletions crates/ruff_linter/resources/test/fixtures/flake8_trio/TRIO100.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import trio


async def foo():
async def func():
with trio.fail_after():
...

async def foo():

async def func():
with trio.fail_at():
await ...

async def foo():

async def func():
with trio.move_on_after():
...

async def foo():

async def func():
with trio.move_at():
await ...


async def func():
with trio.move_at():
async with trio.open_nursery() as nursery:
...
4 changes: 3 additions & 1 deletion crates/ruff_linter/resources/test/fixtures/numpy/NPY002.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
numpy.random.get_state()
numpy.random.set_state()
numpy.random.rand()
numpy.random.ranf()
numpy.random.sample()
numpy.random.randn()
numpy.random.randint()
numpy.random.random()
numpy.random.random_integers()
numpy.random.random_sample()
numpy.random.choice()
Expand All @@ -35,7 +38,6 @@
numpy.random.f()
numpy.random.gamma()
numpy.random.geometric()
numpy.random.get_state()
numpy.random.gumbel()
numpy.random.hypergeometric()
numpy.random.laplace()
Expand Down
Loading

0 comments on commit 0f8a583

Please sign in to comment.