-
Notifications
You must be signed in to change notification settings - Fork 2
Quickstart
Zachary Moore edited this page Jan 14, 2019
·
1 revision
Simple lint rule looking for any non-key String that is test
Example:
Bad
{
"name": "test"
}Good
{
"name": "John"
}Java Implementation in one method
class Example {
public static void setupLinter() {
// Create LintImplementation
LintImplementation<WrappedPrimitive<String>> lintImplementation = new LintImplementation<WrappedPrimitive<String>>() {
@Override
public Class<String> getClazz() {
return String.class;
}
@Override
public boolean shouldReport(WrappedPrimitive<String> string) {
return string.getValue().equals("test");
}
@Override
public String report(WrappedPrimitive<String> string) {
return string.getValue() + " found in file.";
}
};
// Use builder to create rule
LintRule rule = new LintRule.Builder()
.setLevel(LintLevel.ERROR)
.setImplementation(lintImplementation)
.setIssueId("STRING_VALUE_NAMED_TEST")
.build();
// Create register and register rule
LintRegister register = new LintRegister();
register.register(rule);
// Create LintRunner with register and path to lint
LintRunner lintRunner = new LintRunner(register, "./models");
// Create ReportRunner and report lint errors
ReportRunner reportRunner = new ReportRunner(lintRunner);
reportRunner.report("build/reports");
}
}