Repository: okonet/lint-staged (js)

Issue:
Glob issues with 4.2.2 and Prettier
Starting with `lint-staged` version 4.2.2 I have glob issues when using with husky and prettier. Here's my lint-staged config:

```json
"lint-staged": {
  "{app,test,config}/**/*.js": [
    "prettier --single-quote --tab-width 4 --print-width 100 --no-bracket-spacing --write",
    "eslint --fix --max-warnings 0",
    "git add"
  ]
}
```

And here's the error from prettier:
```
husky > npm run -s precommit (node v6.11.3)

 ❯ Running tasks for {app,test,config}/**/*.js
   ✖ prettier --single-quote --tab-width 4 --print-width 100 --no-bracket-spacing --write
     → TypeError: patterns must be a string or an array of strings
     eslint --fix --max-warnings 0
     git add
✖ prettier --single-quote --tab-width 4 --print-width 100 --no-bracket-spacing --write found some errors. Please fix them and try committing again.

Unable to expand glob patterns: {app,test,config}/**/*.js 4 100 /home/user/dev/my-app/app/entity/myEntity.js !**/node_modules/** !./node_modules/**
TypeError: patterns must be a string or an array of strings
```

Anyways, thanks for making this awesome tool and if I have time this weekend I'd be glad to look into this problem myself, just wanted to get this out for others to look at ASAP.

Pull request description:
fix(findBin): Add separator before npm args
Closes #296.

Patch:
diff --git a/src/findBin.js b/src/findBin.js
index 684d7b4..bce2d30 100644
--- a/src/findBin.js
+++ b/src/findBin.js
@@ -4,7 +4,7 @@ const npmWhich = require('npm-which')(process.cwd())
 
 module.exports = function findBin(cmd, scripts, options) {
   const npmArgs = (bin, args) =>
-    ['run', options && options.verbose ? undefined : '--silent', bin]
+    ['run', options && options.verbose ? undefined : '--silent', bin, '--']
       // args could be undefined but we filter that out.
       .concat(args)
       .filter(arg => arg !== undefined)
diff --git a/src/runScript.js b/src/runScript.js
index e19aba3..f473860 100644
--- a/src/runScript.js
+++ b/src/runScript.js
@@ -24,8 +24,6 @@ module.exports = function runScript(commands, pathsToLint, scripts, config) {
       try {
         const res = findBin(linter, scripts, config)
 
-        const separatorArgs = /npm(\.exe)?$/i.test(res.bin) ? ['--'] : []
-
         // Only use gitDir as CWD if we are using the git binary
         // e.g `npm` should run tasks in the actual CWD
         const execaOptions =
@@ -33,7 +31,7 @@ module.exports = function runScript(commands, pathsToLint, scripts, config) {
 
         const errors = []
         const mapper = pathsChunk => {
-          const args = res.args.concat(separatorArgs, pathsChunk)
+          const args = res.args.concat(pathsChunk)
 
           return (
             execa(res.bin, args, Object.assign({}, execaOptions))


Test patch:
diff --git a/test/findBin.spec.js b/test/findBin.spec.js
index 9ec5ef7..5ea8246 100644
--- a/test/findBin.spec.js
+++ b/test/findBin.spec.js
@@ -8,25 +8,25 @@ describe('findBin', () => {
   it('should favor `npm run` command if exists in both package.json and .bin/', () => {
     const { bin, args } = findBin('my-linter', { 'my-linter': 'my-linter' })
     expect(bin).toEqual('npm')
-    expect(args).toEqual(['run', '--silent', 'my-linter'])
+    expect(args).toEqual(['run', '--silent', 'my-linter', '--'])
   })
 
   it('should return npm run command without --silent in verbose mode', () => {
     const { bin, args } = findBin('eslint', { eslint: 'eslint' }, { verbose: true })
     expect(bin).toEqual('npm')
-    expect(args).toEqual(['run', 'eslint'])
+    expect(args).toEqual(['run', 'eslint', '--'])
   })
 
   it('should resolve cmd defined in scripts with args', () => {
     const { bin, args } = findBin('kcd-scripts format', { 'kcd-scripts': 'node index.js' })
     expect(bin).toEqual('npm')
-    expect(args).toEqual(['run', '--silent', 'kcd-scripts', 'format'])
+    expect(args).toEqual(['run', '--silent', 'kcd-scripts', '--', 'format'])
   })
 
   it('should resolve cmd defined in scripts with space in name', () => {
     const { bin, args } = findBin('my cmd', { 'my cmd': 'echo deal-with-it' })
     expect(bin).toEqual('npm')
-    expect(args).toEqual(['run', '--silent', 'my cmd'])
+    expect(args).toEqual(['run', '--silent', 'my cmd', '--'])
   })
 
   it('should return path to bin if there is no `script` with name in package.json', () => {