Skip to content

Commit

Permalink
Allow relative AND absolute paths when ignoring directories (#150)
Browse files Browse the repository at this point in the history
Fixes #149
  • Loading branch information
jamesrweb authored May 2, 2024
1 parent e4f3566 commit 28869fc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

- The `--ignore-dirs` and `--ignore-files` flags now support absolute paths. Thanks [@jamesrweb](https://github.com/jamesrweb)!

## [2.11.1] - 2024-03-16

- Fixed a crash when running in watch mode related to not being able to fetch cache results.
Expand Down
20 changes: 18 additions & 2 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ try re-running it with ${chalk.cyan('--elmjson <path-to-elm.json>')}.`,
license
};

/**
* Converts absolute to relative paths.
*
* @param {Path} filePath
* @returns {Path}
*/
function absolutePathsToRelative(filePath) {
if (path.isAbsolute(filePath)) {
return path.relative(projectToReview(), filePath);
}

return filePath;
}

return {
debug: args.debug,
showBenchmark: args['benchmark-info'],
Expand Down Expand Up @@ -219,8 +233,10 @@ try re-running it with ${chalk.cyan('--elmjson <path-to-elm.json>')}.`,
report: args.report === 'json' || args.report === 'ndjson' ? 'json' : null,
reportOnOneLine: args.report === 'ndjson',
rulesFilter: listOfStrings(args.rules),
ignoredDirs: listOfStrings(args['ignore-dirs']) || [],
ignoredFiles: listOfStrings(args['ignore-files']) || [],
ignoredDirs: () =>
(listOfStrings(args['ignore-dirs']) || []).map(absolutePathsToRelative),
ignoredFiles: () =>
(listOfStrings(args['ignore-files']) || []).map(absolutePathsToRelative),

// TEMPORARY WORKAROUNDS
ignoreProblematicDependencies: args['ignore-problematic-dependencies'],
Expand Down
4 changes: 2 additions & 2 deletions lib/result-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ async function load(options, cacheFolder) {
if (
options.debug ||
options.directoriesToAnalyze.length > 0 ||
options.ignoredDirs.length > 0 ||
options.ignoredFiles.length > 0
options.ignoredDirs().length > 0 ||
options.ignoredFiles().length > 0
) {
// TODO Breaking change: When we drop support for Node.js v10, use `globalThis` everywhere instead of `global`
global.loadResultFromCache = () => null;
Expand Down
4 changes: 2 additions & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ async function initializeApp(options, elmModulePath, reviewElmJson, appHash) {
rulesFilter: options.rulesFilter,
ignoreProblematicDependencies: options.ignoreProblematicDependencies,
directoriesToAnalyze: options.directoriesToAnalyze,
ignoredDirs: options.ignoredDirs,
ignoredFiles: options.ignoredFiles,
ignoredDirs: options.ignoredDirs(),
ignoredFiles: options.ignoredFiles(),
writeSuppressionFiles: options.directoriesToAnalyze.length === 0
});

Expand Down
4 changes: 2 additions & 2 deletions lib/types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export type Options = {
report: ReportMode;
reportOnOneLine: boolean;
rulesFilter: string[] | null;
ignoredDirs: string[];
ignoredFiles: string[];
ignoredDirs: () => string[];
ignoredFiles: () => string[];
ignoreProblematicDependencies: boolean;
prefilledAnswers: NewPackagePrefilledAnswers;

Expand Down

0 comments on commit 28869fc

Please sign in to comment.