Skip to content

8Crafter-Studios/eslint-plugin-no-import-attributes

Repository files navigation

eslint-plugin-no-import-attributes

NPM Downloads NPM Version NPM License NPM Last Update NPM Unpacked Size GitHub last commit Discord

An ESLint plugin that bans import attributes (with {}).

The plugin support custom messages and quick fixes.

Installation

Install ESLint if you haven't already:

npm i eslint --save-dev

Install the plugin:

npm i eslint-plugin-no-import-attributes --save-dev

Usage

Flat Config

Here are six examples of flat configs using this plugin:

// eslint.config.js
import noImportAttributes from "eslint-plugin-no-import-attributes";

export default [
    // Enables the plugin and sets the `no-import-attributes/no-import-attributes` rule to "error".
    noImportAttributes.flatConfigs.recommended,
];
// eslint.config.js
import noImportAttributes from "eslint-plugin-no-import-attributes";

export default [
    // Enables the plugin and sets the `no-import-attributes/no-import-attributes` rule to "error".
    noImportAttributes.flatConfigs.recommended,
    {
        rules: {
            // Sets the message for the `no-import-attributes/no-import-attributes` rule to "Import attributes are not supported.".
            "no-import-attributes/no-import-attributes": ["error", "Import attributes are not supported."],
        },
    },
];
// eslint.config.mjs
import noImportAttributes from "eslint-plugin-no-import-attributes";

export default [
    // Enables the plugin and sets the `no-import-attributes/no-import-attributes` rule to "error".
    noImportAttributes.flatConfigs.recommended,
    {
        rules: {
            // Sets the message for the `no-import-attributes/no-import-attributes` rule to "Import attributes are not supported.".
            "no-import-attributes/no-import-attributes": ["error", { message: "Import attributes are not supported." }],
        },
    },
];
// eslint.config.mjs
import noImportAttributes from "eslint-plugin-no-import-attributes";

export default [
    {
        plugins: {
            // Enables the plugin.
            "no-import-attributes": noImportAttributes,
        },
        rules: {
            // Sets the message for the `no-import-attributes/no-import-attributes` rule to "Import attributes are not supported.", and sets the severity to "error".
            "no-import-attributes/no-import-attributes": ["error", { message: "Import attributes are not supported." }],
        },
    },
];
// eslint.config.cjs
const noImportAttributes = require("eslint-plugin-no-import-attributes");

module.exports = [
    // Enables the plugin and sets the `no-import-attributes/no-import-attributes` rule to "error".
    noImportAttributes.flatConfigs.recommended,
    {
        rules: {
            // Sets the message for the `no-import-attributes/no-import-attributes` rule to "Import attributes are not supported.".
            "no-import-attributes/no-import-attributes": ["error", { message: "Import attributes are not supported." }],
        },
    },
];
// eslint.config.cjs
const noImportAttributes = require("eslint-plugin-no-import-attributes");

module.exports = defineConfig([
    // Enables the plugin and sets the `no-import-attributes/no-import-attributes` rule to "error".
    noImportAttributes.flatConfigs.recommended,
    {
        rules: {
            // Sets the message for the `no-import-attributes/no-import-attributes` rule to "Import attributes are not recommended.", and sets the severity to "warn".
            "no-import-attributes/no-import-attributes": ["warn", "Import attributes are not recommended."],
        },
    },
]);

Legacy Config

Here are four examples of legacy configs using this plugin:

// .eslintrc.json
{
    "extends": [
        // Enables the plugin and sets the `no-import-attributes/no-import-attributes` rule to "error".
        "plugin:no-import-attributes/recommended"
    ]
}
// .eslintrc
{
    "extends": [
        // Enables the plugin and sets the `no-import-attributes/no-import-attributes` rule to "error".
        "plugin:no-import-attributes/recommended"
    ],
    "rules": {
        // Sets the message for the `no-import-attributes/no-import-attributes` rule to "Import attributes are not recommended.", and sets the severity to "warn".
        "no-import-attributes/no-import-attributes": ["warn", "Import attributes are not recommended."]
    }
}
// .eslintrc
{
    "plugins": [
        // Enables the plugin.
        "no-import-attributes"
    ],
    "rules": {
        // Sets the message for the `no-import-attributes/no-import-attributes` rule to "Import attributes are not recommended.", and sets the severity to "warn".
        "no-import-attributes/no-import-attributes": ["warn", "Import attributes are not recommended."]
    }
}
// .eslintrc.cjs
/* eslint-env node */
module.exports = {
    extends: ["plugin:no-import-attributes/recommended"],
    rules: {
        // Sets the message for the `no-import-attributes/no-import-attributes` rule to "Import attributes are not recommended.", and sets the severity to "warn".
        "no-import-attributes/no-import-attributes": ["warn", "Import attributes are not recommended."],
    },
};

Planned Features/Improvements

  • Add support for banning import attributes in dynamic import() statements.
  • Fix the bug where the quick fix removes comments that are placed in between the import source and the with keyword.

About

An eslint plugin that bans import attributes (`with {}`).

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors