hansva commented on code in PR #9391:
URL: https://github.com/apache/hop/pull/9391#discussion_r4537877698
##########
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:
Outside Hop GUI, `LinterConfigPlugin.getProjectPath()` falls back to
`System.getProperty("user.dir")`, and `isProjectRoot()` then treats the JVM
working directory as a project root. So hop-run, hop-server or a test JVM whose
working directory is inside a project (e.g. `/proj/workflows` from a Docker
`WORKDIR`) stops the search there: linting `/proj/workflows/x.hwf` finds no yml
in that folder, hits the 'root', returns null, and the project's real
`/proj/hop-lint.yml` is ignored. Before this PR the walk kept going and found
it. Could the boundary only use a real project path (PROJECT_HOME / the GUI
project), not the `user.dir` fallback?
##########
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:
Only `project-config.json` marks a project root, but projects can also use
`hop-project.config` (`ProjectConfig.CONFIG_FILENAME_CANDIDATES`) or a custom
config filename. For those projects no boundary is found, the walk goes past
the project root, and a `hop-lint.yml` in the workspace above still applies,
which is the #9387 bug. Using the same candidate list as the projects plugin
would cover them.
##########
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:
This early return (kept from before) runs before the boundary walk, which
contradicts the new docs and javadoc ('the nearest hop-lint.yml wins', nested
projects stop at their own root). In Hop GUI with `/ws/main` open, a file in a
nested project or under `transforms/hop-lint.yml` gets main's yml, while the
CLI gets the nearest one, so GUI and CI disagree. And in the CLI `user.dir` is
the Hop install folder (see the `hop` script), so a `hop-lint.yml` left in
HOP_HOME applies to every project linted, the same 'config from outside the
project' leak this PR closes. Could this return go, so the walk decides in both
cases?
##########
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:
Small one: this adds a `project-config.json` stat per folder, and
`findProjectYaml` runs per linted file (plus `getProjectPath()`/HopGui each
time) with no cache. On a network or VFS drive with thousands of files that's a
lot of repeated I/O; caching the result per folder for a lint run would help.
##########
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:
For a relative `context` (e.g. `new File("pipelines/x.hpl")`),
`getParentFile()` runs out before reaching the project root, so the search
silently stops early and the project's yml isn't found. Making `context`
absolute first would fix that.
##########
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:
`getAbsoluteFile().equals()` doesn't normalise, so a PROJECT_HOME with `..`,
`./` or a symlink never equals the walked folder, and for a project without a
`project-config.json` marker the walk passes the root again.
`toPath().toAbsolutePath().normalize()` (or `toRealPath()`) on both sides would
avoid that.
##########
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:
With the early return in `findProjectYaml` (line 366) and the `user.dir`
boundary, this doesn't hold yet: a `transforms/hop-lint.yml` in the open GUI
project is never used, and a file in no project can stop at the working
directory. Worth updating once the code matches.
--
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]