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

[keyword-spacing] Require space before / after as #1729

Closed
OoDeLally opened this issue Mar 13, 2020 · 5 comments · Fixed by #1739
Closed

[keyword-spacing] Require space before / after as #1729

OoDeLally opened this issue Mar 13, 2020 · 5 comments · Fixed by #1739
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@OoDeLally
Copy link
Contributor

Repro

const foo = {}as object;
{
  "rules": {
    "keyword-spacing": "warn",
  }
}

Expected Result

Warning about a missing space before as.

Actual Result

No warning.

Additional Info

It would be nice to have a @typescript-eslint/keyword-spacing rule to cover the typescript keywords.

Versions

package version
@typescript-eslint/eslint-plugin 2.23.0
@typescript-eslint/parser 2.23.0
TypeScript 3.8.3
ESLint 6.8.0
node 12.16.1
npm 6.13.4
@OoDeLally OoDeLally added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Mar 13, 2020
@bradzacher bradzacher added enhancement: new base rule extension New base rule extension required to handle a TS specific case and removed triage Waiting for maintainers to take a look labels Mar 14, 2020
@bradzacher
Copy link
Member

shouldn't be overly difficult - happy to accept a PR!

@OoDeLally
Copy link
Contributor Author

Here you go #1739

@bradzacher bradzacher added the has pr there is a PR raised to close this label Mar 16, 2020
@rhuitl
Copy link

rhuitl commented Mar 16, 2020

A related use case for a TypeScript keyword-spacing rule is this:

In our TypeScript codebase, we want to ban if(condition) in favor of if (condition). Enabling eslint "keyword-spacing": "error" will fail on code that does a type cast that involves this, for example
<unknown>this.property
because this is a keyword in eslint. However, we don't like
<unknown> this.property
with the space. Setting
"keyword-spacing": ["error", {"overrides": {"this": {"before": false}}}]
allows the type cast, but now comparisons like a > this.property fail.

Do you think your rule will be able do enforce this?

@OoDeLally
Copy link
Contributor Author

@rhuitl I had a look at it.
The problem is that I would have to overwrite the checkSpacingBefore function and therefore re declare pretty much every keyword's rule.
@bradzacher @G-Rath Is there a way to preventively suppress the expected reporting of a rule? It would be awesome to leave a dont report here flag for a subsequently-run rule. Without this, I don't think @rhuitl's request is doable without rewriting every single rule.

@bradzacher
Copy link
Member

it is not possible, unless there's something in the base rule's code.
My recommendation is to never use angle bracket assertions anyways, as the syntax is easy to confuse with JSX, and will actively not work in a TSX file.

This is a separate case, and I would not worry about it with this issue @OoDeLally.
If it's important to @rhuitl, they can raise a separate issue for it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants