Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

allow semi colons in javascript eslint

I have following .eslintrc

{     "extends": "standard" } 

I have following code in my javascript file

import React from 'react'; 

Above line of code is incorrect according to eslint. It gives following complain.

";                     Extra semicolon 

How can I allow semi colons in eslint?

like image 205
Om3ga Avatar asked Nov 06 '16 20:11

Om3ga


People also ask

Do you require semicolons ESLint?

This rule has two options, a string option and an object option. String option: "always" (default) requires semicolons at the end of statements. "never" disallows semicolons as the end of statements (except to disambiguate statements beginning with [ , ( , / , + , or - )

Is it OK to not use semicolons in JavaScript?

Semicolons are an essential part of JavaScript code. They are read and used by the compiler to distinguish between separate statements so that statements do not leak into other parts of the code. The good news is that JavaScript includes an automatic semicolon feature.

What is the purpose of semi colons (;) in JavaScript?

The JavaScript parser will automatically add a semicolon when, during the parsing of the source code, it finds these particular situations: when the next line starts with code that breaks the current one (code can spawn on multiple lines) when the next line starts with a } , closing the current block.

How do you set rules in ESLint?

There are two primary ways to configure ESLint: Configuration Comments - use JavaScript comments to embed configuration information directly into a file. Configuration Files - use a JavaScript, JSON, or YAML file to specify configuration information for an entire directory and all of its subdirectories.


1 Answers

eslint-config-standard uses the following rule for semicolons:

"semi": [2, "never"] 

The documentation for the rule lists its options:

  • "always" (default) requires semicolons at the end of statements
  • "never" disallows semicolons as the end of statements (except to disambiguate statements beginning with [, (, /, +, or -

To overide the rule, you could modify your .eslintrc to always require semicolons:

{     "extends": "standard",     "rules": {         "semi": [2, "always"]     } } 

Or to disable the rule:

{     "extends": "standard",     "rules": {         "semi": 0     } } 
like image 174
cartant Avatar answered Sep 20 '22 15:09

cartant