Skip to content

Apache Lucene open-source search software

Add eclint instructions to formatting.txt and 'eclint -fix' to run as part of tidy (#14926)

Dawid Weisscd1a4ecc9ead
diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/eclint/EditorConfigLintPlugin.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/eclint/EditorConfigLintPlugin.java
index 8d9d9f4ce5e..ac801b1d373 100644
--- a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/eclint/EditorConfigLintPlugin.java
+++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/eclint/EditorConfigLintPlugin.java
@@ -18,17 +18,19 @@ package org.apache.lucene.gradle.plugins.eclint;
import com.carrotsearch.gradle.buildinfra.buildoptions.BuildOptionsExtension;
import java.util.List;
-import org.gradle.api.GradleException;
-import org.gradle.api.Plugin;
+import org.apache.lucene.gradle.plugins.LuceneGradlePlugin;
import org.gradle.api.Project;
import org.gradle.api.tasks.Exec;
-public class EditorConfigLintPlugin implements Plugin<Project> {
+/**
+ * Applies (the rust version of) {@code eclint} to verify editor config settings.
+ *
+ * @see "https://gitlab.com/greut/eclint"
+ */
+public class EditorConfigLintPlugin extends LuceneGradlePlugin {
@Override
public void apply(Project project) {
- if (project != project.getRootProject()) {
- throw new GradleException("This plugin can be applied to the root project only.");
- }
+ applicableToRootProjectOnly(project);
var optionName = "lucene.tool.eclint";
var tasks = project.getTasks();
@@ -39,26 +41,27 @@ public class EditorConfigLintPlugin implements Plugin<Project> {
.getByType(BuildOptionsExtension.class)
.addOption(optionName, "External eclint executable (path or name)");
+ var verifyEcLintTask = tasks.register("verifyEcLint", Exec.class);
+
var applyEcLintTask =
tasks.register(
"applyEcLint",
Exec.class,
task -> {
- if (!eclintToolOption.isPresent()) {
- task.getLogger()
- .warn(
- "The eclint tool location is not set ('{}' option), will not apply eclint checks.",
- optionName);
- }
+ task.args("-fix");
});
// Common configuration.
- List.of(applyEcLintTask)
+ List.of(verifyEcLintTask, applyEcLintTask)
.forEach(
taskProv -> {
taskProv.configure(
task -> {
if (!eclintToolOption.isPresent()) {
+ task.getLogger()
+ .warn(
+ "The eclint tool location is not set ('{}' option), will not apply eclint checks.",
+ optionName);
task.setEnabled(false);
}
@@ -72,6 +75,13 @@ public class EditorConfigLintPlugin implements Plugin<Project> {
tasks
.matching(task -> task.getName().equals("check"))
+ .configureEach(
+ task -> {
+ task.dependsOn(verifyEcLintTask);
+ });
+
+ tasks
+ .matching(task -> task.getName().equals("tidy"))
.configureEach(
task -> {
task.dependsOn(applyEcLintTask);
diff --git a/help/formatting.txt b/help/formatting.txt
index ec73552fca7..ef6b4e28c09 100644
--- a/help/formatting.txt
+++ b/help/formatting.txt
@@ -14,9 +14,9 @@ your code so that it complies with the convention and passes gradle
IMPORTANT: wildcard imports are banned but google java format doesn't
detect or fix this. There is a check for wildcard imports implemented
-on top of the ast-grep tool (https://ast-grep.github.io/). It is
-optional. If you'd like to have it run on gradle's check task, install
-ast-grep locally and add this build option to
+on top of the ast-grep tool (https://ast-grep.github.io/). This tool is
+optional. If you'd like to run it locally on gradle's 'check' task,
+install ast-grep locally and add this build option to
build-options.local.properties:
lucene.tool.ast-grep=ast-grep
@@ -29,6 +29,17 @@ variable or reshape code paths) so that it's easier to read after
automatic formatting.
+Other file formatting
+=====================
+
+CI is configured to run additional linting using eclint
+(https://gitlab.com/greut/eclint). This tool is optional. If you'd like
+to run it locally on gradle's 'check' task, install eclint locally and add
+this build option to build-options.local.properties:
+
+lucene.tool.eclint=eclint
+
+
Gradle scripts
==============