Skip to content

Latest commit

 

History

History
386 lines (312 loc) · 9.85 KB

File metadata and controls

386 lines (312 loc) · 9.85 KB

@putout/plugin-eslint-plugin NPM version

Find and fix problems in your JavaScript code

(c) eslint.org

🐊Putout plugin helps to automate fixing ESLint plugins.

Install

npm i @putout/plugin-eslint-plugin -D

Rules

Config

{
    "rules": {
        "eslint-plugin/apply-flat-config-to-rule-tester": "on",
        "eslint-plugin/apply-get-token-before": "on",
        "eslint-plugin/apply-get-token-after": "on",
        "eslint-plugin/apply-is-space-between": "on",
        "eslint-plugin/convert-context-to-source": "on",
        "eslint-plugin/convert-require-resolve-to-require": "on",
        "eslint-plugin/turn-off-schema": "on",
        "eslint-plugin/update-ecma-version": ["on", {
            "ecmaVersion": 2025
        }],
        "eslint/remove-errors-type": "on"
    }
}

apply-flat-config-to-rule-tester

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

const parserTester = new RuleTester({
    parser: require.resolve('@babel/eslint-parser/experimental-worker'),
    parserOptions: {
        requireConfigFile: false,
        babelOptions: {
            plugins: ['@babel/plugin-syntax-typescript'],
        },
    },
});

✅ Example of correct code

const parserTester = new RuleTester({
    parser: require.resolve('@babel/eslint-parser/experimental-worker'),
    parserOptions: {
        requireConfigFile: false,
        babelOptions: {
            plugins: ['@babel/plugin-syntax-typescript'],
        },
    },
});

apply-get-token-before

The following deprecated SourceCode methods have been removed in ESLint v10.0.0: getTokenOrCommentBefore().

(c) eslint.org

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

source.getTokenOrCommentBefore(token);
source.getTokenOrCommentBefore(token, x);

✅ Example of correct code

source.getTokenBefore(token, {
    includeComments: true,
});
source.getTokenBefore(token, {
    skip: x,
    includeComments: true,
});

apply-get-token-after

The following deprecated SourceCode methods have been removed in ESLint v10.0.0: getTokenOrCommentAfter().

(c) eslint.org

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

source.getTokenOrCommentAfter(token);
source.getTokenOrCommentAfter(token, x);

✅ Example of correct code

source.getTokenAfter(token, {
    includeComments: true,
});
source.getTokenAfter(token, {
    skip: x,
    includeComments: true,
});

apply-is-space-between

The following deprecated SourceCode methods have been removed in ESLint v10.0.0: isSpaceBetweenTokens().

(c) eslint.org

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

isSpaceBetweenTokens(first, second);

✅ Example of correct code

isSpaceBetween(first, second);

convert-context-to-source

When ESLint v9.0.0 is released, it will ship with several breaking changes for rule authors. These changes are necessary as part of the work to implement language plugins, which gives ESLint first-class support for linting languages other than JavaScript.

(c) eslint.org

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

context.parserServices;
sourceCode.parserServices;
context.getAncestors(node);
context.getDeclaredVariables(node);
context.getScope();
context.getCwd();
context.getSourceCode();
context.markVariableAsUsed(name);
context.getFilename();
context.getPhysicalFilename();
const nextNode = context.getNodeByRangeIndex(node.range[1] + 2);

context.getSource();
context.getSourceLines();
context.getAllComments();
context.getComments();
context.getCommentsBefore();
context.getCommentsAfter();
context.getCommentsInside();
context.getJSDocComment();
context.getFirstToken();
context.getFirstTokens();
context.getLastToken();
context.getLastTokens();
context.getTokenAfter();
context.getTokenBefore();
context.getTokenByRangeStart();
context.getTokens();
context.getTokensAfter();
context.getTokensBefore();
context.getTokensBetween();
context.parserServices;

✅ Example of correct code

sourceCode.parserServices;
sourceCode.parserServices;
sourceCode.getAncestors(node);
sourceCode.getDeclaredVariables(node);
sourceCode.getScope();
context.cwd;
context.sourceCode;
sourceCode.markVariableAsUsed(name);
context.filename;
context.physicalFilename;
const nextNode = sourceCode.getNodeByRangeIndex(node.range[1] + 2);

sourceCode.getText();
sourceCode.getLines();
sourceCode.getAllComments();
sourceCode.getComments();
sourceCode.getCommentsBefore();
sourceCode.getCommentsAfter();
sourceCode.getCommentsInside();
sourceCode.getJSDocComment();
sourceCode.getFirstToken();
sourceCode.getFirstTokens();
sourceCode.getLastToken();
sourceCode.getLastTokens();
sourceCode.getTokenAfter();
sourceCode.getTokenBefore();
sourceCode.getTokenByRangeStart();
sourceCode.getTokens();
sourceCode.getTokensAfter();
sourceCode.getTokensBefore();
sourceCode.getTokensBetween();
sourceCode.parserServices;

convert-require-resolve-to-require

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

const test = new RuleTester({
    languageOptions: {
        parser: require.resolve('@babel/eslint-parser/experimental-worker'),
        parserOptions: {
            requireConfigFile: false,
            babelOptions: {
                plugins: ['@babel/plugin-syntax-typescript'],
            },
        },
    },
});

✅ Example of correct code

const test = new RuleTester({
    languageOptions: {
        parser: require('@babel/eslint-parser/experimental-worker'),
        parserOptions: {
            requireConfigFile: false,
            babelOptions: {
                plugins: ['@babel/plugin-syntax-typescript'],
            },
        },
    },
});

turn-off-schema

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

function getMeta(plugin) {
    const {
        type = 'layout',
        recommended = true,
        fixable = 'whitespace',
    } = plugin;
    
    return {
        type,
        docs: {
            recommended,
        },
        schema: {},
        fixable,
    };
}

✅ Example of correct code

function getMeta(plugin) {
    const {
        type = 'layout',
        recommended = true,
        fixable = 'whitespace',
    } = plugin;
    
    return {
        type,
        docs: {
            recommended,
        },
        schema: false,
        fixable,
    };
}

update-ecma-version

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

const ruleTester = new RuleTester({
    languageOptions: {
        parserOptions: {
            ecmaVersion: 2024,
            sourceType: 'module',
        },
    },
});

✅ Example of correct code

const ruleTester = new RuleTester({
    languageOptions: {
        parserOptions: {
            ecmaVersion: 2025,
            sourceType: 'module',
        },
    },
});

remove-errors-type

In ESLint v10.0.0, the deprecated nodeType property on LintMessage objects has been removed. Correspondingly, RuleTester no longer accepts the deprecated type property in errors of invalid test cases.

(c) eslint.org

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

ruleTester.run('remove-newline-after-default-import', rule, {
    invalid: [{
        errors: [{
            message: 'Remove newline before t.end()',
            type: 'CallExpression',
        }],
    }],
});

✅ Example of correct code

ruleTester.run('remove-newline-after-default-import', rule, {
    invalid: [{
        errors: [{
            message: 'Remove newline before t.end()',
        }],
    }],
});

License

MIT