Skip to content
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

EsLint and CoffeeLint not using command #352

Closed
kompiro opened this issue Mar 2, 2016 · 9 comments
Closed

EsLint and CoffeeLint not using command #352

kompiro opened this issue Mar 2, 2016 · 9 comments
Labels

Comments

@kompiro
Copy link
Contributor

kompiro commented Mar 2, 2016

Hi,

I confugured below to .overcommit.yml and git commit, it seems not to run via npm

PreCommit:
  RuboCop:
    command: ['bundle', 'exec', 'rubocop']
    enabled: true
    quiet: false
    on_warn: fail # Treat all warnings as failures
  EsLint:
    command: ['npm', 'run', 'lint']
    enabled: true
  CoffeeLint:
    command: ['npm', 'run', 'coffeelint']
    enabled: true
$ git add test.js test.coffee
$ git commit
Running pre-commit hooks
Analyzing with coffeelint................................[CoffeeLint] FAILED
'coffeelint' is not installed, not in your PATH, or does not have execute permissions
Install it by running: npm install -g coffeelint
Analyzing with ESLint........................................[EsLint] FAILED
'eslint' is not installed, not in your PATH, or does not have execute permissions
Install it by running: npm install -g eslint

✗ One or more pre-commit hooks failed

Why overcommit tells me to install these tools globally?

@sds
Copy link
Owner

sds commented Mar 2, 2016

Did you git add the changes to .overcommit.yml in your index? Without them Overcommit will use whatever configuration exists in the unstaged version of your configuration.

@kompiro
Copy link
Contributor Author

kompiro commented Mar 2, 2016

After I added .overcommit.yml and git commit, the output is same...

Where is the update version of my configuration?

@sds sds added the question label Mar 2, 2016
@sds
Copy link
Owner

sds commented Mar 2, 2016

Ah, you need to update the required_executable option for those hooks to npm, i.e.

# .overcommit.yml
PreCommit:
  ...
  EsLint:
      enabled: true
      required_executable: 'npm'
      command: ['npm', 'run', 'lint']
  CoffeeLint:
      enabled: true
      required_executable: 'npm'
      command: ['npm', 'run', 'coffeelint']

Overcommit is working correctly here: since the default configuration specifies the required_executable as eslint/coffeelint, Overcommit raises an error trying to find those executables before running the hook.

Hope that helps.

@sds sds closed this as completed Mar 2, 2016
@kompiro
Copy link
Contributor Author

kompiro commented Mar 2, 2016

Thanks for your help, the FAILED messages are disappered!

BTW, the lint tools are not read their configuration files like #351.

Can I set to show more detail like verbose for these tools output?

@sds
Copy link
Owner

sds commented Mar 2, 2016

You can get Overcommit to show more output by running with the OVERCOMMIT_DEBUG=1 environment variable.

Otherwise, you'll have to consult the documentation for eslint and coffeelint to see what kind of debugging output they offer.

@kompiro
Copy link
Contributor Author

kompiro commented Mar 2, 2016

Thanks, OVERCOMMIT_DEBUG=1 is many helps for me.

@kompiro
Copy link
Contributor Author

kompiro commented Mar 2, 2016

But I found another issue 😨

When run npm run coffeelint, the output likes below

 $ OVERCOMMIT_DEBUG=1 git commit
... continue ...
Analyzing with coffeelint................................[CoffeeLint] npm run coffeelint -- ... (1 splittable args)
EXIT STATUS: 1
STDOUT: ""
STDERR: "npm ERR! Darwin 15.3.0\nnpm ERR! argv \"/usr/local/var/nodebrew/node/v4.2.6/bin/node\" \"/usr/local/var/nodebrew/current/bin/npm\" \"run\" \"coffeelint\" \"--\" \"/Users/kompiro/git/hoge/test.coffee\"\nnpm ERR! node v4.2.6\nnpm ERR! npm  v2.14.12\n\nnpm ERR! missing script: coffeelint\nnpm ERR! \nnpm ERR! If you need help, you may report this error at:\nnpm ERR!     <https://github.com/npm/npm/issues>\n\nnpm ERR! Please include the following file with any support request:\nnpm ERR!     /Users/kompiro/git/hoge/npm-debug.log\n"
OK
 $ npm run coffeelint -- /Users/kompiro/git/hoge/test.coffee

> hoge@1.0.0 coffeelint /Users/kompiro/git/hoge
> coffeelint -f coffeelint.json --reporter=csv "/Users/kompiro/git/hoge/test.coffee"

path,lineNumber,lineNumberEnd,level,message
/Users/kompiro/git/hoge/test.coffee,1,,error,Found debugging code found 'DEBUGGER'.

npm ERR! Darwin 15.3.0
npm ERR! argv "/usr/local/var/nodebrew/node/v4.2.6/bin/node" "/usr/local/var/nodebrew/current/bin/npm" "run" "coffeelint" "--" "/Users/kompiro/git/hoge/test.coffee"
npm ERR! node v4.2.6
npm ERR! npm  v2.14.12
npm ERR! code ELIFECYCLE
npm ERR! hoge@1.0.0 coffeelint: `coffeelint -f coffeelint.json --reporter=csv "/Users/kompiro/git/hoge/test.coffee"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hoge@1.0.0 coffeelint script 'coffeelint -f coffeelint.json --reporter=csv "/Users/kompiro/git/hoge/test.coffee"'.
npm ERR! This is most likely a problem with the hoge package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     coffeelint -f coffeelint.json --reporter=csv "/Users/kompiro/git/hoge/test.coffee"
npm ERR! You can get their info via:
npm ERR!     npm owner ls hoge
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/kompiro/git/hoge/npm-debug.log

I think this is a npm option problem. So I added -s to the output quietly.

 $ npm run coffeelint -s -- test.coffee
path,lineNumber,lineNumberEnd,level,message
test.coffee,1,,error,Found debugging code found 'DEBUGGER'.

Got it! After that, I added silent option for npm like below.

  CoffeeLint:
    enabled: true
    required_executable: 'npm'
    quiet: false
    flags: ['-s','--']
    command: ['npm', 'run', 'coffeelint']

The output is below 😨

 $ OVERCOMMIT_DEBUG=1 git commit
... continue ...
git rev-parse HEAD
EXIT STATUS: 0
STDOUT: "8f8ddfee3fed8c3c4ecec03526e4c936e80fda6f\n"
STDERR: ""
Analyzing with coffeelint................................[CoffeeLint] npm run coffeelint -s -- ... (1 splittable args)
EXIT STATUS: 1
STDOUT: ""
STDERR: ""
OK

✓ All pre-commit hooks passed

Why overcommit cannot handle coffeelint output?

@sds
Copy link
Owner

sds commented Mar 6, 2016

The moment you change the output format of npm via flags, you're changing the output npm sends to Overcommit. Notice the error message STDOUT: "8f8ddfee3fed8c3c4ecec03526e4c936e80fda6f\n": this is not the output Overcommit is expecting, so it fails.

If npm is erroring when run, adding the --silent flag isn't the solution–there's a problem you need to fix (or a bug to report to the npm project). Hope this helps.

@sterpe
Copy link

sterpe commented Apr 3, 2016

@sds This information about the required_executable needs to be moved here https://github.com/brigade/overcommit/blob/master/lib/overcommit/hook/pre_commit/es_lint.rb

callaghanc added a commit to SFDigitalServices/sf-dahlia-web that referenced this issue Nov 19, 2018
The previous Coffeelint configuration in overcommit.yml was not working for me - Overcommit would throw an error when I ran it and it reached the stage where it tried to run Coffeelint. I used the information in this Overcommit GitHub issue: sds/overcommit#352, to update the configuration to something that worked without error.
akegan pushed a commit to SFDigitalServices/sf-dahlia-web that referenced this issue Dec 10, 2018
The previous Coffeelint configuration in overcommit.yml was not working for me - Overcommit would throw an error when I ran it and it reached the stage where it tried to run Coffeelint. I used the information in this Overcommit GitHub issue: sds/overcommit#352, to update the configuration to something that worked without error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants