允许在javascript eslint中使用分号 [英] allow semi colons in javascript eslint

查看:973
本文介绍了允许在javascript eslint中使用分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关注了 .eslintrc

{
    "extends": "standard"
}

我的javascript文件中包含以下代码

I have following code in my javascript file

import React from 'react';

根据eslint,以上代码行均不正确。

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

";                     Extra semicolon

如何在eslint中使用半冒号?

How can I allow semi colons in eslint?

推荐答案

eslint-config-standard 对分号使用以下规则:

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 -

要覆盖规则,您可以修改 .eslintrc 以始终需要分号:

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

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

或禁用规则:

{
    "extends": "standard",
    "rules": {
        "semi": 0
    }
}

这篇关于允许在javascript eslint中使用分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆