question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

False positive for 'no-multi-spaces' combined with 'key-spacing'

See original GitHub issue

Tell us about your environment

Environment Info:

Node version: v10.15.3 npm version: v6.13.1 Local ESLint version: v6.8.0 (Currently used) Global ESLint version: Not found

What parser (default, Babel-ESLint, etc.) are you using?

default, cli

Please show your full configuration:

A portion of interest, json format
    "no-multi-spaces": [
        "error",
        {
            "exceptions": {
                "Property": true,
                "VariableDeclarator": true,
                "ImportDeclaration": true,
                "AssignmentExpression": true
            }
        }
    ],
    "key-spacing": [
        "error",
        {
            "align": "value"
        }
    ],

This is decorator for component for stenciljs web component


@Component({
    tag:      'test-input-search',
    styleUrl: 'input-search.scss',
    shadow:   true,
})
export class InputSearch implements ComponentInterface {
   ...
}
node_modules/.bin/eslint 'src/**/*.{js,ts,tsx}'

What did you expect to happen?

Nothing, lint pass

What actually happened? Please include the actual, raw output from ESLint.

16:9 error Multiple spaces found before ‘‘test-input-search’’ no-multi-spaces 18:12 error Multiple spaces found before ‘true’ no-multi-spaces

Are you willing to submit a pull request to fix this bug?

No, sorry, I am not that into this project in order to be able to contribute.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Jan 14, 2020

I guess you’re using @typescript-eslint/parser?

The problem is most likely with this syntax, in particular with export being between the class and the decorator, not with decorators in general.

In AST, and logically, it’s export > class > decorator (class is a child of export, decorator is a child of the class).

In this source code, the range of the decorator ends up being outside of its class and export ancestors (which is unusual, but a consequence of the @dec export class syntax).

What happens here is, I believe, the following - utility function that looks for the deepest node that contains those multi-spaces returns the "Program" node because it skips traversing export (for performance reasons as its range doesn’t contain the range of the multi-spaces), so it never examines export’s descendant nodes: the decorator and the correct "Property" node inside the decorator.

If you define { "Program": true } as an exception for no-multi-spaces these errors will disappear. But, that could hide some other real errors so it probably isn’t a good solution.

Another solution is to rewrite the code to:

@Component({
    tag:      'test-input-search',
    styleUrl: 'input-search.scss',
    shadow:   true,
})
class InputSearch implements ComponentInterface {
    //    ...
}

export { InputSearch };

It might be also good to open an issue in the typescript-eslint/typescript-eslint repo, maybe they have a solution for this problem.

It’s also possible that the syntax will be changed to export @dec class in the future.

0reactions
eslint-deprecated[bot]commented, Feb 14, 2020

It looks like the conversation is stalled here. As this is a question rather than an action item, I’m closing the issue. If you still need help, please send a message to our mailing list or chatroom. Thanks! [//]: # (auto-close)

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-multi-spaces - ESLint - Pluggable JavaScript Linter
This rule's configuration consists of an object with the following properties: "ignoreEOLComments": true (defaults to false ) ignores multiple spaces before ...
Read more >
eslint/CHANGELOG.md - UNPKG
784, * a3ff8f2 Chore: combine tests in tests/lib/eslint.js and ... 897, * 3c87e85 Fix: no-multi-spaces false positive with irregular indent whitespace ...
Read more >
tslint-eslint-rules | Yarn - Package Manager
You want to code in TypeScript but miss all the rules available in ESLint? Now you can combine both worlds by using this...
Read more >
React typescript: eslint max-length autofix does not work
There have been a couple of issues that are opened, about adding auto-fix for the max-len rule, but unfortunately, the eslint team doesn't ......
Read more >
tslint-eslint-rules - npm
Now you can combine both worlds by using this TSLint plugin! ... Description: Ensure that the results of typeof are compared against a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found