Skip to content

feat(lint): add scalafix linter#914

Open
rafikk wants to merge 12 commits into
aspect-build:mainfrom
rafikk:feat/scalafix-linter
Open

feat(lint): add scalafix linter#914
rafikk wants to merge 12 commits into
aspect-build:mainfrom
rafikk:feat/scalafix-linter

Conversation

@rafikk

@rafikk rafikk commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Supports Scalafix as a linter for Scala code. Scalafix is a refactoring and linting tool from Scala Center that supports both syntactic and semantic code analysis.

Scalafix produces lint diagnostics and rewrite patches for configured rules.

This aspect supports the built-in syntactic and semantic rules. We can amend it in the future to support custom plugins, but I have not yet had a need for this.

Notes:

  • Scalafix only produces output in one mode which consists of a mixture of diagnostic lines and rewrite patches. When a configured Scalafix rule is able to produce rewrites, it prints a patch but does not print a diagnostic line, meaning the SARIF reports that this aspects produce are not as precise as would be ideal. We can only produce a generic "Scalafix rewrite suggested" line for diagnostics with rewrites. I've opened an upstream issue to discuss producing diagnostic-only ouput and hope to find time to work on it: Provide machine-readable output for lint & rewrite rules scalacenter/scalafix#2459
  • This PR is based on draft in feat: Add scalafix linter support #711 which stalled. I've used the original PR as a starting point.

Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: yes
  • Breaking change (forces users to change their own code or config): no
  • Suggested release notes appear below: yes

Suggested Release Notes

Scala targets can not be linted using scalafix.

Test plan

  • New test cases added

@CLAassistant

CLAassistant commented Jun 17, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rafikk rafikk force-pushed the feat/scalafix-linter branch 4 times, most recently from ec4584b to c23503e Compare June 17, 2026 13:08
Comment thread MODULE.bazel Outdated
bazel_dep(name = "rules_shell", version = "0.5.0")
bazel_dep(name = "rules_java", version = "7.0.6")
bazel_dep(name = "rules_cc", version = "0.2.0")
bazel_dep(name = "rules_scala", version = "7.1.6")

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.

I don't want to add any new deps here as this now effects the module versions of any rules_lint user such as pulling in rules_java - who cares if the rules_lint user doesn't use it, but a rules_lint user might not want rules_java being bumped due to a linter.

I'm proposing any lint tools that require a bazel_dep (other then maybe skylib or bazel-lib) live in their own MODULE. See the new aspect_rules_lint_rust MODULE for the first example - that one is now published to BCR and everything.

In rules_lint v3 I'm proposing everything move out of this root MODULE, for now I just want to avoid adding new ones.

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.

Thanks for the review @jbedard.

I've moved the scalafix linter into a new module aspect_rules_lint_scala and updated the example code.

Note that this PR still requires changes to the SARIF processor in rules_lint, so the flow here has to be: publish a new rules_lint release with the changes, bump the minimum rules_lint version for scala, and then publish the new aspect_rules_lint_scala release. Let me know if that sounds right to you.

@rafikk rafikk force-pushed the feat/scalafix-linter branch 2 times, most recently from 6bc3287 to 394d756 Compare June 18, 2026 13:57
@rafikk rafikk requested a review from jbedard June 18, 2026 13:59
@rafikk

rafikk commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

The CI failure for CI - Vanilla Bazel / integration-test (examples/scala) (pull_request) looks like an infra / repo setup issue.

@rafikk rafikk force-pushed the feat/scalafix-linter branch from 394d756 to fb8e6d2 Compare June 19, 2026 10:14
@rafikk rafikk force-pushed the feat/scalafix-linter branch 3 times, most recently from 7a44f4c to 966a1f4 Compare June 22, 2026 10:47
@rafikk rafikk requested a review from thesayyn as a code owner June 22, 2026 10:47
@rafikk

rafikk commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

CI is green now. @jbedard, would you mind taking a look?

@rafikk rafikk force-pushed the feat/scalafix-linter branch from 966a1f4 to cb281bc Compare June 22, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants