Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Detect skipped & unsupported files [PoC] #408

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/linter/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async function lint(
});

const res = await lintWorkspace(workspace, filePathsWorkspace, options, config, matchedPatterns);
checkUnmatchedPatterns(filePatterns, matchedPatterns);
await checkUnmatchedPatterns(filePatterns, matchedPatterns, options);

lintEnd();
return res;
Expand Down Expand Up @@ -360,7 +360,7 @@ export function resolveReader({
* @param patterns Available patterns
* @throws Error if an unmatched pattern is found
*/
function checkUnmatchedPatterns(patterns: FilePattern[], patternsMatch: Set<string>) {
async function checkUnmatchedPatterns(patterns: FilePattern[], patternsMatch: Set<string>, options: LinterOptions) {
const unmatchedPatterns = patterns.reduce((acc, pattern) => {
if (pattern.endsWith("/")) { // Match all files in a directory
pattern += "**/*";
Expand All @@ -372,6 +372,41 @@ function checkUnmatchedPatterns(patterns: FilePattern[], patternsMatch: Set<stri
return acc;
}, [] as FilePattern[]);

// Check if the Glob pattern is actually a file that exists, but the linter is not able to process.
if (unmatchedPatterns.length) {
const notProcessedFiles = new Set<string>();
const rootFileReader = createReader({
fsBasePath: options.rootDir,
virBasePath: "/",
d3xter666 marked this conversation as resolved.
Show resolved Hide resolved
excludes: [
"/node_modules/**/*",
"/.*",
"/.*/**/*",
],
});

const allFiles = await rootFileReader.byGlob("/**/*");
const filePaths = allFiles.map((file) => file.getPath().substring(1));
const patterns = buildPatterns(unmatchedPatterns);

for (const pattern of patterns) {
const matchedFilePaths = filePaths.filter((filePath) => pattern.match(filePath));
if (matchedFilePaths.length) {
matchedFilePaths.forEach((filePath) => notProcessedFiles.add(filePath));
unmatchedPatterns.splice(unmatchedPatterns.indexOf(pattern.pattern), 1);
}
}

if (notProcessedFiles.size) {
// TODO: For files we need to just print a warning, but the reporter is not available here
// eslint-disable-next-line no-console
console.log(
`Specified ${notProcessedFiles.size === 1 ? "file" : "files"} ` +
`'${[...notProcessedFiles].join("', '")}' ${notProcessedFiles.size === 1 ? "is" : "are"}` +
` not supporeted by the linter`);
}
}

if (unmatchedPatterns.length) {
throw new Error(`Specified file ${unmatchedPatterns.length === 1 ? "pattern" : "patterns"}` +
` '${unmatchedPatterns.join("', '")}' did not match any resource`);
Expand Down
14 changes: 14 additions & 0 deletions test/lib/linter/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ test.serial("lint: com.ui5.troublesome.app with unmatched patterns", async (t) =
});
});

test.serial("lint: com.ui5.troublesome.app with unmatched files", async (t) => {
const projectPath = path.join(fixturesProjectsPath, "com.ui5.troublesome.app");

const {lintProject} = t.context;

const res = await lintProject({
filePatterns: ["webapp/i18n/*"],
rootDir: projectPath,
});

// TODO: when logging is implemented, check for log messages.
t.snapshot(preprocessLintResultsForSnapshot(res));
});

test.serial("lint: com.ui5.troublesome.app with files property in ui5lint.config", async (t) => {
const projectPath = path.join(fixturesProjectsPath, "com.ui5.troublesome.app");

Expand Down
6 changes: 6 additions & 0 deletions test/lib/linter/snapshots/linter.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,12 @@ Generated by [AVA](https://avajs.dev).
},
]

## lint: com.ui5.troublesome.app with unmatched files

> Snapshot 1

[]

## lint: com.ui5.troublesome.app with files property in ui5lint.config

> Snapshot 1
Expand Down
Binary file modified test/lib/linter/snapshots/linter.ts.snap
Binary file not shown.