diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 000000000..40b1dda5b --- /dev/null +++ b/.clippy.toml @@ -0,0 +1 @@ +allow-print-in-tests = true diff --git a/.github/features.ua b/.github/features.ua deleted file mode 100644 index 81d3a3121..000000000 --- a/.github/features.ua +++ /dev/null @@ -1,20 +0,0 @@ -# Test combinations of features - -Command ← {"cargo" "c" "--lib" "--no-default-features"} -Features ← ( - {"audio" "tls"} - ⊂⨬( - {"gif,image,terminal_image,webcam" "lsp,raw_mode"} - | {"audio_encode" "gif" "image" "terminal_image" "lsp" "native_sys" "raw_mode"} - ) ∈:□"all" &args -) - -&p "Checking with no features" -⍤⟜≍: 0 &runi Command - -↘1⋯⇡ⁿ:2⧻. Features -≡(/$"_,_" ▽ - &p $"Checking with features: _". - ⊂ Command ⊂ □"--features" □ - ⍤⟜≍: 0 &runi -)⊙¤ diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 75a2510bf..8c48365c7 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -42,21 +42,25 @@ jobs: - uses: actions/checkout@v4 - name: Check formatting run: cargo fmt --all --check - install_deps: - needs: check_formatting + clippy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Install depsAdd commentMore actions + - uses: actions/cache@v4 + with: + path: target + key: build-${{ runner.os }}-${{ hashFiles('Cargo.lock') }} + restore-keys: | + build-${{ runner.os }}- + - name: Install deps run: | sudo apt-get update -y sudo apt-get --fix-missing install -y - sudo apt-get install libasound2-dev libudev-dev pkg-config libx11-dev libjpeg-dev - - name: Install WASM target - run: rustup target add wasm32-unknown-unknown + sudo apt-get install libasound2-dev + - name: Run clippy + run: cargo clippy --no-deps --all-targets --workspace --all-features -- --deny=warnings # Test the interpreter test_bin: - needs: install_deps runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -66,13 +70,10 @@ jobs: key: build-${{ runner.os }}-${{ hashFiles('Cargo.lock') }} restore-keys: | build-${{ runner.os }}- - - name: Check interpreter clippy lints - run: cargo clippy --no-deps - name: Run interpreter tests run: cargo test --lib # Test the site test_site: - needs: install_deps runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -86,7 +87,6 @@ jobs: run: cargo test -p site # Test ffi test_ffi: - needs: install_deps runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -98,10 +98,3 @@ jobs: build-${{ runner.os }}- - name: Run site tests run: cargo test -p tests_ffi - # check_features: - # needs: test_bin - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 - # - name: Check feature combinations - # run: cargo run ./.github/features.ua diff --git a/Cargo.toml b/Cargo.toml index 903a2e22b..2f6f266ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -165,9 +165,18 @@ system = ["libffi?/system"] [[bin]] name = "uiua" +required-features = ["binary"] [workspace] members = ["site", "tests_ffi", "pad/editor", "parser"] +[workspace.lints.clippy] +print_stdout = "warn" +print_stderr = "allow" +dbg_macro = "warn" + +[lints] +workspace = true + [profile.dev] incremental = true diff --git a/pad/editor/.clippy.toml b/pad/editor/.clippy.toml new file mode 120000 index 000000000..868439e8e --- /dev/null +++ b/pad/editor/.clippy.toml @@ -0,0 +1 @@ +../../.clippy.toml \ No newline at end of file diff --git a/pad/editor/Cargo.toml b/pad/editor/Cargo.toml index 55634947f..3cc39adbd 100644 --- a/pad/editor/Cargo.toml +++ b/pad/editor/Cargo.toml @@ -6,6 +6,9 @@ edition = "2021" [lib] crate-type = ["cdylib", "rlib"] +[lints] +workspace = true + [dependencies] leptos = { version = "0.6.10", features = ["csr"] } js-sys = "0.3.69" diff --git a/parser/.clippy.toml b/parser/.clippy.toml new file mode 120000 index 000000000..c5ecbcbfa --- /dev/null +++ b/parser/.clippy.toml @@ -0,0 +1 @@ +../.clippy.toml \ No newline at end of file diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 55a326714..2fdbda94a 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -10,6 +10,9 @@ repository = "https://github.com/uiua-lang/uiua" rust-version = "1.82.0" version = "0.17.0-dev.1" +[lints] +workspace = true + [dependencies] bytemuck = {version = "1.17", features = ["must_cast", "derive", "extern_crate_alloc"]} colored = "2" diff --git a/site/.clippy.toml b/site/.clippy.toml new file mode 120000 index 000000000..c5ecbcbfa --- /dev/null +++ b/site/.clippy.toml @@ -0,0 +1 @@ +../.clippy.toml \ No newline at end of file diff --git a/site/Cargo.toml b/site/Cargo.toml index 834dd28ed..5206fde12 100644 --- a/site/Cargo.toml +++ b/site/Cargo.toml @@ -3,6 +3,9 @@ edition = "2021" name = "site" version = "0.1.0" +[lints] +workspace = true + [dependencies] base64 = "0.22.0" comrak = "0.39.0" diff --git a/src/compile/mod.rs b/src/compile/mod.rs index bec4354a6..4f9e9563a 100644 --- a/src/compile/mod.rs +++ b/src/compile/mod.rs @@ -2610,6 +2610,7 @@ impl Compiler { let inputs = self.asm.inputs.clone(); self.emit_diagnostic_impl(Diagnostic::new(message.into(), span, kind, inputs)); } + #[allow(clippy::print_stdout)] fn emit_diagnostic_impl(&mut self, diagnostic: Diagnostic) { if self.print_diagnostics { eprintln!("{}", diagnostic.report()); diff --git a/src/ffi.rs b/src/ffi.rs index 1e5ece48a..99fe01044 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -3,9 +3,6 @@ use std::{ str::FromStr, }; -#[allow(missing_docs)] -pub const DEBUG: bool = false; - /// Data for how to send an argument type to `&ffi` #[derive(Debug)] pub struct FfiArg { diff --git a/src/lib.rs b/src/lib.rs index e10a0dc43..2bc8f6913 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -356,43 +356,11 @@ mod tests { } } - fn recurse_dirs(dir: &std::path::Path, f: &impl Fn(&std::path::Path)) { - for entry in std::fs::read_dir(dir).unwrap() { - let entry = entry.unwrap(); - let path = entry.path(); - if path.to_string_lossy().contains("target") { - continue; - } - if path.is_dir() { - recurse_dirs(&path, f); - } else { - f(&path); - } - } - } - #[test] fn no_dbgs() { - recurse_dirs(std::path::Path::new("."), &|path| { - if path.extension().is_none_or(|ext| ext != "rs") - || path.canonicalize().unwrap() - == std::path::Path::new(file!()).canonicalize().unwrap() - { - return; - } - let contents = std::fs::read_to_string(path).unwrap(); - for line in contents.lines() { - if line.contains("dbg!") && !line.trim().starts_with("//") { - panic!("File {} contains a dbg! macro", path.display()); - } - } - }); if crate::compile::invert::DEBUG { panic!("compile::invert::DEBUG is true"); } - if crate::ffi::DEBUG { - panic!("ffi::DEBUG is true"); - } if crate::compile::optimize::DEBUG { panic!("compile::optimize::DEBUG is true"); } @@ -401,31 +369,6 @@ mod tests { } } - #[test] - fn no_printlns() { - recurse_dirs(std::path::Path::new("."), &|path| { - if path.extension().is_none_or(|ext| ext != "rs") - || path.canonicalize().unwrap() - == std::path::Path::new(file!()).canonicalize().unwrap() - || path - .components() - .any(|c| c.as_os_str() == "main.rs" || c.as_os_str() == "profile.rs") - { - return; - } - let contents = std::fs::read_to_string(path).unwrap(); - for line in contents.lines() { - if line.contains("println!") - && !(line.trim().starts_with("//") - || line.contains("eprintln!") - || line.contains("// Allow println")) - { - panic!("File {} contains a println! macro", path.display()); - } - } - }); - } - #[test] fn external_bind_before() { let mut comp = Compiler::new(); diff --git a/src/main.rs b/src/main.rs index db36747cf..d909d8674 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![allow(clippy::print_stdout)] #[cfg(not(feature = "binary"))] compile_error!("To compile the uiua interpreter binary, you must enable the `binary` feature flag"); diff --git a/src/profile.rs b/src/profile.rs index f7c87a1c4..0c2d385cc 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -1,3 +1,4 @@ +#![allow(clippy::print_stdout)] #[macro_export] #[doc(hidden)] macro_rules! profile_function { @@ -297,8 +298,7 @@ Life ← ↥∩=₃⟜+⊸(/+↻⊂A₂C₂) } } println!( - "{:<26} | {:>7} {:>5} | {:>5} {:>5} |", - name, median_dur, media_dur_change, share, share_change + "{name:<26} | {median_dur:>7} {media_dur_change:>5} | {share:>5} {share_change:>5} |" ); } } diff --git a/src/run.rs b/src/run.rs index fc22edc4c..f42639428 100644 --- a/src/run.rs +++ b/src/run.rs @@ -274,6 +274,7 @@ impl Uiua { take(&mut self.rt.reports) } /// Print all pending reports + #[allow(clippy::print_stdout)] pub fn print_reports(&mut self) { for report in self.take_reports() { eprintln!("{report}"); @@ -790,6 +791,7 @@ impl Uiua { Ok(()) } }; + #[allow(clippy::print_stdout)] if self.rt.time_instrs { let end_time = self.rt.backend.now(); let padding = self.rt.call_stack.len().saturating_sub(1) * 2; diff --git a/src/sys/native.rs b/src/sys/native.rs index 889799768..f059dfde6 100644 --- a/src/sys/native.rs +++ b/src/sys/native.rs @@ -663,6 +663,7 @@ impl SysBackend for NativeSys { fn allow_thread_spawning(&self) -> bool { true } + #[allow(clippy::print_stdout)] #[cfg(all(feature = "terminal_image", feature = "image"))] fn show_image(&self, image: image::DynamicImage, _label: Option<&str>) -> Result<(), String> { let (_width, _height) = if let Some((w, h)) = terminal_size() { @@ -1279,6 +1280,7 @@ impl SysBackend for NativeSys { NATIVE_SYS.git_paths.insert(url.to_string(), res.clone()); res } + #[allow(clippy::print_stdout)] fn breakpoint(&self, env: &Uiua) -> Result { if !self.output_enabled() { return Ok(true); @@ -1299,6 +1301,7 @@ impl SysBackend for NativeSys { } } +#[allow(clippy::print_stdout)] #[doc(hidden)] pub fn print_stack(stack: &[Value], color: bool) { #[cfg(feature = "window")] diff --git a/tests_ffi/.clippy.toml b/tests_ffi/.clippy.toml new file mode 120000 index 000000000..c5ecbcbfa --- /dev/null +++ b/tests_ffi/.clippy.toml @@ -0,0 +1 @@ +../.clippy.toml \ No newline at end of file diff --git a/tests_ffi/Cargo.toml b/tests_ffi/Cargo.toml index 0efd52c4e..caa4971da 100644 --- a/tests_ffi/Cargo.toml +++ b/tests_ffi/Cargo.toml @@ -7,5 +7,8 @@ version = "0.1.0" crate-type = ["cdylib"] name = "ffi_lib" +[lints] +workspace = true + [dependencies] uiua.path = ".."