bamaer commented on code in PR #9391:
URL: https://github.com/apache/hop/pull/9391#discussion_r4540319603
##########
plugins/misc/lint/src/main/java/org/apache/hop/lint/registry/RuleRegistry.java:
##########
@@ -340,12 +345,23 @@ public EffectiveRuleSet resolveForCurrentProject() {
projectYaml != null && projectYaml.exists() ? projectYaml :
findProjectYaml(null));
}
- /** Locate the project hop-lint.yml governing a file, or null. Used to root
relative patterns. */
+ /**
+ * Locate the project hop-lint.yml governing a file, or null. Used to root
relative patterns.
+ *
+ * <p>The nearest hop-lint.yml in the file's folder or above it is used, up
to the project root:
+ * the folder holding {@code project-config.json}, or the project Hop Gui
has open. A hop-lint.yml
+ * above the project, left in a home or workspace folder, changed the
findings of every project
+ * below it and rooted their exclude and suppress paths outside the project,
so a CI checkout
+ * linted differently from a developer's machine. A file in no project still
uses the nearest one
+ * above it.
+ */
public File findProjectYaml(File context) {
+ File projectFolder = null;
try {
String projectPath = LinterConfigPlugin.getInstance().getProjectPath();
if (!Utils.isEmpty(projectPath)) {
- File projectConfig = new File(projectPath, "hop-lint.yml");
+ projectFolder = new File(projectPath).getAbsoluteFile();
Review Comment:
Fixed. The boundary uses the new `LinterConfigPlugin.getProjectHome()`,
which has no `user.dir` fallback. `getProjectPath()` is unchanged for its other
callers. Covered by `theWorkingDirectoryIsNotAProjectRoot`.
##########
plugins/misc/lint/src/main/java/org/apache/hop/lint/registry/RuleRegistry.java:
##########
@@ -359,15 +375,24 @@ public File findProjectYaml(File context) {
? context
: (context != null ? context.getParentFile() : null);
while (directory != null) {
- File configFile = new File(directory, "hop-lint.yml");
+ File configFile = new File(directory, LINT_CONFIG_FILENAME);
if (configFile.exists()) {
return configFile;
}
+ if (isProjectRoot(directory, projectFolder)) {
+ return null;
+ }
directory = directory.getParentFile();
}
return null;
}
+ /** Whether this folder is a project's root, where the search for a
hop-lint.yml stops. */
+ private static boolean isProjectRoot(File directory, File projectFolder) {
+ return new File(directory, PROJECT_CONFIG_FILENAME).isFile()
Review Comment:
Both standard names now mark a project root. For a custom config filename,
`PROJECT_HOME` stops the search: `hop lint`, the Run Linter action, the
pre-commit hook and `--list-rules` now pass it to the linter. The lint plugin
does not depend on the projects plugin, so the two names are mirrored rather
than shared.
##########
plugins/misc/lint/src/main/java/org/apache/hop/lint/registry/RuleRegistry.java:
##########
@@ -340,12 +345,23 @@ public EffectiveRuleSet resolveForCurrentProject() {
projectYaml != null && projectYaml.exists() ? projectYaml :
findProjectYaml(null));
}
- /** Locate the project hop-lint.yml governing a file, or null. Used to root
relative patterns. */
+ /**
+ * Locate the project hop-lint.yml governing a file, or null. Used to root
relative patterns.
+ *
+ * <p>The nearest hop-lint.yml in the file's folder or above it is used, up
to the project root:
+ * the folder holding {@code project-config.json}, or the project Hop Gui
has open. A hop-lint.yml
+ * above the project, left in a home or workspace folder, changed the
findings of every project
+ * below it and rooted their exclude and suppress paths outside the project,
so a CI checkout
+ * linted differently from a developer's machine. A file in no project still
uses the nearest one
+ * above it.
+ */
public File findProjectYaml(File context) {
+ File projectFolder = null;
try {
String projectPath = LinterConfigPlugin.getInstance().getProjectPath();
if (!Utils.isEmpty(projectPath)) {
- File projectConfig = new File(projectPath, "hop-lint.yml");
+ projectFolder = new File(projectPath).getAbsoluteFile();
+ File projectConfig = new File(projectFolder, LINT_CONFIG_FILENAME);
if (projectConfig.exists()) {
return projectConfig;
Review Comment:
Removed. The nearest `hop-lint.yml` wins in Hop Gui too, and
`resolveForCurrentProject()` starts its search at the open project. A
`hop-lint.yml` in the Hop install folder no longer leaks in
(`aHopLintYmlInTheWorkingDirectoryIsNotTheCurrentProjects`). That also covers
your note on line 339: the literal and the repeated lookup are gone.
##########
docs/hop-user-manual/modules/ROOT/pages/linting/lint-rules.adoc:
##########
@@ -502,7 +502,12 @@ That can miss a dead file which happens to share a name
with a live one, which i
== Configuring a project
-Put a `hop-lint.yml` in the project root. It holds overrides and project-local
rules only, not a copy of the rule packs:
+Put a `hop-lint.yml` in the project root. It holds overrides and project-local
rules only, not a copy of the rule packs.
+
+A file is linted with the nearest `hop-lint.yml` in its own folder or a folder
above it, up to the project root: the folder that holds `project-config.json`,
or the project open in Hop Gui.
Review Comment:
Updated to match: the same rule in Gui, CLI and action, the project root as
either marker file or `PROJECT_HOME`, and the working directory not being a
root.
##########
plugins/misc/lint/src/main/java/org/apache/hop/lint/registry/RuleRegistry.java:
##########
@@ -359,15 +375,24 @@ public File findProjectYaml(File context) {
? context
: (context != null ? context.getParentFile() : null);
while (directory != null) {
- File configFile = new File(directory, "hop-lint.yml");
+ File configFile = new File(directory, LINT_CONFIG_FILENAME);
if (configFile.exists()) {
return configFile;
}
+ if (isProjectRoot(directory, projectFolder)) {
+ return null;
+ }
directory = directory.getParentFile();
}
return null;
}
+ /** Whether this folder is a project's root, where the search for a
hop-lint.yml stops. */
+ private static boolean isProjectRoot(File directory, File projectFolder) {
+ return new File(directory, PROJECT_CONFIG_FILENAME).isFile()
+ || directory.getAbsoluteFile().equals(projectFolder);
Review Comment:
Both sides are now absolute and normalised. The project home is also matched
by its real path, for the symlink case.
##########
plugins/misc/lint/src/main/java/org/apache/hop/lint/registry/RuleRegistry.java:
##########
@@ -359,15 +375,24 @@ public File findProjectYaml(File context) {
? context
: (context != null ? context.getParentFile() : null);
Review Comment:
Fixed. The context is made absolute and normalised before the search starts.
##########
plugins/misc/lint/src/main/java/org/apache/hop/lint/registry/RuleRegistry.java:
##########
@@ -359,15 +375,24 @@ public File findProjectYaml(File context) {
? context
: (context != null ? context.getParentFile() : null);
while (directory != null) {
- File configFile = new File(directory, "hop-lint.yml");
+ File configFile = new File(directory, LINT_CONFIG_FILENAME);
if (configFile.exists()) {
return configFile;
}
+ if (isProjectRoot(directory, projectFolder)) {
Review Comment:
Each `HopLinter` instance, which lasts one run, now keeps the result per
folder, and the cache is cleared whenever a configuration is loaded. The rule
set is still resolved once per run.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]