Skip to content

putout v22.2.0

Choose a tag to compare

@coderaiser coderaiser released this 27 Nov 13:30
· 12818 commits to master since this release

Improved support of typescript-eslint

image

If night and day were to approach the Sun, Both would disappear.
In the same way, their duality would vanish
If their essential unity were seen

(c) Jnaneshvara "Amritanubhav"

More TypeScript nodes supported 💪

Thanks for an issue reported by @brunoparga , typescrit-eslint support improved drastically 🎉 .

It's AST has couple differences with @babel/parser that should be handled.

To the point! When you use .eslintrc.json:

{
    "parser": "@typescript-eslint/parser",
    "plugins": [
        "putout",
        "@typescript-eslint"
    ],
    "extends": [
        "plugin:putout/recommended",
        "plugin:@typescript-eslint/recommended"
    ]
}

With help of estree-to-babel, such constructs:

// TSClassImplements
class A implements B {
}
// TSInterfaceHeritage
interface x extends y.z.m {
}

// TSAbstractMethodDefinition
class Base {
    abstract getName(): string;
}

// PrivateIdentifier
class ClassWithPrivateField implements B{
    #privateField;
    pubplicField = 5;
    constructor() {
        this.#privateField = 5;
    }
}

Will work as expected, and will be parsed without a problem.
here is a circle of transformations: TypeScript AST -> ESTree -> Babel. But that's not a problem for estree-to-babel.

Improved support of comments

When using both typescript-eslint and eslint-plugin-putout there was an issue with comments:

/**
 * Copyright (c) 2016 The xterm.js authors. All rights reserved.
 * @license MIT
 */
import { ICircularList } from 'common/Types';

/**
 * Represents a circular list; a list with a maximum size that wraps around when push is called,
 * overriding values at the start of the list.
 */
export class CircularList<T> implements ICircularList<T> {
    get maxLength() {
        if (2)  // <-- should be removed with remove-constant-conditions
            alert();

        return this._maxLength;
    }
}

After applying fixes all comments go on top:

/**
 * Copyright (c) 2016 The xterm.js authors. All rights reserved.
 * @license MIT
 */
/**
 * Represents a circular list; a list with a maximum size that wraps around when push is called,
 * overriding values at the start of the list.
 */

import { ICircularList } from 'common/Types';

export class CircularList<T> implements ICircularList<T> {
    get maxLength() {
        alert();

        return this._maxLength;
    }
}

Which is very bad and has no sense. Starting from eslint-plugin-putout v11.18.0 it's fixed, and comments placed in the way they should:

/**
 * Copyright (c) 2016 The xterm.js authors. All rights reserved.
 * @license MIT
 */
import { ICircularList } from 'common/Types';

/**
 * Represents a circular list; a list with a maximum size that wraps around when push is called,
 * overriding values at the start of the list.
 */
export class CircularList<T> implements ICircularList<T> {
    get maxLength() {
        alert();

        return this._maxLength;
    }
}

That's all folks 🎈.

Have a nice day!
If you got any problems, create an issue!

🐞 fix

🔥 feature