Skip to content

brandnday/eslint-plugin-import-rewrite

Repository files navigation

eslint-plugin-import-rewrite

This is a simple Node.js module for eslint plugin which handles import rewrite. At this moment, the plugin can only replace a keyword in import path. This plugin might be useful if the project has multiple import alias or tsconfig alias.

Installation

npm install eslint-plugin-import-rewrite --save-dev

or

yarn add -D eslint-plugin-import-rewrite

Usage

Write down your import path aliases and path that needs to be rewritten.

// .eslintrc.js
module.exports = {
  plugins: ['import-rewrite'],
    parser: '@typescript-eslint/parser',
    ...
    rules: {
        'import-rewrite/rewrite-path': [
            'error',
            [
                {
                    keyword: 'lib',
                    replaceWith: '~lib',
                    message:
                        'Replace lib to ~lib'
                },
            ]
        ],
};

One of the way to add aliases if you are using typescript is using path alias, you can add the aliases to the paths in .tsconfig.json.

// .tsconfig.json
{
    "compilerOptions": {
        ...
        "paths": {
            "~src": ["src/*"],
        },
        ...
    }
}

References

About

An eslint plugin that handle import paths rewriting

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published