allow semi colons in javascript eslint

2020-05-18 03:48发布

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?

2条回答
太酷不给撩
2楼-- · 2020-05-18 04:26

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
    }
}
查看更多
老娘就宠你
3楼-- · 2020-05-18 04:47

Modify your .eslintrc (deprecated) or .eslintrc.js(recommended) with

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

Good Luck...

查看更多
登录 后发表回答