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

Allow relative AND absolute paths when ignoring directories #150

Merged
merged 5 commits into from
May 2, 2024
Merged
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
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
Loading