Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rule to detect useless escapes #203

Open
ajafff opened this issue Apr 19, 2018 · 2 comments
Open

add rule to detect useless escapes #203

ajafff opened this issue Apr 19, 2018 · 2 comments

Comments

@ajafff
Copy link
Member

ajafff commented Apr 19, 2018

In the git history of trailing-newline.ts you can find a mistake where I wrote '\UFEFF' instead of \uFEFF.
The rule should check every string and template literal for escaped characters that are useless.
Some background on escape sequences: https://mathiasbynens.be/notes/javascript-escapes

It doesn't need to check for useless escapes in regular expressions.

It should allow '\${' and `\${` only if followed by { to allow for escaping template literal substitutions (or suppress TSLint's no-invalid-template-strings).

Note that this information is not present in the AST node, so you need to use node.getText() to get the raw source text.

The autofixer could just remove the backslash.

@ajafff
Copy link
Member Author

ajafff commented Apr 26, 2018

The rule should probably exclude tagged template literals, because the tag function can actually access the content of the original escape and may use that for some strange magic.
https://tc39.github.io/proposal-template-literal-revision/

@ajafff
Copy link
Member Author

ajafff commented May 17, 2018

Octal escapes in string literal types are not parsed, the escape is therefore useless. But that may also just be a bug: microsoft/TypeScript#24209

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant