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: plugin-maven/README.md
+58Lines changed: 58 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1944,6 +1944,64 @@ By default, `spotless:check` is bound to the `verify` phase. You might want to
1944
1944
- set `-Dspotless.check.skip=true` at the command line
1945
1945
- set `spotless.check.skip` to `true` in the `<properties>` section of the `pom.xml`
1946
1946
1947
+
### Suppressing lint errors
1948
+
1949
+
Sometimes Spotless will encounter lint errors that can't be auto-fixed. For example, if you run `mvn spotless:check`, you might see:
1950
+
1951
+
```
1952
+
[ERROR] Unable to format file src/main/java/com/example/App.java
1953
+
[ERROR] Step 'removeWildcardImports' found problem in 'App.java':
1954
+
[ERROR] Do not use wildcard imports
1955
+
```
1956
+
1957
+
To suppress these lints, you can use the `<lintSuppressions>` configuration:
1958
+
1959
+
```xml
1960
+
<plugin>
1961
+
<groupId>com.diffplug.spotless</groupId>
1962
+
<artifactId>spotless-maven-plugin</artifactId>
1963
+
<version>${spotless.version}</version>
1964
+
<configuration>
1965
+
<java>
1966
+
<removeWildcardImports/>
1967
+
</java>
1968
+
<lintSuppressions>
1969
+
<lintSuppression>
1970
+
<path>src/main/java/com/example/App.java</path>
1971
+
<step>removeWildcardImports</step>
1972
+
<shortCode>*</shortCode>
1973
+
</lintSuppression>
1974
+
</lintSuppressions>
1975
+
</configuration>
1976
+
</plugin>
1977
+
```
1978
+
1979
+
Each `<lintSuppression>` can match by:
1980
+
-`<path>` - file path (supports wildcards like `*`)
1981
+
-`<step>` - step name (supports wildcards like `*`)
1982
+
-`<shortCode>` - specific error code (supports wildcards like `*`)
1983
+
1984
+
You can suppress multiple patterns:
1985
+
1986
+
```xml
1987
+
<lintSuppressions>
1988
+
<!-- Suppress all wildcard import errors in legacy code -->
1989
+
<lintSuppression>
1990
+
<path>src/main/java/com/example/legacy/*</path>
1991
+
<step>removeWildcardImports</step>
1992
+
<shortCode>*</shortCode>
1993
+
</lintSuppression>
1994
+
<!-- Suppress all errors from a specific step -->
1995
+
<lintSuppression>
1996
+
<path>*</path>
1997
+
<step>removeWildcardImports</step>
1998
+
<shortCode>*</shortCode>
1999
+
</lintSuppression>
2000
+
</lintSuppressions>
2001
+
```
2002
+
2003
+
Spotless is primarily a formatter, _not_ a linter. In our opinion, a linter is just a broken formatter. But formatters do break sometimes, and representing these failures as lints that can be suppressed is more useful than just giving up.
2004
+
1947
2005
<aname="preview"></a>
1948
2006
1949
2007
## How do I preview what `mvn spotless:apply` will do?
0 commit comments