Skip to content

Commit

Permalink
fix: Allow ignoring ui5.yaml files via config
Browse files Browse the repository at this point in the history
For some files, only the passed ignorePatterns
were considered, but not pattern defined in the
configuration.

This mainly affected linting of ui5.yaml files, as
they are accessed via the so-called root reader
rather than the project workspace, where the
problem did not occur.
  • Loading branch information
matz3 committed Nov 13, 2024
1 parent 8a3976f commit a024d44
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/linter/lintWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {taskStart} from "../utils/perf.js";
import TypeLinter from "./ui5Types/TypeLinter.js";
import LinterContext, {LintResult, LinterParameters, LinterOptions, FSToVirtualPathOptions} from "./LinterContext.js";
import {createReader} from "@ui5/fs/resourceFactory";
import {resolveReader} from "./linter.js";
import {mergeIgnorePatterns, resolveReader} from "./linter.js";
import {UI5LintConfigType} from "../utils/ConfigManager.js";

export default async function lintWorkspace(
Expand All @@ -33,7 +33,7 @@ export default async function lintWorkspace(
patternsMatch,
});
reader = resolveReader({
patterns: options.ignorePatterns ?? [],
patterns: mergeIgnorePatterns(options, config),
resourceReader: reader,
patternsMatch,
relFsBasePath: relFsBasePath ?? "",
Expand Down
14 changes: 9 additions & 5 deletions src/linter/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,8 @@ async function lint(
// that didn't match any file
const matchedPatterns = new Set<string>();

// Resolve ignores
ignorePatterns = [
...(config.ignores ?? []),
...(ignorePatterns ?? []), // CLI patterns go after config patterns
].filter(($) => $);
ignorePatterns = mergeIgnorePatterns(options, config);

// Apply ignores to the workspace reader.
// TypeScript needs the full context to provide correct analysis.
// so, we can do filtering later via the filePathsReader
Expand Down Expand Up @@ -380,3 +377,10 @@ function checkUnmatchedPatterns(patterns: FilePattern[], patternsMatch: Set<stri
` '${unmatchedPatterns.join("', '")}' did not match any resource`);
}
}

export function mergeIgnorePatterns(options: LinterOptions, config: UI5LintConfigType): string[] {
return [
...(config.ignores ?? []),
...(options.ignorePatterns ?? []), // CLI patterns go after config patterns
].filter(($) => $);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
ignores: [
"webapp/test/**/*",
"!webapp/test/integration/opaTests.qunit.js"
"!webapp/test/integration/opaTests.qunit.js",
"ui5.yaml"
],
};
1 change: 1 addition & 0 deletions test/lib/linter/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ test.serial("lint: Ignore files from library.with.custom.paths", async (t) => {
ignorePatterns: [
"src/",
"!src/main/",
"ui5.yaml",
],
});

Expand Down
32 changes: 0 additions & 32 deletions test/lib/linter/snapshots/linter.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1899,22 +1899,6 @@ Generated by [AVA](https://avajs.dev).
],
warningCount: 0,
},
{
coverageInfo: [],
errorCount: 1,
fatalErrorCount: 0,
filePath: 'ui5.yaml',
messages: [
{
column: 7,
line: 15,
message: 'Use of deprecated library \'sap.landvisz\'',
ruleId: 'no-deprecated-library',
severity: 2,
},
],
warningCount: 0,
},
]

## lint: All files of library with sap.f namespace
Expand Down Expand Up @@ -2363,22 +2347,6 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
[
{
coverageInfo: [],
errorCount: 1,
fatalErrorCount: 0,
filePath: 'ui5.yaml',
messages: [
{
column: 7,
line: 11,
message: 'Use of deprecated library \'sap.landvisz\'',
ruleId: 'no-deprecated-library',
severity: 2,
},
],
warningCount: 0,
},
{
coverageInfo: [],
errorCount: 0,
Expand Down
Binary file modified test/lib/linter/snapshots/linter.ts.snap
Binary file not shown.
2 changes: 2 additions & 0 deletions test/lib/utils/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ test("Check config file", async (t) => {
ignores: [
"webapp/test/**/*",
"!webapp/test/integration/opaTests.qunit.js",
"ui5.yaml",
],
}, "The configuration is derived from the provided custom config file");
});
Expand Down Expand Up @@ -64,6 +65,7 @@ test("Check config file with absolute path", async (t) => {
ignores: [
"webapp/test/**/*",
"!webapp/test/integration/opaTests.qunit.js",
"ui5.yaml",
],
}, "The configuration is derived from the provided custom config file");
});
Expand Down

0 comments on commit a024d44

Please sign in to comment.