Trailing whitespace after long line leads to invalid TS
- Dominant language
- TypeScript
- Stars
- 5.3k
- Forks
- 212
- PR merge metrics
- No merged PRs in 30d
Description
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:
```typescript
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`:
```diff
$ 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:
```shell
$ ./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:
```shell
$ ./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)
Contributor guide
Assessment
This issue has not been assessed yet.