iceberg-rust icon indicating copy to clipboard operation
iceberg-rust copied to clipboard

[WIP] Add precommit hook for linting and formatting

Open dentiny opened this issue 8 months ago • 0 comments

What changes are included in this PR?

This PR adds linting and formatting logic into precommit hook, the code is copied from CI setup to keep consistency. https://github.com/apache/iceberg-rust/blob/5677d446dec1361459d42a6c3672d8ec605a289a/.github/workflows/ci.yml#L52-L60

The motivation behind is to uncover problems earlier at local environment, rather than CI, which is time-consuming and requires extra round-trip.

Are these changes tested?

I intentionally made bad code changes, and confirm precommit hook works as expected. Example output:

[/workspaces/iceberg-rust] (hjiang/add-precommit-hook) 
vscode@a9c6eedd4430$ git push 
format...................................................................Failed
- hook id: format
- exit code: 1

error: unexpected token: `(`
  --> /workspaces/iceberg-rust/crates/iceberg/src/transaction/mod.rs:61:39
   |
61 |             metadata_builder = update.().apply(metadata_builder)?;
   |                                       ^

Error writing files: failed to resolve mod `transaction`: cannot parse /workspaces/iceberg-rust/crates/iceberg/src/transaction/mod.rs

clipper..................................................................Failed
- hook id: clipper
- exit code: 101

    Checking iceberg v0.4.0 (/workspaces/iceberg-rust/crates/iceberg)
    Checking iceberg_test_utils v0.4.0 (/workspaces/iceberg-rust/crates/test_utils)
    Checking iceberg-sqllogictest v0.4.0 (/workspaces/iceberg-rust/crates/sqllogictest)
error: unexpected token: `(`
  --> crates/iceberg/src/transaction/mod.rs:61:39
   |
61 |             metadata_builder = update.().apply(metadata_builder)?;
   |                                       ^

error[E0618]: expected function, found `&catalog::TableUpdate`
  --> crates/iceberg/src/transaction/mod.rs:61:32
   |
60 |         for update in updates {
   |             ------ `update` has type `&catalog::TableUpdate`
61 |             metadata_builder = update.().apply(metadata_builder)?;
   |                                ^^^^^^---
   |                                |
   |                                call expression requires function

For more information about this error, try `rustc --explain E0618`.
error: could not compile `iceberg` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...

error: failed to push some refs to 'github.com:dentiny/iceberg-rust.git'

dentiny avatar Apr 27 '25 09:04 dentiny