-
Notifications
You must be signed in to change notification settings - Fork 81
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 error when an absolute path is given #80
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense, thanks!
You say it’s a quick fix, but it looks pretty reasonable to me. Did you have any concerns about this?
@@ -110,6 +110,7 @@ function prepareFileList(files, fileExtensions, previousResults) { | |||
return flatten(files).map(function (file) { | |||
return { | |||
original: file, | |||
relative: path.relative(process.cwd(), file), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you capture the call to cwd
in a const outside the map, please?
I would love to add tests here, but I think you didn’t because it’s not clear how to do so in a platform-independent manner, right? |
I found a way to add tests that should be platform-independent and merged this PR. |
Hi @DavidAnson. Sorry I forgot about this PR. Thansk for the merge. |
When an absolute path is given (e.g. via
lint-staged
),node-ignore
was throwing a RangeErrorpath 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 anabsolute
property based on the cwd, this commit only introduce a newrelative
property, which is also based on the cwd.No new specific test was written for this use case.
Close #79