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
Changes from 1 commit
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
31 changes: 29 additions & 2 deletions src/linter/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
});

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 @@
* @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,33 @@
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
});
// TODO: Define a better way to get all files. Exclude node_modules, .git, etc.
const allFiles = await rootFileReader.byGlob("/**/*");
const filePaths = allFiles.map((file) => file.getPath());

for (const pattern of unmatchedPatterns) {
if (filePaths.some((filePath) => filePath.includes(pattern))) {
d3xter666 marked this conversation as resolved.
Show resolved Hide resolved
notProcessedFiles.add(pattern);
unmatchedPatterns.splice(unmatchedPatterns.indexOf(pattern), 1);
}
}

if (notProcessedFiles.size) {
// TODO: For files we need to just print a warning, but the reporter is not available here
console.log(

Check failure on line 395 in src/linter/linter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Unexpected console statement
`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
Loading