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
Error when lint staging files with $ in its name #962
Comments
No, I am not using shell option. Just lint-staged command. So maybe it's execa problem? I think the filenames should be escaped. I'll take a look at the PR. Thank you |
Please post the debug logs, that way we can see what the actual filename passed to |
Hey there, I got it working by escaping the filenames. diff --git a/node_modules/lint-staged/node_modules/execa/index.js b/node_modules/lint-staged/node_modules/execa/index.js
index 6fc9f12..891f53d 100644
--- a/node_modules/lint-staged/node_modules/execa/index.js
+++ b/node_modules/lint-staged/node_modules/execa/index.js
@@ -72,6 +72,9 @@ const handleOutput = (options, value, error) => {
};
const execa = (file, args, options) => {
+ if(options.escape) {
+ args = args.replace(/\$/g, '\\\$')
+ }
const parsed = handleArguments(file, args, options);
const command = joinCommand(file, args);
const escapedCommand = getEscapedCommand(file, args);
And one for lint-staged: diff --git a/node_modules/lint-staged/lib/resolveTaskFn.js b/node_modules/lint-staged/lib/resolveTaskFn.js
index 8c67a69..8e4ec54 100644
--- a/node_modules/lint-staged/lib/resolveTaskFn.js
+++ b/node_modules/lint-staged/lib/resolveTaskFn.js
@@ -89,7 +89,7 @@ module.exports = function resolveTaskFn({
debug('cmd:', cmd)
debug('args:', args)
- const execaOptions = { preferLocal: true, reject: false, shell }
+ const execaOptions = { preferLocal: true, reject: false, shell, escape: true }
if (relative) {
execaOptions.cwd = process.cwd()
} else if (/^git(\.exe)?/i.test(cmd) && gitDir !== process.cwd()) { |
Nice, thank you. Did you create PR for these patches? I think we are not the only ones with that issue. |
Hey 👋 |
Hey! I guess this is a NPM-related bug. Try running the executable without NPM wrapper. For me it worked (an example with $ npx run eslint 'app/routes/service.$serviceId.tsx'
Oops! Something went wrong! :(
ESLint: 8.22.0
No files matching the pattern "app/routes/service..tsx" were found.
Please check for typing mistakes in the pattern.
$ node_modules/.bin/eslint 'app/routes/service.$serviceId.tsx'
$ echo $?
0 |
Doesn't seem to be a lint-staged issue, but rather npm? |
I faced up with the same issue |
same issue here |
I was having the same issue as some of my paths have the
If you're using husky it will be this line in your package.json - "precommit": "lint-staged"
+ "precommit": "lint-staged --shell"
function escapeDollar(filepath) {
return filepath.replace(/\$/g, '\\$');
}
export default {
'src/**/*.{js,jsx,ts,tsx}': (filenames) => [
`prettier --write ${filenames.map(escapeDollar).join(' ')}`,
`eslint --fix ${filenames.map(escapeDollar).join(' ')}`
],
'src/**/*.{css,json}': `prettier --write`
}; In my case I'm running both prettier and eslint, but I think you can adapt from this example to your specific case. |
I added an e2e test for a difficult filename in #1413 and looks like EDIT: So lint-staged should handle these files just fine at least for ESLint and Prettier:
We are using |
Description
When I try eslint path/to/file/$something.foo it tries to resolve $something as an variable (I'm on Linux) and it becomes only path/to/file/.foo since variable does not exist. Is there any way how to resolve this issue? Specifically I'm using ESLint with lint-staged. I cannot properly escape the filename. Right now I am exporting variable with export something='$something', but that is far from ideal.
Do you have some workaround?
Steps to reproduce
Have some file with
$
in its name and runlint-staged
on it.Environment
lint-staged
: 10.5.4The text was updated successfully, but these errors were encountered: