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

Trailing whitespace after long line leads to invalid TS #586

Open
kanatohodets opened this issue Oct 20, 2020 · 0 comments
Open

Trailing whitespace after long line leads to invalid TS #586

kanatohodets opened this issue Oct 20, 2020 · 0 comments

Comments

@kanatohodets
Copy link

kanatohodets commented Oct 20, 2020

Hello! Thanks for gts, it is super handy.

I think I found an issue where eslint and prettier conflict and produce invalid TypeScript.

Using gts 3.0.1.

Test case:

function run() {
  warnLoudlyIfItSeemsSketch(doubleCheckTheSketch, flagsFlagsFlagsFlags, reticulatePlaceholderSplines, foo, bar, baz, qux);
   
}

// satisfy "declared but not used"
run();

Note that the last line of the function has junk whitespace.

After gts fix:

$ git diff
diff --git a/test.ts b/test.ts
index b79d7554..3961fa05 100644
--- a/test.ts
+++ b/test.ts
@@ -1,6 +1,13 @@
 function run() {
-  warnLoudlyIfItSeemsSketch(doubleCheckTheSketch, flagsFlagsFlagsFlags, reticulatePlaceholderSplines, foo, bar, baz, qux);
-   
+  warnLoudlyIfItSeemsSketch(
+    doubleCheckTheSketch,
+    flagsFlagsFlagsFlags,
+    reticulatePlaceholderSplines,
+    foo,
+    bar,
+    baz,
+    qux
+
 }
 
 // satisfy "declared but not used"
$ 

This is missing the final );, and thus invalid TypeScript. As far as I can tell this requires a combination of:

  1. A very long line that gts wants to flatten out, and
  2. Junk whitespace on the line after the long one.

Other info:

gts check output:

$ ./node_modules/gts/build/src/cli.js check test.ts 
version: 12

/tmp/example/test.ts
  2:29  error  Replace `doubleCheckTheSketch,·flagsFlagsFlagsFlags,·reticulatePlaceholderSplines,·foo,·bar,·baz,·qux);` with `⏎····doubleCheckTheSketch,⏎····flagsFlagsFlagsFlags,⏎····reticulatePlaceholderSplines,⏎····foo,⏎····bar,⏎····baz,⏎····qux`  prettier/prettier
  3:1   error  Trailing spaces not allowed                                                                                                                                                                                                                no-trailing-spaces
  3:3   error  Replace `·` with `);`                                                                                                                                                                                                                      prettier/prettier

✖ 3 problems (3 errors, 0 warnings)
  3 errors and 0 warnings potentially fixable with the `--fix` option.
$ 

gts fix output:

$ ./node_modules/gts/build/src/cli.js fix test.ts 
version: 12

/tmp/example/test.ts
  11:0  error  Parsing error: ',' expected

✖ 1 problem (1 error, 0 warnings)

Error: Command failed with exit code 1: node ./node_modules/eslint/bin/eslint --fix test.ts
    at makeError (/tmp/example/node_modules/gts/node_modules/execa/lib/error.js:59:11)
    at handlePromise (/tmp/example/node_modules/gts/node_modules/execa/index.js:114:26)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async run (/tmp/example/node_modules/gts/build/src/cli.js:123:17) {
  shortMessage: 'Command failed with exit code 1: node ./node_modules/eslint/bin/eslint --fix test.ts',
  command: 'node ./node_modules/eslint/bin/eslint --fix test.ts',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: undefined,
  stderr: undefined,
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}
$ 

(An eslint fluent colleague tells me that this stacktrace is more or less to be expected)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants