Skip to content

dev: Add a script to auto fix all lint violations#19560

Merged
2010YOUY01 merged 5 commits intoapache:mainfrom
2010YOUY01:auto-fix
Jan 14, 2026
Merged

dev: Add a script to auto fix all lint violations#19560
2010YOUY01 merged 5 commits intoapache:mainfrom
2010YOUY01:auto-fix

Conversation

@2010YOUY01
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Part of #19227

Rationale for this change

See issue for details.

The existing script ./dev/rust_lint.sh do checks for all non-functional tests include formater/clippy checks.

Some check tools support auto fix options, so this PR add an option to the lint scripts to perform auto-fixes.

Now ./dev/rust_lint.sh --write --allow-dirty can perform auto-fixes for all linter etc. violations

yongting@Yongtings-MacBook-Pro-2 ~/C/datafusion (auto-fix)> ./dev/rust_lint.sh --help
Usage: ./dev/rust_lint.sh [--write] [--allow-dirty]

Runs the local Rust lint suite similar to CI.
--write        Run formatters, clippy and other non-functional checks in best-effort write/fix mode (requires a clean git worktree, no uncommitted changes; some checks are test-only and ignore this flag).
--allow-dirty  Allow `--write` to run even when the git worktree has uncommitted changes.

What changes are included in this PR?

  • Adds [--write] [--allow-dirty] flag to rust_lint.sh to support auto fixes
  • rust_lint.sh consists of several sub-scripts like rust_fmt.sh, they're all extended with auto-fix feature through --write flag, and the rust_lint.sh is optionally calling them with an additional flag for auto fixes.
  • Clean up rust_lint.sh

Are these changes tested?

Yes, commit 8c99417 intentionally introduced one violation for each available lint check, and the auto-fix command is able to fix all of them.

The test may not be comprehensive, but it provides a reasonable starting point. We can begin using this script now and iterate on it if we discover cases where the auto-fix does not behave correctly.

Are there any user-facing changes?

No

@github-actions github-actions Bot added the development-process Related to development process of DataFusion label Dec 30, 2025

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
PRETTIER_VERSION="2.7.1"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to keep using this old version ?
Latest is https://www.npmjs.com/package/prettier/v/3.7.4

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think it's supposed to get updated manually.
We can do so separately since it might have a large code diff.

Comment thread ci/scripts/utils/git.sh
Comment thread ci/scripts/rust_fmt.sh Outdated
else
echo "[${SCRIPT_NAME}] \`cargo fmt --all -- --check\`"
cargo fmt --all -- --check
fi No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It seems there is no newline (\n) at the end here (non POSIX complaint).
It is recommended to have it otherwise "it may break some old tools".
Even Github UI marks it as a warning.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, updated.

Perhaps we should introduce some lint tools to check the existing bash scripts, to prevent similar issues in the future 🤔

Comment thread dev/rust_lint.sh Outdated
Comment thread ci/scripts/license_header.sh
Comment thread ci/scripts/rust_clippy.sh Outdated
Comment thread dev/rust_lint.sh Outdated
@2010YOUY01
Copy link
Copy Markdown
Contributor Author

@martin-g Thank you for the review, all comments are addressed in ae7fc70

After the change, I have tested again the following step, and it's working as expected.

Are these changes tested?

Yes, commit 8c99417 intentionally introduced one violation for each available lint check, and the auto-fix command is able to fix all of them.

The test may not be comprehensive, but it provides a reasonable starting point. We can begin using this script now and iterate on it if we discover cases where the auto-fix does not behave correctly.

@2010YOUY01 2010YOUY01 added this pull request to the merge queue Jan 14, 2026
Merged via the queue into apache:main with commit 6bf5e98 Jan 14, 2026
28 checks passed
de-bgunter pushed a commit to de-bgunter/datafusion that referenced this pull request Mar 24, 2026
## Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes apache#123` indicates that this PR will close issue apache#123.
-->

Part of apache#19227

## Rationale for this change

<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
See issue for details.

The existing script `./dev/rust_lint.sh` do checks for all
non-functional tests include formater/clippy checks.

Some check tools support auto fix options, so this PR add an option to
the lint scripts to perform auto-fixes.

Now `./dev/rust_lint.sh --write --allow-dirty` can perform auto-fixes
for all linter etc. violations

```
yongting@Yongtings-MacBook-Pro-2 ~/C/datafusion (auto-fix)> ./dev/rust_lint.sh --help
Usage: ./dev/rust_lint.sh [--write] [--allow-dirty]

Runs the local Rust lint suite similar to CI.
--write        Run formatters, clippy and other non-functional checks in best-effort write/fix mode (requires a clean git worktree, no uncommitted changes; some checks are test-only and ignore this flag).
--allow-dirty  Allow `--write` to run even when the git worktree has uncommitted changes.
```

## What changes are included in this PR?

<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
- Adds `[--write] [--allow-dirty]` flag to `rust_lint.sh` to support
auto fixes
- `rust_lint.sh` consists of several sub-scripts like `rust_fmt.sh`,
they're all extended with auto-fix feature through `--write` flag, and
the `rust_lint.sh` is optionally calling them with an additional flag
for auto fixes.
- Clean up `rust_lint.sh`

## Are these changes tested?

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->

Yes, commit 8c99417 intentionally
introduced one violation for each available lint check, and the auto-fix
command is able to fix all of them.

The test may not be comprehensive, but it provides a reasonable starting
point. We can begin using this script now and iterate on it if we
discover cases where the auto-fix does not behave correctly.

## Are there any user-facing changes?
No
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->

<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

development-process Related to development process of DataFusion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants