-
-
Notifications
You must be signed in to change notification settings - Fork 418
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
Request: Lenient shell command parser #640
Comments
We’re using execa to run commands. Please research if that’s possible and submit a PR that implements it. |
This seems to be a limitation of child_process() which execa uses. Also tried # assuming foo is in bar.js
$ ! grep -q foo bar.js; echo $?
1 # no-match (negated)
$ bash -c "! grep -q foo bar.js; echo $?"
0 # match (negation did not take) For these reasons it's probably not worth pursuing further. The 2nd option (positioning the file argument) may be viable -- any thoughts on that? |
@moos can you check out this test and if it works for you? ecd5aef#diff-7c51e29de830d755b8f565e11f965bd9 I think I was able to solve this by skipping parsing of the command string entirely when using |
@iiroj Yes that worked -- I don't know how, but it did. Brilliant solution to both complex commands and filename placeholder! // lint-staged.config.js:
module.exports = {
"*.js": [
() => "! grep foo bar.j"
]
};
// bar.js:
// I haz foo Output:
Removing the
|
Closed in #639 |
Very nice,
PS nice idea @moos ☝️ |
Not so simple with const path = require('path');
module.exports = {
'*.php': (filenames) => {
// @see https://github.com/okonet/lint-staged#example-use-relative-paths-for-commands
const cwd = process.cwd();
const relativeFilenames = filenames.map((file) => path.relative(cwd, file)).join(' ');
return [
`./vendor/bin/phpcbf ${relativeFilenames}; if [ $? -eq 1 ]; then exit 0; fi`,
`./vendor/bin/phpcs -s ${relativeFilenames}`,
`./vendor/bin/psalm ${relativeFilenames}`,
]
}
} |
Description
It'd be great if normal bash command modifiers could be accepted (see below for example). I know same can be accomplished with an external script or an npm script -- but a one-liner would be super useful and less clutter.
Steps to reproduce
This example will fail the hook if there are any lingering
.only()
s left in staged test files. The!
is used to negate the exit code of grep.Debug Logs
This and not being able to position the file in the command, (e.g.
grep -q '\.only\W' {}; test $? -eq 1
where{}
is the (supposed!) file placeholder), is a real handicap in this otherwise very useful tool, IMHO.Environment
lint-staged
: v8.2.1The text was updated successfully, but these errors were encountered: