sheerun / prettier-standard

Formats with Prettier and lints with ESLint+Standard! (✿◠‿◠)
MIT License
868 stars 44 forks source link

Extra semi-colon added before destructuring assignment #103

Closed jjarthur closed 4 years ago

jjarthur commented 4 years ago

I have the following code:

if (true) {
    [a, b] = ['a', 'b']
}

prettier-standard changes this to the following:

if (true) {
    ;[a, b] = ['a', 'b']
}

I'm not sure where this is coming from -- is this a bug?

JCQuintas commented 4 years ago

This is the correct behavior. This is one of the few cases where ; is required in JS

sheerun commented 4 years ago

yup

ertrzyiks commented 3 years ago

I experience the same issue as a result of conflict between prettier-standard and @typescript-eslint/no-extra-semi.

I created a simplified repo which helps to reproduce the problem: https://github.com/ertrzyiks/typescript-eslint-no-semi-repro

The content of the sample.ts file is the following:

(window.scrollY as unknown) = 123

no-extra-semi is ok without semicolon and actually complains when it's added prettier-standard forces the semicolon presence

no-extra-semi rule is right in this case, there is no other code that could possibly cause misinterpretation. The same is true for the example given by @jjarthur

The semicolon is needed only if there is any other expression before (. You can modify the sample.ts to have it like:

console.log('Hello world')
;(window.scrollY as unknown) = 123

Then both prettier-standard and no-extra-semi rule get it right - the semicolor is required.

@JCQuintas @sheerun please reconsider this as a bug