Skip to content

Commit 28869fc

Browse files
authored
Allow relative AND absolute paths when ignoring directories (#150)
Fixes #149
1 parent e4f3566 commit 28869fc

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [Unreleased]
44

5+
- The `--ignore-dirs` and `--ignore-files` flags now support absolute paths. Thanks [@jamesrweb](https://github.com/jamesrweb)!
6+
57
## [2.11.1] - 2024-03-16
68

79
- Fixed a crash when running in watch mode related to not being able to fetch cache results.

lib/options.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,20 @@ try re-running it with ${chalk.cyan('--elmjson <path-to-elm.json>')}.`,
191191
license
192192
};
193193

194+
/**
195+
* Converts absolute to relative paths.
196+
*
197+
* @param {Path} filePath
198+
* @returns {Path}
199+
*/
200+
function absolutePathsToRelative(filePath) {
201+
if (path.isAbsolute(filePath)) {
202+
return path.relative(projectToReview(), filePath);
203+
}
204+
205+
return filePath;
206+
}
207+
194208
return {
195209
debug: args.debug,
196210
showBenchmark: args['benchmark-info'],
@@ -219,8 +233,10 @@ try re-running it with ${chalk.cyan('--elmjson <path-to-elm.json>')}.`,
219233
report: args.report === 'json' || args.report === 'ndjson' ? 'json' : null,
220234
reportOnOneLine: args.report === 'ndjson',
221235
rulesFilter: listOfStrings(args.rules),
222-
ignoredDirs: listOfStrings(args['ignore-dirs']) || [],
223-
ignoredFiles: listOfStrings(args['ignore-files']) || [],
236+
ignoredDirs: () =>
237+
(listOfStrings(args['ignore-dirs']) || []).map(absolutePathsToRelative),
238+
ignoredFiles: () =>
239+
(listOfStrings(args['ignore-files']) || []).map(absolutePathsToRelative),
224240

225241
// TEMPORARY WORKAROUNDS
226242
ignoreProblematicDependencies: args['ignore-problematic-dependencies'],

lib/result-cache.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ async function load(options, cacheFolder) {
3131
if (
3232
options.debug ||
3333
options.directoriesToAnalyze.length > 0 ||
34-
options.ignoredDirs.length > 0 ||
35-
options.ignoredFiles.length > 0
34+
options.ignoredDirs().length > 0 ||
35+
options.ignoredFiles().length > 0
3636
) {
3737
// TODO Breaking change: When we drop support for Node.js v10, use `globalThis` everywhere instead of `global`
3838
global.loadResultFromCache = () => null;

lib/runner.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ async function initializeApp(options, elmModulePath, reviewElmJson, appHash) {
111111
rulesFilter: options.rulesFilter,
112112
ignoreProblematicDependencies: options.ignoreProblematicDependencies,
113113
directoriesToAnalyze: options.directoriesToAnalyze,
114-
ignoredDirs: options.ignoredDirs,
115-
ignoredFiles: options.ignoredFiles,
114+
ignoredDirs: options.ignoredDirs(),
115+
ignoredFiles: options.ignoredFiles(),
116116
writeSuppressionFiles: options.directoriesToAnalyze.length === 0
117117
});
118118

lib/types/options.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export type Options = {
2828
report: ReportMode;
2929
reportOnOneLine: boolean;
3030
rulesFilter: string[] | null;
31-
ignoredDirs: string[];
32-
ignoredFiles: string[];
31+
ignoredDirs: () => string[];
32+
ignoredFiles: () => string[];
3333
ignoreProblematicDependencies: boolean;
3434
prefilledAnswers: NewPackagePrefilledAnswers;
3535

0 commit comments

Comments
 (0)