Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: fix rust formatting #18328

Merged
merged 7 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ql-for-ql-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ruby-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 27 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- -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 -- -D warnings
rust-codegen:
runs-on: ubuntu-latest
steps:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tree-sitter-extractor-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rust/ast-generator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 24 additions & 8 deletions rust/ast-generator/patches/rust-analyzer.patch
Original file line number Diff line number Diff line change
@@ -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},
aibaars marked this conversation as resolved.
Show resolved Hide resolved
@@ -23,7 +25,7 @@ use crate::{
project_root,
};

Expand All @@ -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 {
Expand All @@ -28,7 +31,7 @@ index e7534582f2..8bc9237737 100644
matches!(self, Field::Node { cardinality: Cardinality::Many, .. })
}
fn token_kind(&self) -> Option<proc_macro2::TokenStream> {
@@ -636,7 +637,7 @@ impl Field {
@@ -636,7 +638,7 @@ impl Field {
_ => None,
}
}
Expand All @@ -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 {
}
}
}
Expand All @@ -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 {
}
}

Expand All @@ -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;
aibaars marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 2 additions & 3 deletions rust/ast-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions rust/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Loading