diff --git a/.github/workflows/ql-for-ql-tests.yml b/.github/workflows/ql-for-ql-tests.yml index bc247165198a..4502dded53f4 100644 --- a/.github/workflows/ql-for-ql-tests.yml +++ b/.github/workflows/ql-for-ql-tests.yml @@ -40,7 +40,7 @@ jobs: ql/target key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-qltest-cargo-${{ hashFiles('ql/rust-toolchain.toml', 'ql/**/Cargo.lock') }} - name: Check formatting - run: cd ql; cargo fmt --all -- --check + run: cd ql; cargo fmt -- --check - name: Build extractor run: | cd ql; diff --git a/.github/workflows/ruby-build.yml b/.github/workflows/ruby-build.yml index b1ae2e2b7db1..343e896151c2 100644 --- a/.github/workflows/ruby-build.yml +++ b/.github/workflows/ruby-build.yml @@ -79,7 +79,7 @@ jobs: key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-ruby-rust-cargo-${{ hashFiles('ruby/extractor/rust-toolchain.toml', 'ruby/extractor/**/Cargo.lock') }} - name: Check formatting if: steps.cache-extractor.outputs.cache-hit != 'true' - run: cd extractor && cargo fmt --all -- --check + run: cd extractor && cargo fmt -- --check - name: Build if: steps.cache-extractor.outputs.cache-hit != 'true' run: cd extractor && cargo build --verbose diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e5f4bb2140f5..cc880072555e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -23,26 +23,48 @@ permissions: contents: read jobs: - rust-code: + rust-ast-generator: runs-on: ubuntu-latest + defaults: + run: + working-directory: rust/ast-generator steps: - name: Checkout uses: actions/checkout@v4 + - name: Inject sources + shell: bash + run: | + bazel run //rust/ast-generator:inject-sources - name: Format - working-directory: rust/extractor shell: bash run: | cargo fmt --check - name: Compilation - working-directory: rust/extractor shell: bash run: cargo check - name: Clippy + shell: bash + run: | + cargo clippy --no-deps -- -D warnings + rust-code: + runs-on: ubuntu-latest + defaults: + run: working-directory: rust/extractor + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Format + shell: bash + run: | + cargo fmt --check + - name: Compilation + shell: bash + run: cargo check + - name: Clippy shell: bash run: | - cargo clippy --fix - git diff --exit-code + cargo clippy --no-deps -- -D warnings rust-codegen: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/tree-sitter-extractor-test.yml b/.github/workflows/tree-sitter-extractor-test.yml index acc68e7ec2c7..9a71e1fc7c54 100644 --- a/.github/workflows/tree-sitter-extractor-test.yml +++ b/.github/workflows/tree-sitter-extractor-test.yml @@ -32,17 +32,17 @@ jobs: steps: - uses: actions/checkout@v4 - name: Check formatting - run: cargo fmt --all -- --check + run: cargo fmt -- --check - name: Run tests run: cargo test --verbose fmt: - runs-on: ubuntu-latest + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Check formatting run: cargo fmt --check clippy: - runs-on: ubuntu-latest + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run clippy diff --git a/ql/ql/test/dataflow/getAStringValue/getAStringValue.expected b/ql/ql/test/dataflow/getAStringValue/getAStringValue.expected index 48de9172b362..e69de29bb2d1 100644 --- a/ql/ql/test/dataflow/getAStringValue/getAStringValue.expected +++ b/ql/ql/test/dataflow/getAStringValue/getAStringValue.expected @@ -1,2 +0,0 @@ -failures -testFailures diff --git a/rust/ast-generator/BUILD.bazel b/rust/ast-generator/BUILD.bazel index b9a4baf018d6..b5956d096067 100644 --- a/rust/ast-generator/BUILD.bazel +++ b/rust/ast-generator/BUILD.bazel @@ -75,7 +75,7 @@ write_file( 'DST_DIR="$(dirname "$(rlocation "$1")")"', 'mkdir -p "$DST_DIR/src/codegen/grammar"', ] + [ - 'cp "$(rlocation "$%s")" "$DST_DIR/%s"' % item + 'cp -f --no-preserve=mode "$(rlocation "$%s")" "$DST_DIR/%s"' % item for item in enumerate(_codegen_outs, 2) ], is_executable = True, diff --git a/rust/ast-generator/patches/rust-analyzer.patch b/rust/ast-generator/patches/rust-analyzer.patch index dceb60fbf4c2..e799e90f48a4 100644 --- a/rust/ast-generator/patches/rust-analyzer.patch +++ b/rust/ast-generator/patches/rust-analyzer.patch @@ -1,16 +1,19 @@ diff --git a/xtask/src/codegen/grammar.rs b/xtask/src/codegen/grammar.rs -index e7534582f2..8bc9237737 100644 +index e7534582f2..49c96f1be3 100644 --- a/xtask/src/codegen/grammar.rs +++ b/xtask/src/codegen/grammar.rs -@@ -3,6 +3,7 @@ +@@ -3,7 +3,9 @@ //! Specifically, it generates the `SyntaxKind` enum and a number of newtype //! wrappers around `SyntaxNode` which implement `syntax::AstNode`. +-#![allow(clippy::disallowed_types)] +#![allow(warnings)] - #![allow(clippy::disallowed_types)] ++#![allow(clippy)] ++#![cfg_attr(any(), rustfmt::skip)] use std::{ -@@ -23,7 +24,7 @@ use crate::{ + collections::{BTreeSet, HashSet}, +@@ -23,7 +25,7 @@ use crate::{ project_root, }; @@ -19,7 +22,7 @@ index e7534582f2..8bc9237737 100644 use self::ast_src::{AstEnumSrc, AstNodeSrc, AstSrc, Cardinality, Field, KindsSrc}; pub(crate) fn generate(check: bool) { -@@ -624,7 +625,7 @@ fn pluralize(s: &str) -> String { +@@ -624,7 +626,7 @@ fn pluralize(s: &str) -> String { } impl Field { @@ -28,7 +31,7 @@ index e7534582f2..8bc9237737 100644 matches!(self, Field::Node { cardinality: Cardinality::Many, .. }) } fn token_kind(&self) -> Option { -@@ -636,7 +637,7 @@ impl Field { +@@ -636,7 +638,7 @@ impl Field { _ => None, } } @@ -37,7 +40,7 @@ index e7534582f2..8bc9237737 100644 match self { Field::Token(name) => { let name = match name.as_str() { -@@ -682,7 +683,7 @@ impl Field { +@@ -682,7 +684,7 @@ impl Field { } } } @@ -46,7 +49,7 @@ index e7534582f2..8bc9237737 100644 match self { Field::Token(_) => format_ident!("SyntaxToken"), Field::Node { ty, .. } => format_ident!("{}", ty), -@@ -699,7 +700,7 @@ fn clean_token_name(name: &str) -> String { +@@ -699,7 +701,7 @@ fn clean_token_name(name: &str) -> String { } } @@ -55,3 +58,16 @@ index e7534582f2..8bc9237737 100644 let mut res = AstSrc { tokens: "Whitespace Comment String ByteString CString IntNumber FloatNumber Char Byte Ident" +diff --git a/xtask/src/codegen/grammar/ast_src.rs b/xtask/src/codegen/grammar/ast_src.rs +index 9269d15423..babe7ca1bf 100644 +--- a/xtask/src/codegen/grammar/ast_src.rs ++++ b/xtask/src/codegen/grammar/ast_src.rs +@@ -1,5 +1,8 @@ + //! Defines input for code generation process. + ++#![allow(clippy)] ++#![cfg_attr(any(), rustfmt::skip)] ++ + use quote::ToTokens; + + use crate::codegen::grammar::to_upper_snake_case; diff --git a/rust/ast-generator/src/main.rs b/rust/ast-generator/src/main.rs index a0e524689c12..2cc77fe5fff1 100644 --- a/rust/ast-generator/src/main.rs +++ b/rust/ast-generator/src/main.rs @@ -9,8 +9,7 @@ use std::env; use ungrammar::Grammar; fn project_root() -> PathBuf { - let dir = - env::var("CARGO_MANIFEST_DIR").unwrap().to_owned(); + let dir = env::var("CARGO_MANIFEST_DIR").unwrap().to_owned(); PathBuf::from(dir).parent().unwrap().to_owned() } @@ -593,7 +592,7 @@ impl Translator<'_> {{ fn main() -> std::io::Result<()> { let grammar = PathBuf::from("..").join(env::args().nth(1).expect("grammar file path required")); let grammar: Grammar = fs::read_to_string(&grammar) - .expect(&format!("Failed to parse grammar file: {}", grammar.display())) + .unwrap_or_else(|_| panic!("Failed to parse grammar file: {}", grammar.display())) .parse() .expect("Failed to parse grammar"); let mut grammar = codegen::grammar::lower(&grammar); diff --git a/rust/lint.py b/rust/lint.py index 3a231c157df3..bb3109a0f501 100755 --- a/rust/lint.py +++ b/rust/lint.py @@ -10,9 +10,11 @@ cargo = shutil.which("cargo") assert cargo, "no cargo binary found on `PATH`" -fmt = subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir) +runs = [] +runs.append(subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir)) + for manifest in this_dir.rglob("Cargo.toml"): if not manifest.is_relative_to(this_dir / "ql") and not manifest.is_relative_to(this_dir / "integration-tests"): - clippy = subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet"], - cwd=manifest.parent) -sys.exit(fmt.returncode or clippy.returncode) + runs.append(subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet", "--", "-D", "warnings"], + cwd=manifest.parent)) +sys.exit(max(r.returncode for r in runs))