为什么短绒棉会选择无用的逃生字符? [英] Why do linters pick on useless escape character?

查看:138
本文介绍了为什么短绒棉会选择无用的逃生字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在字符串,模板文字和正则表达式中转义非特殊字符没有任何作用

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

来源: https://eslint.org/docs/rules/no-useless -转义

但是显然这是错误的:

这里没有什么可以修复"的;我们都知道这是一个完全有效的字符序列.

There's nothing to "fix" here; we all know this is a perfectly valid sequence of characters.

开玩笑的原因是什么?

如果连ESLint都承认没有伤害,那为什么还要打扰呢?如果仅查看最终结果(我知道不会打印出\字符)可能没有用,但是在代码就是数据" 上下文中,这可能是有用的数据在进行语法分析时.

If even ESLint acknowledges that there's no harm then why bother? It may be useless if you only look at the end result (I know that the \ character won't be printed out) but in a "code is data" context, this may be useful data when doing syntax analysis.

ESLint会对字符串中的内容进行判断,但是它不会与以下代码放在一起:(这对我来说也很没用)

ESLint makes a judgment on what goes into the string, yet it won't budge with this code: (and that's pretty useless to me too)

var x = 10;
var y = x + 0;
var z = y * 1;

推荐答案

如果转义字符没有做任何有用的事情,那么它在做什么?

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.

这篇关于为什么短绒棉会选择无用的逃生字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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