Skip to content

Commit 2b2a373

Browse files
authored
Merge pull request #18328 from github/redsun82/fix-cargo-fmt-checks
CI: fix rust formatting
2 parents d5571c5 + 8e28d99 commit 2b2a373

File tree

9 files changed

+65
-28
lines changed

9 files changed

+65
-28
lines changed

.github/workflows/ql-for-ql-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
ql/target
4141
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-qltest-cargo-${{ hashFiles('ql/rust-toolchain.toml', 'ql/**/Cargo.lock') }}
4242
- name: Check formatting
43-
run: cd ql; cargo fmt --all -- --check
43+
run: cd ql; cargo fmt -- --check
4444
- name: Build extractor
4545
run: |
4646
cd ql;

.github/workflows/ruby-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-ruby-rust-cargo-${{ hashFiles('ruby/extractor/rust-toolchain.toml', 'ruby/extractor/**/Cargo.lock') }}
8080
- name: Check formatting
8181
if: steps.cache-extractor.outputs.cache-hit != 'true'
82-
run: cd extractor && cargo fmt --all -- --check
82+
run: cd extractor && cargo fmt -- --check
8383
- name: Build
8484
if: steps.cache-extractor.outputs.cache-hit != 'true'
8585
run: cd extractor && cargo build --verbose

.github/workflows/rust.yml

+27-5
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,48 @@ permissions:
2323
contents: read
2424

2525
jobs:
26-
rust-code:
26+
rust-ast-generator:
2727
runs-on: ubuntu-latest
28+
defaults:
29+
run:
30+
working-directory: rust/ast-generator
2831
steps:
2932
- name: Checkout
3033
uses: actions/checkout@v4
34+
- name: Inject sources
35+
shell: bash
36+
run: |
37+
bazel run //rust/ast-generator:inject-sources
3138
- name: Format
32-
working-directory: rust/extractor
3339
shell: bash
3440
run: |
3541
cargo fmt --check
3642
- name: Compilation
37-
working-directory: rust/extractor
3843
shell: bash
3944
run: cargo check
4045
- name: Clippy
46+
shell: bash
47+
run: |
48+
cargo clippy --no-deps -- -D warnings
49+
rust-code:
50+
runs-on: ubuntu-latest
51+
defaults:
52+
run:
4153
working-directory: rust/extractor
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
- name: Format
58+
shell: bash
59+
run: |
60+
cargo fmt --check
61+
- name: Compilation
62+
shell: bash
63+
run: cargo check
64+
- name: Clippy
4265
shell: bash
4366
run: |
44-
cargo clippy --fix
45-
git diff --exit-code
67+
cargo clippy --no-deps -- -D warnings
4668
rust-codegen:
4769
runs-on: ubuntu-latest
4870
steps:

.github/workflows/tree-sitter-extractor-test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ jobs:
3232
steps:
3333
- uses: actions/checkout@v4
3434
- name: Check formatting
35-
run: cargo fmt --all -- --check
35+
run: cargo fmt -- --check
3636
- name: Run tests
3737
run: cargo test --verbose
3838
fmt:
39-
runs-on: ubuntu-latest
39+
runs-on: ubuntu-latest
4040
steps:
4141
- uses: actions/checkout@v4
4242
- name: Check formatting
4343
run: cargo fmt --check
4444
clippy:
45-
runs-on: ubuntu-latest
45+
runs-on: ubuntu-latest
4646
steps:
4747
- uses: actions/checkout@v4
4848
- name: Run clippy
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
failures
2-
testFailures

rust/ast-generator/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ write_file(
7575
'DST_DIR="$(dirname "$(rlocation "$1")")"',
7676
'mkdir -p "$DST_DIR/src/codegen/grammar"',
7777
] + [
78-
'cp "$(rlocation "$%s")" "$DST_DIR/%s"' % item
78+
'cp -f --no-preserve=mode "$(rlocation "$%s")" "$DST_DIR/%s"' % item
7979
for item in enumerate(_codegen_outs, 2)
8080
],
8181
is_executable = True,
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
diff --git a/xtask/src/codegen/grammar.rs b/xtask/src/codegen/grammar.rs
2-
index e7534582f2..8bc9237737 100644
2+
index e7534582f2..49c96f1be3 100644
33
--- a/xtask/src/codegen/grammar.rs
44
+++ b/xtask/src/codegen/grammar.rs
5-
@@ -3,6 +3,7 @@
5+
@@ -3,7 +3,9 @@
66
//! Specifically, it generates the `SyntaxKind` enum and a number of newtype
77
//! wrappers around `SyntaxNode` which implement `syntax::AstNode`.
88

9+
-#![allow(clippy::disallowed_types)]
910
+#![allow(warnings)]
10-
#![allow(clippy::disallowed_types)]
11+
+#![allow(clippy)]
12+
+#![cfg_attr(any(), rustfmt::skip)]
1113

1214
use std::{
13-
@@ -23,7 +24,7 @@ use crate::{
15+
collections::{BTreeSet, HashSet},
16+
@@ -23,7 +25,7 @@ use crate::{
1417
project_root,
1518
};
1619

@@ -19,7 +22,7 @@ index e7534582f2..8bc9237737 100644
1922
use self::ast_src::{AstEnumSrc, AstNodeSrc, AstSrc, Cardinality, Field, KindsSrc};
2023

2124
pub(crate) fn generate(check: bool) {
22-
@@ -624,7 +625,7 @@ fn pluralize(s: &str) -> String {
25+
@@ -624,7 +626,7 @@ fn pluralize(s: &str) -> String {
2326
}
2427

2528
impl Field {
@@ -28,7 +31,7 @@ index e7534582f2..8bc9237737 100644
2831
matches!(self, Field::Node { cardinality: Cardinality::Many, .. })
2932
}
3033
fn token_kind(&self) -> Option<proc_macro2::TokenStream> {
31-
@@ -636,7 +637,7 @@ impl Field {
34+
@@ -636,7 +638,7 @@ impl Field {
3235
_ => None,
3336
}
3437
}
@@ -37,7 +40,7 @@ index e7534582f2..8bc9237737 100644
3740
match self {
3841
Field::Token(name) => {
3942
let name = match name.as_str() {
40-
@@ -682,7 +683,7 @@ impl Field {
43+
@@ -682,7 +684,7 @@ impl Field {
4144
}
4245
}
4346
}
@@ -46,7 +49,7 @@ index e7534582f2..8bc9237737 100644
4649
match self {
4750
Field::Token(_) => format_ident!("SyntaxToken"),
4851
Field::Node { ty, .. } => format_ident!("{}", ty),
49-
@@ -699,7 +700,7 @@ fn clean_token_name(name: &str) -> String {
52+
@@ -699,7 +701,7 @@ fn clean_token_name(name: &str) -> String {
5053
}
5154
}
5255

@@ -55,3 +58,16 @@ index e7534582f2..8bc9237737 100644
5558
let mut res = AstSrc {
5659
tokens:
5760
"Whitespace Comment String ByteString CString IntNumber FloatNumber Char Byte Ident"
61+
diff --git a/xtask/src/codegen/grammar/ast_src.rs b/xtask/src/codegen/grammar/ast_src.rs
62+
index 9269d15423..babe7ca1bf 100644
63+
--- a/xtask/src/codegen/grammar/ast_src.rs
64+
+++ b/xtask/src/codegen/grammar/ast_src.rs
65+
@@ -1,5 +1,8 @@
66+
//! Defines input for code generation process.
67+
68+
+#![allow(clippy)]
69+
+#![cfg_attr(any(), rustfmt::skip)]
70+
+
71+
use quote::ToTokens;
72+
73+
use crate::codegen::grammar::to_upper_snake_case;

rust/ast-generator/src/main.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use std::env;
99
use ungrammar::Grammar;
1010

1111
fn project_root() -> PathBuf {
12-
let dir =
13-
env::var("CARGO_MANIFEST_DIR").unwrap().to_owned();
12+
let dir = env::var("CARGO_MANIFEST_DIR").unwrap().to_owned();
1413
PathBuf::from(dir).parent().unwrap().to_owned()
1514
}
1615

@@ -593,7 +592,7 @@ impl Translator<'_> {{
593592
fn main() -> std::io::Result<()> {
594593
let grammar = PathBuf::from("..").join(env::args().nth(1).expect("grammar file path required"));
595594
let grammar: Grammar = fs::read_to_string(&grammar)
596-
.expect(&format!("Failed to parse grammar file: {}", grammar.display()))
595+
.unwrap_or_else(|_| panic!("Failed to parse grammar file: {}", grammar.display()))
597596
.parse()
598597
.expect("Failed to parse grammar");
599598
let mut grammar = codegen::grammar::lower(&grammar);

rust/lint.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
cargo = shutil.which("cargo")
1111
assert cargo, "no cargo binary found on `PATH`"
1212

13-
fmt = subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir)
13+
runs = []
14+
runs.append(subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir))
15+
1416
for manifest in this_dir.rglob("Cargo.toml"):
1517
if not manifest.is_relative_to(this_dir / "ql") and not manifest.is_relative_to(this_dir / "integration-tests"):
16-
clippy = subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet"],
17-
cwd=manifest.parent)
18-
sys.exit(fmt.returncode or clippy.returncode)
18+
runs.append(subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet", "--", "-D", "warnings"],
19+
cwd=manifest.parent))
20+
sys.exit(max(r.returncode for r in runs))

0 commit comments

Comments
 (0)