Skip to content

obsolete - Add support for linters #1097

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

Closed
wants to merge 31 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d5b0421
Define a `Lint`.
nedtwigg Jan 12, 2022
db676fc
Add a `lint` method to `FormatterStep` and let it wripple through.
nedtwigg Jan 12, 2022
5dc6271
Make Lint roundtrippable through a String.
nedtwigg Jan 13, 2022
cc71751
Formatter.lint
nedtwigg Jan 13, 2022
aac3972
Lint ripples through DirtyState and Formatter.
nedtwigg Jan 13, 2022
a25eded
SpotlessTaskImpl now generates both a formatted result and a lint res…
nedtwigg Jan 13, 2022
89339cd
SpotlessTaskImpl now generates a lint result for `check` and for `app…
nedtwigg Jan 14, 2022
cac4f70
Gradle spotlessCheck will now throw an error if all of the files are …
nedtwigg Jan 14, 2022
d4ec76b
Maven spotless:check will now throw an error if all of the files are …
nedtwigg Jan 14, 2022
7a1e72a
Default `FormatterFunc.lint` now traps errors from the formatter itse…
nedtwigg Jan 14, 2022
109c7fb
Remove `FormatExceptionPolicy`.
nedtwigg Jan 14, 2022
0049661
Remove `FormatExceptionPolicy` from the maven plugin.
nedtwigg Jan 14, 2022
dd5165f
Replace `FormatExceptionPolicy` with `LintPolicy` inside the Gradle p…
nedtwigg Jan 14, 2022
85fbe71
Lint.toFile might need to create parent directories.
nedtwigg Jan 14, 2022
e8e5df5
Lints are now quietly suppressed during `apply`, you have to do `chec…
nedtwigg Jan 14, 2022
6ec06cc
Fix spotbugs warnings.
nedtwigg Jan 14, 2022
9557c66
Fix the bug I made from fixing spotbugs :)
nedtwigg Jan 14, 2022
2844068
Make sure that FormatterFunc.Closeable's helpers support linting.
nedtwigg Jan 14, 2022
9134d8c
Fix FormatterFunc.Closeable earlier
nedtwigg Jan 14, 2022
5a9799d
Refactor PipeStepPair so that it can detect lost tags within our new …
nedtwigg Jan 14, 2022
07b39cb
Rename PipeStepPair to FenceStep.
nedtwigg Jan 14, 2022
78ddcd6
Removed `rootDir` property `Formatter` and its builder because it was…
nedtwigg Jan 14, 2022
f947c7b
`DiffMessageFormatter.Builder::formatter` needs a new `Path rootDir` …
nedtwigg Jan 14, 2022
a3eef1f
Adapt StepHarness for the new "exceptions never get thrown" environment.
nedtwigg Jan 15, 2022
3f72b7e
When a step throws an exception, we now accurately consider the entir…
nedtwigg Jan 14, 2022
1ed3149
Fix tests.
nedtwigg Jan 15, 2022
6e38887
Fix spotbugs.
nedtwigg Jan 15, 2022
eb0feed
Fix wrong SuppressFBWarnings import.
nedtwigg Jan 15, 2022
248ec28
Fix tests on windows.
nedtwigg Jan 15, 2022
3aa780e
Fix prettier error test.
nedtwigg Jan 15, 2022
e110426
Make our testing parallel.
nedtwigg Jan 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Define a Lint.
  • Loading branch information
nedtwigg committed Jan 14, 2022
commit d5b0421b0f636b4c5ec589c31822e7580ec7a7d4
87 changes: 87 additions & 0 deletions lib/src/main/java/com/diffplug/spotless/Lint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.spotless;

import java.util.Objects;

/**
* Models a linted line or line range. Note that there is no concept of severity level - responsibility
* for severity and confidence are pushed down to the configuration of the lint tool. If a lint makes it
* to Spotless, then it is by definition.
*/
public final class Lint {
private int lineStart, lineEnd; // 1-indexed
private String code; // e.g. CN_IDIOM https://spotbugs.readthedocs.io/en/stable/bugDescriptions.html#cn-class-implements-cloneable-but-does-not-define-or-use-clone-method-cn-idiom
private String msg;

private Lint(int lineStart, int lineEnd, String lintCode, String lintMsg) {
this.lineStart = lineStart;
this.lineEnd = lineEnd;
this.code = lintCode;
this.msg = lintMsg;
}

public static Lint create(String code, String msg, int lineStart, int lineEnd) {
if (lineEnd < lineStart) {
throw new IllegalArgumentException("lineEnd must be >= lineStart: lineStart=" + lineStart + " lineEnd=" + lineEnd);
}
return new Lint(lineStart, lineEnd, code, msg);
}

public static Lint create(String code, String msg, int line) {
return new Lint(line, line, code, msg);
}

public int getLineStart() {
return lineStart;
}

public int getLineEnd() {
return lineEnd;
}

public String getCode() {
return code;
}

public String getMsg() {
return msg;
}

@Override
public String toString() {
if (lineStart == lineEnd) {
return lineStart + ": (" + code + ") " + msg;
} else {
return lineStart + "-" + lineEnd + ": (" + code + ") " + msg;
}
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Lint lint = (Lint) o;
return lineStart == lint.lineStart && lineEnd == lint.lineEnd && Objects.equals(code, lint.code) && Objects.equals(msg, lint.msg);
}

@Override
public int hashCode() {
return Objects.hash(lineStart, lineEnd, code, msg);
}
}