millermedeiros / esformatter

ECMAScript code beautifier/formatter
MIT License
970 stars 91 forks source link

needs better error messages when formatting multiple files #303

Closed millermedeiros closed 9 years ago

millermedeiros commented 9 years ago

right now if it throws an error while trying to parse a file we have no idea where the error came from:

$ esformatter -i lib/**/*.js
/Users/millermedeiros/Projects/opensource/rocambole/node_modules/esprima/esprima.js:4365
            throw e;
                  ^
Error: Line 123: Unexpected token &

it should say which file triggered the error and we probably shouldn't even list "esprima" on the error message at all. We should probably say something like:

Error: /Users/millermedeiros/foo/bar.js:123 Unexpected token &

we should follow the format Error: <filepath>:<line> <error_message> (keep error message into a single line) to make it easier for other tools to parse it (some editors/terminals understand the :<line> after the file name but couldn't find any link to prove it's a real standard)

millermedeiros commented 9 years ago

another thing that was wrong is that we called process.exit() in multiple places of the app, we should really not terminate the program if it's formatting multiple files at once. we should log errors for each file and only set the exit code after formatting is complete.