Skip to content

[keyword-spacing] override this before: false with greater than #14712

Closed
@sam-s4s

Description

Tell us about your environment

  • ESLint Version: 7.27.0
  • Node Version: 14.17.0

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using?
@typescript-eslint/parser
but also tested with only using eslint and the problem still exists.

Please show your full configuration:

Configuration
{
  "rules": {
    'keyword-spacing': 'off',
    '@typescript-eslint/keyword-spacing': [
        'error',
        {
            "overrides": {
                "this": { "before": null },
                "new": { "before": null }
            }
        }
    ],
  }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

Here is a demo showing the problem:
https://eslint.org/demo#eyJ0ZXh0IjoiLyogZXNsaW50IGtleXdvcmQtc3BhY2luZzogWydlcnJvcicsIHtcbiAgICAgICAgICAgIFwib3ZlcnJpZGVzXCI6IHtcbiAgICAgICAgICAgICAgICBcInRoaXNcIjogeyBcImJlZm9yZVwiOiBmYWxzZSB9LFxuICAgICAgICAgICAgICAgIFwibmV3XCI6IHsgXCJiZWZvcmVcIjogZmFsc2UgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XSAqL1xuXG5pZiAodGhpcy5yZWZ1bmRBbW91bnQgPiB0aGlzLm1heGltdW1SZWZ1bmQpIHt9Iiwib3B0aW9ucyI6eyJwYXJzZXJPcHRpb25zIjp7ImVjbWFWZXJzaW9uIjoxMSwic291cmNlVHlwZSI6InNjcmlwdCIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6e30sImVudiI6e319fQ==

(note that when you change the > into a < the lint error goes away.

if (this.refundAmount > this.maximumRefund) { // the same thing with a less than works fine

I wasn't sure what to expect from this configuration of the rule. I had to set "this" and "new" to before: false, because I don't want a space between casting angle brackets <Thing>this.blah or <Thing>new Blah().
And I was happy when it seemed to work in almost all cases. Obviously I'm using this.blah in thousands of places, very commonly with spaces in front, and almost all of them work. The only exception is the "greater than" symbol, used for comparisons. Less than (and everything else) seems to work fine.

So given it only gives an error with the exact combination > this I feel like it's a bug.

What did you expect to happen?
No errors

What actually happened? Please copy-paste the actual, raw output from ESLint.
283:41 error Unexpected space(s) before "this" @typescript-eslint/keyword-spacing

Steps to reproduce this issue:

  1. (see demo above)

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionbugESLint is working incorrectlyrepro:yesIssues with a reproducible exampleruleRelates to ESLint's core rules

Type

No type

Projects

  • Status

    Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions