-
Notifications
You must be signed in to change notification settings - Fork 460
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
obsolete - Add support for linters #1097
Conversation
…ly` (the line numbers in a lint will change depending on whether the `apply` already ran or not).
…as formatted as they can be, except for lints.
…as formatted as they can be, except for lints.
…lf, and tries to parse a line number from the error message.
…lint paradigm. The old way made it impossible to detect lost tags if `apply` always succeeds.
… only used to annnotate errors, which is now done by the lint phase.
…e file as linted, rather than just the first line.
fe898e8
to
a1974be
Compare
a1974be
to
481aa49
Compare
I have been convinced that this is totally worth doing. There are three reasons:
I'm not sure if reason 3 is a good idea or not, but reasons 1 and 2 alone make it worthwhile. In terms of disruption to our stakeholders:
The existing PR's have all gone stale (a year old), but I'll be reusing them by force-pushing. |
@nedtwigg Haha, I've only just seen your request for me to review this January last year, so sorry about that. Let me know when you're finished with this PR, and I'd be more than happy to review it. :) |
Thanks! It'll probably be a week or two before it's ready :) |
On the subject of OpenRewrite, I've actually used it a bit on a small project with some success. But IIRC it focuses purely on "solving" rather than "yelling", not to mention it already has a Gradle plugin, so it's not clear to me how Spotless linting would help. I don't suppose you can remember why you mentioned it now, can you? But perhaps an advantage of incorporating OpenRewrite into Spotless would be the speed gained from Spotless's caching mechanism (at least on the Gradle side). |
I did not dig into the PR, but maybe this limitation is slightly stricter for now: 'the linter must do source-only analysis, one a per-file basis'. i.e. I suspect the first iteration will not be able to receive a whole Set of source-files in a single batch.
OpenRewrite behave (much) better when called on a source-set, than on each individual files.
I agree. (I integrated it as an underlying engine of CleanThat, which is focused on solving than yelling)
About |
Is this PR still relevant for a future release although it was labeled as "pr-archive"? |
This PR is absolutely still relevant to a future release, but it will be a while. |
Hello I'd be interested in having this feature implemented and released. How would I be able to help contribute to getting this merged? I haven't contributed to open source before so sorry if this is a newbie Q |
@WillHolbrook which linter would you like to use? Merging this is blocked on me, but I could use help testing the API with specific steps that need the linter. |
01f73c0
to
fe898e8
Compare
Replaced by #2149 |
This is just a proposal, open to other UIs / designs / implementations
This PR adds a
Lint
pojo, as well as the new methodFormatterFunc::lint
with the following default implementation:spotless/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java
Lines 41 to 44 in e8e5df5
We now split formatting into two parts: the composable
String -> String
part and the non-composableList<Lint>
part. Before this PR, the only way to "lint" was to throw a single exception. In this PR, those exceptions are now caught and transformed into a lint 7a1e72a which has the following implications:apply
always succeeds (it traps errors and continues, rather than bubbling them up to the user)check
shows every exception to the user at once (with a best-guess line number from parsing the error message)spotless:off/on
across formatters and linters (take toggleOffOn into account for linters #719)FormatExceptionPolicy
, just aLintSuppressionPolicy
dd5165fGradle integration notes
There's an interesting subtlety here specific to the Gradle plugin, but it could also matter for maven if we go further with up-to-date checking. The
spotlessJava
task generates a folder of "clean" files for each file which is found to be unclean. Here (a25eded) we extend that to also have a folder of "lint" files for each file found to have non-zero lints . However, the lints will be different if the user calls./gradlew spotlessCheck
or instead./gradlew spotlessApply spotlessCheck
. The "clean" content will be the same, but the line numbers and content of the lints will depend on whetherapply
was called or not,spotlessJava
can't know that ahead of time, so for now we just compute the lints twice (89339cd). That's not as expensive as it seems because we can skip the double-compute for clean files, which is almost-always almost-all files.Open questions
There might be other things to think about too, but these are what is on my mind:
spotlessApply
fail if there are any lints?apply
always succeedsspotlessCheck
(we could makeapplyFailsOnLint = true
available as an option)fooLint().level('info').confidence(70)
, so that each step can handle thatspotlessCheck
could add comments and suggested fix to GitHub PR #655Moving forward
It would be great to have some draft PRs based on this
feat/lint
branch that exercise the newlint
method. I'm very confident thatFormatterStep
andFormatterFunc
are stable. The uncertain part is what fieldsLint
will have, and that will be determined by a combination of:This is a big change so it will happen slowly :)