npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@putout/plugin-eslint

v9.1.0

Published

🐊Putout plugin for eslint config

Downloads

57,589

Readme

@putout/plugin-eslint NPM version

Find and fix problems in your JavaScript code

(c) eslint.org

🐊Putout plugin helps to automate fixing ESLint config.

Install

npm i @putout/plugin-eslint -D

Rules

Config

{
    "rules": {
        "eslint/add-putout": "on",
        "eslint/apply-dir-to-flat": "on",
        "eslint/apply-safe-align": "on",
        "eslint/apply-match-to-flat": "on",
        "eslint/move-putout-to-end-of-extends": "on",
        "eslint/convert-export-match-to-decleration": "on",
        "eslint/convert-files-to-array": "on",
        "eslint/convert-ide-to-safe": "on",
        "eslint/convert-require-to-import": "on",
        "eslint/convert-node-to-n": "on",
        "eslint/declare": "on",
        "eslint/remove-no-missing": "on",
        "eslint/remove-no-unpublished-require": "on",
        "eslint/remove-no-unsupported-features": "on",
        "eslint/remove-overrides-with-empty-rules": "on",
        "eslint/remove-useless-slice": "on",
        "eslint/remove-useless-properties": "on",
        "eslint/convert-plugins-array-to-object": "on",
        "eslint/convert-rc-to-flat": "off"
    }
}

add-putout

{
    "extends": [
+       "plugin:putout/safe+align",
        "plugin:node/recommended"
    ],
    "plugins": [
+       "putout",
        "node"
    ]
}

apply-safe-align

{
-    "rules": {
-       "putout/align-spaces": "error"
-    },
    "extends": [
-       "plugin:putout/safe",
+       "plugin:putout/safe+align",
        "plugin:node/recommended"
    ],
    "plugins": [
        "putout",
        "node"
    ]
}

apply-dir-to-flat

matchToFlatDir() and mergeESLintConfigs supports __dirname or import.meta.url starting from v2 of @putout/eslint-flat.

Check out in 🐊Putout Editor.

❌ Example of incorrect code

const scriptsConfig = await matchToFlatDir('scripts');
const monoConfig = await mergeESLintConfigs(['codemods', 'packages', 'rules']);

module.exports = [
    ...scriptsConfig,
    ...monoConfig,
];

✅ Example of correct code

// CommonJS
const scriptsConfig = await matchToFlatDir(__dirname, 'scripts');

// ESM
const monoConfig = await mergeESLintConfigs(import.meta.url, ['codemods', 'packages', 'rules']);

module.exports = [
    ...scriptsConfig,
    ...monoConfig,
];

apply-match-to-flat

Check out in 🐊Putout Editor.

❌ Example of incorrect code

import {safeAlign} from 'eslint-plugin-putout/config';

export default [
    ...safeAlign, {
        files: ['*.d.ts'],
        rules: {
            'no-var': 'off',
        },
    }, {
        files: ['*.spec.*'],
        rules: {
            'node/no-extraneous-import': 'off',
        },
    },
];

✅ Example of correct code

import {safeAlign} from 'eslint-plugin-putout/config';

const config = matchToFlat({
    '*.d.ts': {
        'no-var': 'off',
    },
    '*.spec.*': {
        'node/no-extraneous-import': 'off',
    },
});

export default [
    ...safeAlign,
    ...config,
];

move-putout-to-end-of-extends

❌ Example of incorrect code

{
    "extends": [
        "plugin:putout/recommended",
        "plugin:node/recommended"
    ],
    "plugins": [
        "putout",
        "node"
    ]
}

✅ Example of correct code

{
    "extends": [
        "plugin:node/recommended",
        "plugin:putout/recommended"
    ],
    "plugins": [
        "putout",
        "node"
    ]
}

convert-ide-to-safe

❌ Example of incorrect code

{
    "extends": [
        "plugin:node/recommended",
        "plugin:putout/ide"
    ],
    "plugins": [
        "putout",
        "node"
    ]
}

✅ Example of correct code

{
    "extends": [
        "plugin:node/recommended",
        "plugin:putout/safe"
    ],
    "plugins": [
        "putout",
        "node"
    ]
}

convert-files-to-array

Check it out in 🐊Putout Editor.

{
    "overrides": [{
-        "files": "test/*.js",
+        "files": ["test/*.js"],
         "rules": {
           "node/no-missing-require": "off"
        }
    }],
};

convert-require-to-import

node/no-missing-require has no sense when type=module in package.json. Check it out in 🐊Putout Editor.

{
    "overrides": [{
        "files": "test/*.js",
        "rules": {
-           "node/no-missing-require": "off"
+           "node/no-missing-import": "off"
        }
    }],
    "extends": [
        "plugin:node/recommended",
        "plugin:putout/recommended"
    ],
    "plugins": [
        "putout",
        "node"
    ]
};

remove-no-unpublished-require

node/remove-no-unpublished-require should be enabled, since this is a very useful rule, which shows what files should be add to .npmignore.

{
    "overrides": [{
        "files": "test/*.js",
        "rules": {
-           "node/no-unpublished-require": "off"
        }
    }],
    "extends": [
        "plugin:node/recommended",
        "plugin:putout/recommended"
    ],
    "plugins": [
        "putout",
        "node"
    ]
};

remove-no-unsupported-features

node/remove-no-unsupported-features is already disabled in eslint-plugin-putout.

{
    "overrides": [{
        "files": "test/*.js",
        "rules": {
-           "node/no-unpublished-require": "off"
        }
    }],
    "extends": [
        "plugin:node/recommended",
        "plugin:putout/recommended"
    ],
    "plugins": [
        "putout",
        "node"
    ]
};

remove-overrides-with-empty-rules

overrides with rules: {} has no sense. Check out in 🐊Putout Editor:

Remove overrides with one element with empty rules:

{
-   "overrides": [{
-       "files": "test/*.js",
-       "rules": {
-       }
-   }],
    "extends": [
        "plugin:node/recommended",
        "plugin:putout/recommended"
    ],
    "plugins": [
        "putout",
        "node"
    ]
};

Or remove empty overrides:

{
-   "overrides": [],
    "extends": [
        "plugin:node/recommended",
        "plugin:putout/recommended"
    ],
    "plugins": [
        "putout",
        "node"
    ]
};

And ofcourse remove only elements with empty rules:

{
  "overrides": [{
-   "files": "test/*.js",
-   "rules": {
-   }
- }, {
    "files": "test/*.js",
    "rules": {
      "no-semi": "off"
    }
  }],
    "extends": [
      "plugin:node/recommended",
      "plugin:putout/recommended"
    ],
    "plugins": [
      "putout",
      "node"
    ]
};

convert-node-to-n

eslint-plugin-node is no longer supported. Better to use eslint-plugin-n.

{
    "extends": [
        "plugin:putout/safe+align",
-       "plugin:node/recommended"
+       "plugin:n/recommended"
    ],
    "plugins": [
        "putout",
-       "node"
+       "n"
    ]
}

remove-no-missing

node/remove-no-missing-require and node/remove-no-missing-import doesn't supports exports and already disabled by eslint-plugin-putout.

{
    "overrides": [{
        "files": "test/*.js",
        "rules": {
-           "node/no-missing-require": "off",
-           "node/no-missing-import": "off"
        }
    }],
    "extends": [
        "plugin:node/recommended",
        "plugin:putout/recommended"
    ],
    "plugins": [
        "putout",
        "node"
    ]
};

remove-useless-slice

Fixes code after convert-array-copy-to-slice.

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

export default x.slice();

module.exports = x.slice();

✅ Example of correct code

export default x;

module.exports = x;

remove-useless-properties

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

module.exports = [
    ...safeAlign, {
        rules: {},
    },
];

✅ Example of correct code

module.exports = safeAlign;

convert-export-match-to-declaration

Fixes apply-match-to-flat. Checkout in 🐊Putout Editor.

❌ Example of incorrect code

module.exports.match = {
    'bin/**': {
        'no-process-exit': 'off',
    },
};

module.exports = [
    ...safeAlign, {
        rules: {
            'node/no-unsupported-features/node-builtins': 'off',
        },
    },
    ...matchToFlat(match),
];

✅ Example of correct code

const match = {
    'bin/**': {
        'no-process-exit': 'off',
    },
};

module.exports = [
    ...safeAlign, {
        rules: {
            'node/no-unsupported-features/node-builtins': 'off',
        },
    },
    ...matchToFlat(match),
];

module.exports.match = match;

declare

Declare:

convert-plugins-array-to-object

On the surface, using a plugin in flat config looks very similar to using a plugin in eslintrc. The big difference is that eslintrc used strings whereas flat configs uses objects. Instead of specifying the name of a plugin, you import the plugin directly and place it into the plugins key.

(c) eslint.org

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

export default {
    plugins: [react],
};

module.exports = {
    plugins: ['react'],
};

✅ Example of correct code

export default {
    plugins: {
        react,
    },
};

module.exports = {
    plugins: ['react'],
};

convert-rc-to-flat

Checkout in 🐊Putout Editor:

Converts .eslintrc.json:

{
    "root": true,
    "parser": "@typescript-eslint/parser",
    "env": {
        "node": true
    },
    "extends": ["eslint:recommended"],
    "plugins": ["@nx"],
    "rules": {
        "@typescript-eslint/explicit-module-boundary-types": "error"
    },
    "overrides": [{
        "files": ["*.json"],
        "parser": "jsonc-eslint-parser"
    }, {
        "files": [
            "*.ts",
            "*.tsx",
            "*.js",
            "*.jsx"
        ],
        "rules": {
            "@nx/enforce-module-boundaries": ["error", {
                "enforceBuildableLibDependency": true,
                "allow": [],
                "depConstraints": [{
                    "sourceTag": "*",
                    "onlyDependOnLibsWithTags": ["*"]
                }]
            }]
        }
    }]
}

To .eslint.config.js:

const nxPlugin = require('@nx/eslint-plugin');
const js = require('@eslint/js');
const globals = require('globals');
const jsoncParser = require('jsonc-eslint-parser');
const tsParser = require('@typescript-eslint/parser');

module.exports = [
    js.configs.recommended, {
        plugins: {
            '@nx': nxPlugin,
        },
    }, {
        languageOptions: {
            parser: tsParser,
            globals: {
                ...globals.node,
            },
        },
        rules: {
            '@typescript-eslint/explicit-module-boundary-types': ['error'],
        },
    }, {
        files: ['*.json'],
        languageOptions: {
            parser: jsoncParser,
        },
        rules: {},
    }, {
        files: [
            '*.ts',
            '*.tsx',
            '*.js',
            '*.jsx',
        ],
        rules: {
            '@nx/enforce-module-boundaries': ['error', {
                enforceBuildableLibDependency: true,
                allow: [],
                depConstraints: [{
                    sourceTag: '*',
                    onlyDependOnLibsWithTags: ['*'],
                }],
            }],
        },
    }];

License

MIT