mirror of
https://github.com/charliermarsh/ruff
synced 2025-10-05 23:52:47 +02:00
## Summary We use the `System` abstraction in ty to abstract away the host/system on which ty runs. This has a few benefits: * Tests can run in full isolation using a memory system (that uses an in-memory file system) * The LSP has a custom implementation where `read_to_string` returns the content as seen by the editor (e.g. unsaved changes) instead of always returning the content as it is stored on disk * We don't require any file system polyfills for wasm in the browser However, it does require extra care that we don't accidentally use `std::fs` or `std::env` (etc.) methods in ty's code base (which is very easy). This PR sets up Clippy and disallows the most common methods, instead pointing users towards the corresponding `System` methods. The setup is a bit awkward because clippy doesn't support inheriting configurations. That means, a crate can only override the entire workspace configuration or not at all. The approach taken in this PR is: * Configure the disallowed methods at the workspace level * Allow `disallowed_methods` at the workspace level * Enable the lint at the crate level using the warn attribute (in code) The obvious downside is that it won't work if we ever want to disallow other methods, but we can figure that out once we reach that point. What about false positives: Just add an `allow` and move on with your life :) This isn't something that we have to enforce strictly; the goal is to catch accidental misuse. ## Test Plan Clippy found a place where we incorrectly used `std::fs::read_to_string`
299 lines
10 KiB
TOML
299 lines
10 KiB
TOML
[workspace]
|
|
members = ["crates/*"]
|
|
resolver = "2"
|
|
|
|
[workspace.package]
|
|
# Please update rustfmt.toml when bumping the Rust edition
|
|
edition = "2024"
|
|
rust-version = "1.87"
|
|
homepage = "https://docs.astral.sh/ruff"
|
|
documentation = "https://docs.astral.sh/ruff"
|
|
repository = "https://github.com/astral-sh/ruff"
|
|
authors = ["Charlie Marsh <charlie.r.marsh@gmail.com>"]
|
|
license = "MIT"
|
|
|
|
[workspace.dependencies]
|
|
ruff = { path = "crates/ruff" }
|
|
ruff_annotate_snippets = { path = "crates/ruff_annotate_snippets" }
|
|
ruff_cache = { path = "crates/ruff_cache" }
|
|
ruff_db = { path = "crates/ruff_db", default-features = false }
|
|
ruff_diagnostics = { path = "crates/ruff_diagnostics" }
|
|
ruff_formatter = { path = "crates/ruff_formatter" }
|
|
ruff_graph = { path = "crates/ruff_graph" }
|
|
ruff_index = { path = "crates/ruff_index" }
|
|
ruff_linter = { path = "crates/ruff_linter" }
|
|
ruff_macros = { path = "crates/ruff_macros" }
|
|
ruff_memory_usage = { path = "crates/ruff_memory_usage" }
|
|
ruff_notebook = { path = "crates/ruff_notebook" }
|
|
ruff_options_metadata = { path = "crates/ruff_options_metadata" }
|
|
ruff_python_ast = { path = "crates/ruff_python_ast" }
|
|
ruff_python_codegen = { path = "crates/ruff_python_codegen" }
|
|
ruff_python_formatter = { path = "crates/ruff_python_formatter" }
|
|
ruff_python_index = { path = "crates/ruff_python_index" }
|
|
ruff_python_literal = { path = "crates/ruff_python_literal" }
|
|
ruff_python_parser = { path = "crates/ruff_python_parser" }
|
|
ruff_python_semantic = { path = "crates/ruff_python_semantic" }
|
|
ruff_python_stdlib = { path = "crates/ruff_python_stdlib" }
|
|
ruff_python_trivia = { path = "crates/ruff_python_trivia" }
|
|
ruff_server = { path = "crates/ruff_server" }
|
|
ruff_source_file = { path = "crates/ruff_source_file" }
|
|
ruff_text_size = { path = "crates/ruff_text_size" }
|
|
ruff_workspace = { path = "crates/ruff_workspace" }
|
|
|
|
ty = { path = "crates/ty" }
|
|
ty_combine = { path = "crates/ty_combine" }
|
|
ty_ide = { path = "crates/ty_ide" }
|
|
ty_project = { path = "crates/ty_project", default-features = false }
|
|
ty_python_semantic = { path = "crates/ty_python_semantic" }
|
|
ty_server = { path = "crates/ty_server" }
|
|
ty_static = { path = "crates/ty_static" }
|
|
ty_test = { path = "crates/ty_test" }
|
|
ty_vendored = { path = "crates/ty_vendored" }
|
|
|
|
aho-corasick = { version = "1.1.3" }
|
|
anstream = { version = "0.6.18" }
|
|
anstyle = { version = "1.0.10" }
|
|
anyhow = { version = "1.0.80" }
|
|
arc-swap = { version = "1.7.1" }
|
|
assert_fs = { version = "1.1.0" }
|
|
argfile = { version = "0.2.0" }
|
|
bincode = { version = "2.0.0" }
|
|
bitflags = { version = "2.5.0" }
|
|
bitvec = { version = "1.0.1", default-features = false, features = [
|
|
"alloc",
|
|
] }
|
|
bstr = { version = "1.9.1" }
|
|
cachedir = { version = "0.3.1" }
|
|
camino = { version = "1.1.7" }
|
|
clap = { version = "4.5.3", features = ["derive"] }
|
|
clap_complete_command = { version = "0.6.0" }
|
|
clearscreen = { version = "4.0.0" }
|
|
divan = { package = "codspeed-divan-compat", version = "3.0.2" }
|
|
codspeed-criterion-compat = { version = "3.0.2", default-features = false }
|
|
colored = { version = "3.0.0" }
|
|
console_error_panic_hook = { version = "0.1.7" }
|
|
console_log = { version = "1.0.0" }
|
|
countme = { version = "3.0.1" }
|
|
compact_str = "0.9.0"
|
|
criterion = { version = "0.7.0", default-features = false }
|
|
crossbeam = { version = "0.8.4" }
|
|
dashmap = { version = "6.0.1" }
|
|
dir-test = { version = "0.4.0" }
|
|
dunce = { version = "1.0.5" }
|
|
drop_bomb = { version = "0.1.5" }
|
|
etcetera = { version = "0.10.0" }
|
|
fern = { version = "0.7.0" }
|
|
filetime = { version = "0.2.23" }
|
|
getrandom = { version = "0.3.1" }
|
|
get-size2 = { version = "0.6.2", features = [
|
|
"derive",
|
|
"smallvec",
|
|
"hashbrown",
|
|
"compact-str",
|
|
] }
|
|
glob = { version = "0.3.1" }
|
|
globset = { version = "0.4.14" }
|
|
globwalk = { version = "0.9.1" }
|
|
hashbrown = { version = "0.15.0", default-features = false, features = [
|
|
"raw-entry",
|
|
"equivalent",
|
|
"inline-more",
|
|
] }
|
|
heck = "0.5.0"
|
|
ignore = { version = "0.4.22" }
|
|
imara-diff = { version = "0.1.5" }
|
|
imperative = { version = "1.0.4" }
|
|
indexmap = { version = "2.6.0" }
|
|
indicatif = { version = "0.18.0" }
|
|
indoc = { version = "2.0.4" }
|
|
insta = { version = "1.35.1" }
|
|
insta-cmd = { version = "0.6.0" }
|
|
is-macro = { version = "0.3.5" }
|
|
is-wsl = { version = "0.4.0" }
|
|
itertools = { version = "0.14.0" }
|
|
jiff = { version = "0.2.0" }
|
|
js-sys = { version = "0.3.69" }
|
|
jod-thread = { version = "1.0.0" }
|
|
libc = { version = "0.2.153" }
|
|
libcst = { version = "1.1.0", default-features = false }
|
|
log = { version = "0.4.17" }
|
|
lsp-server = { version = "0.7.6" }
|
|
lsp-types = { git = "https://github.com/astral-sh/lsp-types.git", rev = "3512a9f", features = [
|
|
"proposed",
|
|
] }
|
|
matchit = { version = "0.8.1" }
|
|
memchr = { version = "2.7.1" }
|
|
mimalloc = { version = "0.1.39" }
|
|
natord = { version = "1.0.9" }
|
|
notify = { version = "8.0.0" }
|
|
ordermap = { version = "0.5.0" }
|
|
path-absolutize = { version = "3.1.1" }
|
|
path-slash = { version = "0.2.1" }
|
|
pathdiff = { version = "0.2.1" }
|
|
pep440_rs = { version = "0.7.1" }
|
|
pretty_assertions = "1.3.0"
|
|
proc-macro2 = { version = "1.0.79" }
|
|
pyproject-toml = { version = "0.13.4" }
|
|
quick-junit = { version = "0.5.0" }
|
|
quote = { version = "1.0.23" }
|
|
rand = { version = "0.9.0" }
|
|
rayon = { version = "1.10.0" }
|
|
regex = { version = "1.10.2" }
|
|
regex-automata = { version = "0.4.9" }
|
|
rustc-hash = { version = "2.0.0" }
|
|
rustc-stable-hash = { version = "0.1.2" }
|
|
# When updating salsa, make sure to also update the revision in `fuzz/Cargo.toml`
|
|
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "a3ffa22cb26756473d56f867aedec3fd907c4dd9", default-features = false, features = [
|
|
"compact_str",
|
|
"macros",
|
|
"salsa_unstable",
|
|
"inventory",
|
|
] }
|
|
schemars = { version = "0.8.16" }
|
|
seahash = { version = "4.1.0" }
|
|
serde = { version = "1.0.197", features = ["derive"] }
|
|
serde-wasm-bindgen = { version = "0.6.4" }
|
|
serde_json = { version = "1.0.113" }
|
|
serde_test = { version = "1.0.152" }
|
|
serde_with = { version = "3.6.0", default-features = false, features = [
|
|
"macros",
|
|
] }
|
|
shellexpand = { version = "3.0.0" }
|
|
similar = { version = "2.4.0", features = ["inline"] }
|
|
smallvec = { version = "1.13.2", features = ["union", "const_generics", "const_new"] }
|
|
snapbox = { version = "0.6.0", features = [
|
|
"diff",
|
|
"term-svg",
|
|
"cmd",
|
|
"examples",
|
|
] }
|
|
static_assertions = "1.1.0"
|
|
strum = { version = "0.27.0", features = ["strum_macros"] }
|
|
strum_macros = { version = "0.27.0" }
|
|
syn = { version = "2.0.55" }
|
|
tempfile = { version = "3.9.0" }
|
|
test-case = { version = "3.3.1" }
|
|
thiserror = { version = "2.0.0" }
|
|
tikv-jemallocator = { version = "0.6.0" }
|
|
toml = { version = "0.9.0" }
|
|
tracing = { version = "0.1.40" }
|
|
tracing-flame = { version = "0.2.0" }
|
|
tracing-indicatif = { version = "0.3.11" }
|
|
tracing-log = { version = "0.2.0" }
|
|
tracing-subscriber = { version = "0.3.18", default-features = false, features = [
|
|
"env-filter",
|
|
"fmt",
|
|
"ansi",
|
|
"smallvec",
|
|
] }
|
|
tryfn = { version = "0.2.1" }
|
|
typed-arena = { version = "2.0.2" }
|
|
unic-ucd-category = { version = "0.9" }
|
|
unicode-ident = { version = "1.0.12" }
|
|
unicode-width = { version = "0.2.0" }
|
|
unicode_names2 = { version = "1.2.2" }
|
|
unicode-normalization = { version = "0.1.23" }
|
|
url = { version = "2.5.0" }
|
|
uuid = { version = "1.6.1", features = ["v4", "fast-rng", "macro-diagnostics"] }
|
|
walkdir = { version = "2.3.2" }
|
|
wasm-bindgen = { version = "0.2.92" }
|
|
wasm-bindgen-test = { version = "0.3.42" }
|
|
wild = { version = "2" }
|
|
zip = { version = "0.6.6", default-features = false }
|
|
|
|
[workspace.metadata.cargo-shear]
|
|
ignored = ["getrandom", "ruff_options_metadata", "uuid"]
|
|
|
|
|
|
[workspace.lints.rust]
|
|
unsafe_code = "warn"
|
|
unreachable_pub = "warn"
|
|
unexpected_cfgs = { level = "warn", check-cfg = [
|
|
"cfg(fuzzing)",
|
|
"cfg(codspeed)",
|
|
] }
|
|
|
|
[workspace.lints.clippy]
|
|
pedantic = { level = "warn", priority = -2 }
|
|
# Enabled at the crate level
|
|
disallowed_methods = "allow"
|
|
# Allowed pedantic lints
|
|
char_lit_as_u8 = "allow"
|
|
collapsible_else_if = "allow"
|
|
collapsible_if = "allow"
|
|
implicit_hasher = "allow"
|
|
map_unwrap_or = "allow"
|
|
match_same_arms = "allow"
|
|
missing_errors_doc = "allow"
|
|
missing_panics_doc = "allow"
|
|
module_name_repetitions = "allow"
|
|
must_use_candidate = "allow"
|
|
similar_names = "allow"
|
|
single_match_else = "allow"
|
|
too_many_lines = "allow"
|
|
needless_continue = "allow" # An explicit continue can be more readable, especially if the alternative is an empty block.
|
|
unnecessary_debug_formatting = "allow" # too many instances, the display also doesn't quote the path which is often desired in logs where we use them the most often.
|
|
# Without the hashes we run into a `rustfmt` bug in some snapshot tests, see #13250
|
|
needless_raw_string_hashes = "allow"
|
|
# Disallowed restriction lints
|
|
ignore_without_reason = "allow" # Too many exsisting instances, and there's no auto fix.
|
|
print_stdout = "warn"
|
|
print_stderr = "warn"
|
|
dbg_macro = "warn"
|
|
empty_drop = "warn"
|
|
empty_structs_with_brackets = "warn"
|
|
exit = "warn"
|
|
get_unwrap = "warn"
|
|
rc_buffer = "warn"
|
|
rc_mutex = "warn"
|
|
rest_pat_in_fully_bound_structs = "warn"
|
|
# nursery rules
|
|
redundant_clone = "warn"
|
|
debug_assert_with_mut_call = "warn"
|
|
unused_peekable = "warn"
|
|
|
|
# Diagnostics are not actionable: Enable once https://github.com/rust-lang/rust-clippy/issues/13774 is resolved.
|
|
large_stack_arrays = "allow"
|
|
|
|
|
|
[profile.release]
|
|
# Note that we set these explicitly, and these values
|
|
# were chosen based on a trade-off between compile times
|
|
# and runtime performance[1].
|
|
#
|
|
# [1]: https://github.com/astral-sh/ruff/pull/9031
|
|
lto = "thin"
|
|
codegen-units = 16
|
|
|
|
# Some crates don't change as much but benefit more from
|
|
# more expensive optimization passes, so we selectively
|
|
# decrease codegen-units in some cases.
|
|
[profile.release.package.ruff_python_parser]
|
|
codegen-units = 1
|
|
[profile.release.package.ruff_python_ast]
|
|
codegen-units = 1
|
|
|
|
[profile.dev.package.insta]
|
|
opt-level = 3
|
|
|
|
[profile.dev.package.similar]
|
|
opt-level = 3
|
|
|
|
[profile.dev.package.salsa]
|
|
opt-level = 3
|
|
|
|
# Reduce complexity of a parser function that would trigger a locals limit in a wasm tool.
|
|
# https://github.com/bytecodealliance/wasm-tools/blob/b5c3d98e40590512a3b12470ef358d5c7b983b15/crates/wasmparser/src/limits.rs#L29
|
|
[profile.dev.package.ruff_python_parser]
|
|
opt-level = 1
|
|
|
|
# Use the `--profile profiling` flag to show symbols in release mode.
|
|
# e.g. `cargo build --profile profiling`
|
|
[profile.profiling]
|
|
inherits = "release"
|
|
debug = 1
|
|
|
|
# The profile that 'cargo dist' will build with.
|
|
[profile.dist]
|
|
inherits = "release"
|