Why do linters pick on useless escape character?

前端 未结 2 1447
有刺的猬
有刺的猬 2021-01-29 07:51

Escaping non-special characters in strings, template literals, and regular expressions doesn\'t have any effect

Source: https://eslint.org/d

2条回答
  •  孤街浪徒
    2021-01-29 08:13

    If the escape character isn't doing anything useful, what is it doing there?

    Perhaps the writer of the code wanted a literal backslash character. The error draws attention to it so they can replace \ with \\.

    Perhaps they thought the next character needed escaping. This educates them otherwise.

    Perhaps it is just a typo.

    Since there is no good reason to have the \ there, there can only be bad reasons. Some are more seriously bad than others, but the linter will draw attention to them.

提交回复
热议问题