javascript - ESLint error on semicolon after class declaration ECMAScript 6 -


i have following code:

class car() {      constructor() {         // ...     }      withsemi() {         // ...     };  // eslint not complain here      withoutsemi() {        // ...     }  // eslint not complain here  };  // eslint complain semicolon (no-extra-semi) 

can explain how automatic semicolon insertion work in es6 in regards classes , why eslint has behaviour?

according ecmascript 2015 class specification, semicolon valid classelement, can exist within classbody.

however, semantics treat having no behavior whatsoever (for example, see nonconstructormethoddefinitions). effectively can have many or few semicolons want in classbody , won't change thing.

automatic semicolon insertion doesn't come play here, or people think in general. speaking, asi happens when parser sees wouldn't allowed part of previous block or line. (the actual rules asi aren't terribly long if you're interested; scroll down examples , practical advice.) in context, you're allowed put bunch of class method definitions sequentially. there's nothing "unexpected" next method in list, no semicolon gets inserted between them.

i don't know history of decision, assume semicolons valid classelements because valid empty statements, , confusing folks if couldn't put semicolons in class body.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -