Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mbuchalik/eslint-plugin-library-import
Improve imports from popular libraries like Lodash
https://github.com/mbuchalik/eslint-plugin-library-import
Last synced: 5 days ago
JSON representation
Improve imports from popular libraries like Lodash
- Host: GitHub
- URL: https://github.com/mbuchalik/eslint-plugin-library-import
- Owner: MBuchalik
- License: mit
- Created: 2023-06-11T09:14:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-06-11T12:17:16.000Z (over 1 year ago)
- Last Synced: 2024-10-29T10:46:13.211Z (2 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/eslint-plugin-library-import
- Size: 79.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# eslint-plugin-library-import
> Improve imports from popular libraries like Lodash
Are you using a library like Lodash? Often, you want to avoid top-level imports like this:
```ts
import { isEqual } from 'lodash';
```and rather want to use an import like this:
```ts
import isEqual from 'lodash/isEqual';
````eslint-plugin-library-import` helps: This plugin contains auto-fixable (!) rules for such libraries.
> Please note that this plugin currently only has support for Lodash. If there is a popular library with a similar problem as in Lodash, feel free to open an Issue or to create a PR with a new rule. Please note however that we only accept libraries that are somewhat popular (like Lodash, MUI, etc.).
## Usage
First, install this eslint plugin:
```
npm install --save-dev eslint-plugin-library-import
```Then, add the following to the `plugins` sections of your eslint config file:
```js
plugins: ['library-import'],
```Finally, you can activate the Lodash rule:
```js
rules: {
'library-import/lodash': 'warn',
}
```Once you run the ESLint auto-fixer, the imports will get rewritten.
## Examples
Examples of **incorrect** code:
```ts
// 'library-import/lodash': 'warn',/*
The following will get auto-fixed to:
import isEqual from 'lodash/isEqual';
*/
import { isEqual } from 'lodash';/*
The following will get auto-fixed to:import isEqual from 'lodash/isEqual';
import each from 'lodash/each';
*/
import { isEqual, each } from 'lodash';/*
The following will not get auto-fixed.
*/
import lodash, { isEqual } from 'lodash';/*
The rule also does not allow this simple default import.
*/
import lodash from 'lodash';
```Examples of **correct** code:
```ts
// 'library-import/lodash': 'warn',import { isEqual } from 'this-is-not-lodash';
import { type isEqual } from 'lodash';
import type lodash from 'lodash';
```