You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: CHANGES.md
+8
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,15 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
11
11
12
12
## [Unreleased]
13
13
### Added
14
+
* APIs to support linting. (implemented in [#2148](https://github.com/diffplug/spotless/pull/2148) and [#2149](https://github.com/diffplug/spotless/pull/2149))
15
+
* Spotless is still primarily a formatter, not a linter. But when formatting fails, it's more flexible to model those failures as lints so that the formatting can continue and ideally we can also capture the line numbers causing the failure.
16
+
*`Lint` models a single change. A `FormatterStep` can create a lint by:
17
+
* throwing an exception during formatting, ideally `throw Lint.atLine(127, "code", "Well what happened was...")`
18
+
* or by implementing the `List<Lint> lint(String content, File file)` method to create multiple of them
14
19
* Support for line ending policy `PRESERVE` which just takes the first line ending of every given file as setting (no matter if `\n`, `\r\n` or `\r`) ([#2304](https://github.com/diffplug/spotless/pull/2304))
20
+
### Changes
21
+
***BREAKING** Moved `PaddedCell.DirtyState` to its own top-level class with new methods. ([#2148](https://github.com/diffplug/spotless/pull/2148))
22
+
***BREAKING** Removed `isClean`, `applyTo`, and `applyToAndReturnResultIfDirty` from `Formatter` because users should instead use `DirtyState`.
15
23
### Fixed
16
24
*`ktlint` steps now read from the `string` instead of the `file` so they don't clobber earlier steps. (fixes [#1599](https://github.com/diffplug/spotless/issues/1599))
Copy file name to clipboardexpand all lines: CONTRIBUTING.md
+9-1
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,6 @@ Here's a checklist for creating a new step for Spotless:
93
93
-[ ] Class name ends in Step, `SomeNewStep`.
94
94
-[ ] Class has a public static method named `create` that returns a `FormatterStep`.
95
95
-[ ] Has a test class named `SomeNewStepTest` that uses `StepHarness` or `StepHarnessWithFile` to test the step.
96
-
-[ ] Start with `StepHarness.forStep(myStep).supportsRoundTrip(false)`, and then add round trip support as described in the next section.
97
96
-[ ] Test class has test methods to verify behavior.
98
97
-[ ] Test class has a test method `equality()` which tests equality using `StepEqualityTester` (see existing methods for examples).
99
98
@@ -137,6 +136,15 @@ There are many great formatters (prettier, clang-format, black, etc.) which live
137
136
138
137
Because of Spotless' up-to-date checking and [git ratcheting](https://github.com/diffplug/spotless/tree/main/plugin-gradle#ratchet), Spotless actually doesn't have to call formatters very often, so even an expensive shell call for every single invocation isn't that bad. Anything that works is better than nothing, and we can always speed things up later if it feels too slow (but it probably won't).
139
138
139
+
## Lints
140
+
141
+
Spotless is primarily a formatter, not a linter. But, if something goes wrong during formatting, it's better to model that as a lint with line numbers rather than just a naked exception. There are two ways to go about this:
142
+
143
+
- at any point during the formatting process, you can throw a `Lint.atLine(int line, ...)` exception. This will be caught and turned into a lint.
144
+
- or you can override the `default List<Lint> lint(String content, File file)` method. This method will only run if the step did not already throw an exception.
145
+
146
+
Don't go lint crazy! By default, all lints are build failures. Users have to suppress them explicitly if they want to continue.
0 commit comments