royriojas / eslint-friendly-formatter

A simple formatter/reporter for ESLint that's friendly with Sublime Text and iterm2 "click to open file" functionality
MIT License
198 stars 28 forks source link

message.source can be null #29

Closed Julian closed 6 years ago

Julian commented 6 years ago

Apologies if this is in the wrong place, I'm not a JS dev.

I think there's an assumption that message.source is undefined or an object with a length, but that doesn't appear to be the case. I was getting the below traceback, which, after inserting a console.log, showed me that message was the object at the top:

great@ build /Users/Julian/Development/Great/frontend node build/build.js "--output-path=/Users/Julian/Development/Great/frontend/great/static/"

⠸ building for production...{ filePath: 'src/main.js', ruleId: null, fatal: true, severity: 2, source: null, message: 'Parsing error: Cannot find module \'babel-eslint\'' } Hash: de4abf6558c690e13510 Version: webpack 3.10.0 Time: 1054ms Asset Size Chunks Chunk Names static/js/app.ac5f7a1782f171a9b60d.js 699 bytes 0 [emitted] app static/js/manifest.98e4b6563f239cfa083a.js 1.46 kB 1 [emitted] manifest static/js/app.ac5f7a1782f171a9b60d.js.map 1.07 kB 0 [emitted] app static/js/manifest.98e4b6563f239cfa083a.js.map 14.2 kB 1 [emitted] manifest index.html 352 bytes [emitted]

ERROR in ./src/main.js Module build failed: TypeError: Cannot read property 'length' of null at /Users/Julian/Development/Great/frontend/node_modules/eslint-friendly-formatter/index.js:185:74 at Array.reduce () at Object.module.exports [as formatter] (/Users/Julian/Development/Great/frontend/node_modules/eslint-friendly-formatter/index.js:160:17) at printLinterOutput (/Users/Julian/Development/Great/frontend/node_modules/eslint-loader/index.js:79:29) at Object.module.exports (/Users/Julian/Development/Great/frontend/node_modules/eslint-loader/index.js:213:3)

Build failed with errors.



where `source` is `null`, not `undefined`.
royriojas commented 6 years ago

hi @Julian can you provide a bit more context? not really clear from this output what was the command you were trying to execute. Can you provide a github repo with a minimum repro case?

Julian commented 6 years ago

Hey @royriojas will assemble one, thanks for the response!

Julian commented 6 years ago

@royriojas done: https://github.com/Julian/some-repo + npm run build

(Which I got by running vue init webpack some-repo and then just deleting babel-eslint from the package.json and running npm install)

royriojas commented 6 years ago

Thanks @Julian, will give it a try later today.

blacksun1 commented 6 years ago

Hey, I was able to reproduce the same bug by giving eslint the flag --report-unused-disable-directives and having one or more non-required disable comments.

bponomarenko commented 6 years ago

@royriojas I was able to reproduce this issue in the same way as @blacksun1. When there is at least one unused // eslint-disable comment in the code and --report-unused-disable-directives is present, message.source is set to null.

peteralt commented 6 years ago

So what is the recommended solution for this issue? I'm suddenly running into this and don't really know how to fix it.

peteralt commented 6 years ago

Following up on my request, I've been able to get the project working with this: In the .eslintrc.js file, I changed

parserOptions: { parser: 'babel-eslint' },

to parserOptions: { // parser: 'babel-eslint' },

Which seems to do the trick.

royriojas commented 6 years ago

It is really weird as I was not able to reproduce the issue locally. But @exbinary has made a fix for this and will just publish a new version since tests pass with his change. Hope this helps to alleviate this issue.

royriojas commented 6 years ago

closing as we've published v4.0.1