prettier-atom
prettier-atom copied to clipboard
Format on Save: "path should be a path.relative()d string, but got "/path/to/file.js"
Hi,
Edit: I've been able to narrow down the cause of this, which makes it a pretty minor error... but here goes -
I've noticed that when I type something up in a new .js file that is not attached to ~any npm project~ the current Atom project (i.e. just create a new file and save it to my desktop), it always prints the following message every time I save:
path should be a path.relative()d string, but got "/Users/me/my/new/file.js"
Looking at dev tools, it looks like it crashes here:
helpers/general.js
const someGlobsMatchFilePath = (globs, filePath) => isPresent(filePath) && ignore().add(globs).ignores(filePath);
If I disable Format on Save, the error does not print. Specifically, the .ignores() call is what is failing. I see that relativizePathFromAtomProject() isn't returning a relative path and that ignores() is getting an absolute one instead.
Any ideas? If anyone can suggest the fix, I would be happy to help.
Atom version: 1.35.1
prettier-atom version: 0.56.0
prettier: bundled
prettier version: 1.15.2
prettier-eslint version: 8.8.2
prettier-atom configuration: {
"formatOnSaveOptions": {
"isDisabledIfNoConfigFile": true,
"isDisabledIfNotInPackageJson": true,
"showInStatusBar": true,
"enabled": false,
"respectEslintignore": true,
"excludedGlobs": [],
"whitelistedGlobs": []
},
"useEslint": false,
"useStylelint": false,
"prettierEslintOptions": {
"prettierLast": false
}
}
It seems like you are right on with your diagnosis here. Just as some background, in order to check against any whitelist/exclude globs, we use the ignores package. They unfortunately made it so it throws a hard error unless you give a path that is relative (as opposed to absolute).
So what we've been doing is using relativizePathFromAtomProject to get us the relative path version of your file. It seems that since you're not in a project here, it's falling back to just giving an absolute path.
All we need to do really is just change the path in such a way that the ignores package is happy (that it identifies via regex that the path is relative).
One solution I guess we could try would be detecting whether there is a project present, and if not, don't call relativizePathFromAtomProject and instead turn /Foo/Bar/Baz to ./Foo/Bar/Baz?
I dunno, maybe that's a bit hacky?