Skip to content

Commit 6e9849c

Browse files
committedMar 5, 2020
Fix error when an absolute path is given
When an absolute path is given (e.g. via `lint-staged`), `node-ignore` was throwing a RangeError `path should be a path.relative()'d string`. see https://github.com/kaelzhang/node-ignore#1-pathname-should-be-a-pathrelatived-pathname This is only a "quick win" to fix this issue. As `prepareFileList` was already returning an `absolute` property based on the cwd, this commit only introduce a new `relative` property, which is also based on the cwd. No new specific test was written for this use case.
1 parent 8a3a64e commit 6e9849c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed
 

‎markdownlint.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function prepareFileList(files, fileExtensions, previousResults) {
110110
return flatten(files).map(function (file) {
111111
return {
112112
original: file,
113+
relative: path.relative(process.cwd(), file),
113114
absolute: path.resolve(file)
114115
};
115116
});
@@ -231,7 +232,7 @@ let ignoreFilter = () => true;
231232
if (existsSync(ignorePath)) {
232233
const ignoreText = fs.readFileSync(ignorePath, fsOptions);
233234
const ignoreInstance = ignore().add(ignoreText);
234-
ignoreFilter = fileInfo => !ignoreInstance.ignores(fileInfo.original);
235+
ignoreFilter = fileInfo => !ignoreInstance.ignores(fileInfo.relative);
235236
}
236237

237238
const files = prepareFileList(program.args, ['md', 'markdown'])

0 commit comments

Comments
 (0)
Please sign in to comment.