nrwl / precise-commits

:sparkles: Painlessly apply Prettier by only formatting lines you have modified anyway!
MIT License
471 stars 20 forks source link

Syntax Error Parsing CodeMirror #16

Open twigz20 opened 6 years ago

twigz20 commented 6 years ago

We're integrating precise-commits into our project and running into a failure when we try and commit our files:

√  [489/960] Processing file: src/editor/src/thirdparty/CodeMirror/addon/comment/comment.js
×  precise-commits: An Error occurred

{ SyntaxError: Unexpected token (1:9)
> 1 | function(mod) {
    |         ^
  2 |     if (typeof exports == "object" && typeof module == "object") // CommonJS
  3 |       mod(require("../../lib/codemirror"));
  4 |     else if (typeof define == "function" && define.amd) // AMD
    at createError (D:\Programming\WebDev\next\node_modules\prettier\parser-babylon.js:1:110)
    at Object.parse (D:\Programming\WebDev\next\node_modules\prettier\parser-babylon.js:1:170100)
    at Object.parse$3 [as parse] (D:\Programming\WebDev\next\node_modules\prettier\index.js:23660:19)
    at formatWithCursor (D:\Programming\WebDev\next\node_modules\prettier\index.js:29344:27)
    at format (D:\Programming\WebDev\next\node_modules\prettier\index.js:29389:10)
    at formatRange (D:\Programming\WebDev\next\node_modules\prettier\index.js:29626:26)
    at formatWithCursor (D:\Programming\WebDev\next\node_modules\prettier\index.js:29348:30)
    at format (D:\Programming\WebDev\next\node_modules\prettier\index.js:29389:10)
    at Object.format (D:\Programming\WebDev\next\node_modules\prettier\index.js:29649:12)
    at D:\Programming\WebDev\next\node_modules\precise-commits\lib\precise-formatters\prettier.js:42:64
  loc: { start: { line: 1, column: 9 } },
  codeFrame: '> 1 | function(mod) {\n    |         ^\n  2 |     if (typeof exports == "object" && typeof module == "object") // CommonJS\n  3 |       mod(require("../../lib/codemirror"));\n  4 |     else if (typeof define == "function" && define.amd) // AMD' }

husky > pre-commit hook failed (add --no-verify to bypass)

The file that's causing this is: comment.js

When we've tried running prettier on the file by itself it seems to work. All of the following versions of prettier work stand-alone.

I'm not sure where the bug is, but I wanted to file with you to get some help because I'm stuck. It certainly looks like precise-commits is involved or the version of prettier it's using is involved.

cc @dsych