microsoft / vscode-typescript-tslint-plugin

VS Code extension that provides TSLint support using the typescript-tslint-plugin
https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-tslint-plugin
MIT License
188 stars 35 forks source link

Autofix issues with `ordered-imports` with `grouped-imports: true` option #132

Closed Greenek closed 1 year ago

Greenek commented 4 years ago

I came across a problem when sometimes autofix is not firing up on file saving, because of Overlapping ranges are not allowed! VSCode error. After investigation I found that it's caused by ordered-imports.grouped-imports: true option when imports in the file are not grouped properly. In order to make autofix working again I have to manually run "Fix: Imports from this module are not allowed in this group" first.

To reproduce this error clone @greenek/vscode-tslint-ordered-imports-bug repo, run npm install and try to autofix src/index.ts.

Example code:

import { Observable } from 'rxjs';

import { a } from './a/a';
import { tap } from 'rxjs/operators';
import { b } from '@b/b';

console.log(a, b, tap);

tslint.json

{
    "rules": {
        "ordered-imports": [
            true,
            {
                "grouped-imports": true,
                "groups": [
                    {
                        "match": "^@b",
                        "order": 20
                    },
                    {
                        "match": "^[.][.]",
                        "name": "parent_dir",
                        "order": 30
                    },
                    {
                        "match": "^[.]",
                        "name": "current dir",
                        "order": 40
                    },
                    {
                        "match": ".*",
                        "order": 10
                    }
                ],
                "import-sources-order": "case-insensitive",
                "named-imports-order": "case-insensitive"
            }
        ]
    }
}

tsconfig.json

{
    "compileOnSave": false,
    "compilerOptions": {
        "baseUrl": "./",
        "module": "esnext",
        "moduleResolution": "node",
        "outDir": "./dist/out-tsc",
        "target": "ES2015",
        "paths": {
            "@b/*": ["src/b/*"]
        }
    }
}

VSCode Log (Window)

[2020-04-15 12:41:00.996] [renderer4] [error] Error: Overlapping ranges are not allowed!
    at l.applyEdits (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1342:24)
    at e._doApplyEdits (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1374:236)
    at e.applyEdits (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1374:54)
    at pushEditOperation (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1210:85)
    at e._pushEditOperations (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1373:29)
    at e.pushEditOperations (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1371:918)
    at executeEdits (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1479:119)
    at executeEdits (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:2242:124)
    at D.apply (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:5835:131)
    at e.apply (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:5836:654)
    at e._performTextEdits (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:5839:313)
    at async e.perform (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:5838:82)
    at async x (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:2455:49)
    at async e.applyOnSaveActions (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:4615:78)
    at async e.participate (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:4614:624)
    at async file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:4445:205

vscode-tslint (deprecated) extension with "tslint.autoFixOnSave": true setting can be used as a temporary workaround.

VSCode v1.45.0-insider TSLint extension v1.2.3

frederikdekegel commented 4 years ago

I can confirm that I am experiencing this issue too. In order to solve I had to disable the grouping feature of the ordered imports rule. Using TSLint (deprecated) got me into other trouble. Though I know TSLint is deprecated, Angular is only migrating by the end of this year towards ESLint. So I would like to see this fixed, plz.

VSCode V1.45.0 TSLint 1.2.3

mjbvz commented 1 year ago

Closing as TSLint has been deprecated in favor of ESLint and this extension is no longer being maintained

Please look into migrating to use ESLint and the ESLint VS Code extension