为什么 ESLint 在我认为有用的地方警告分号?

Why is ESLint warning about a semicolon where I think it's useful?

    fetch_roles () {
      axios.get('/roles')
        .then((response) => {
          this.is_loaded = true; <-- ES lint hate this semicolon?! 
          this.pageData = response
        })
        .catch((error) => {
          alert(`Error: ${error}`)
        })
    }

对于上面显示的分号,我得到 ESLint: Extra semicolon.(semi)。如果我们缩小,分号不是很好吗?

I get ESLint: Extra semicolon.(semi) for the above pointed semicolon.

ESLint 可以配置为 require, ignore, or forbid optional semi-colons。您的配置已将它们设置为禁止。

Isn't the semicolon better be there incase we minify ?

如果在缺少可选分号时缩小会导致问题,那么您需要更好的缩小器。

听起来您的 linter 配置当前设置为禁止分号。

如果您是专家并且一眼就能识别出自动分号插入规则导致的潜在错误,您可以保留当前规则并安全地从该行中删除分号。

否则,您可能会发现将 semi 规则更改为在适当的时候要求使用分号会更有益,这样可以防止出现难以理解的错误。

为此,change the semi rule 改为 always 而不是 never。您还需要在以下行中添加分号:

this.pageData = response
alert(`Error: ${error}`)

分号的存在(或不存在)不会真正影响缩小。如果一行中没有分号由于不直观的 ASI 行为而导致错误,则无论源文件是 运行 还是缩小文件是 运行.

,该错误都会存在