Skip to content

R1ON/eslint-plugin-import-name

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eslint-plugin-import-name

npm NPM total downloads

Eslint plugin to restrict import name. Works with default and CommonJS imports.

Installation

yarn add -D eslint-plugin-import-name

or

npm install -D eslint-plugin-import-name

How to use:

Add to your .eslintrc:

"extends": [
    "plugin:import-name/recommended"
]

This will add the correct name for the package classnames. Or create your own rule for your imports:

"plugins": ["import-name"],
"rules": {
    "import-name/default-import-name": [
        'error',
        { classnames: 'classNames', 'prop-types': 'PropTypes' }
    ],
    "import-name/common-import-name": [
        'warning',
        { 'cookie-parser': 'cookieParser' }
    ],
}

Rules:

  • all-imports-name - combines the two previous rules together.
'import-name/all-imports-name': [
    'error',
    { classnames: 'classNames', 'prop-types': 'PropTypes' }
],
  • default-import-name - allows you to create a constant name for default import.
'import-name/default-import-name': [
    'error',
    { classnames: 'classNames', 'prop-types': 'PropTypes' }
]

Bad: ❌
import cx from 'classnames';
import proptypes from 'prop-types';

Good: ✅
import classNames from 'classnames';
import PropTypes from 'prop-types';
  • common-import-name - allows you to create a constant name for CommonJS import.
'import-name/common-import-name': [
    'error',
    { classnames: 'classNames', 'prop-types': 'PropTypes' }
]

Bad: ❌
const cx = require('classnames');
const proptypes = require('prop-types');

Good: ✅
const classNames = require('classnames');
const PropTypes = require('prop-types');

About

Eslint plugin to restrict the name of imports. Works with default and CommonJS imports.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published