![Introducing Dashboard Analytics](https://cdn.sanity.io/images/cgdhsj6q/production/af327c5bd94708db501516a75da6870aef894c64-2286x1522.png?w=400&fit=max&auto=format)
Product
Introducing Dashboard Analytics
We're introducing a new Analytics feature in the Socket dashboard so you can view changes in your organization's and repositories' alerts over time.
eslint-plugin-simple-import-sort
Advanced tools
The eslint-plugin-simple-import-sort package is an ESLint plugin that automatically sorts import statements in your JavaScript and TypeScript files. It helps in maintaining a consistent order of imports, making the codebase easier to read and maintain. It can sort imports alphabetically, group and separate different types of imports, and remove duplicate imports.
Sorting import statements
This feature automatically sorts import statements alphabetically and groups them. After running ESLint with this plugin, the imports would be sorted as follows: import React from 'react'; import z from 'zoo'; import { a, b } from 'alphabet'; import { c as cat, d as dog } from 'animals';
import React from 'react';
import { b, a } from 'alphabet';
import z from 'zoo';
import { d as dog, c as cat } from 'animals';
Grouping and separating imports
This feature groups and separates imports by their origin. Built-in modules, external modules, internal modules, and local modules are grouped together and separated by a blank line. After sorting, the imports would be grouped as follows: import fs from 'fs'; import path from 'path'; import React from 'react'; import myLocalModule from './myLocalModule';
import fs from 'fs';
import path from 'path';
import myLocalModule from './myLocalModule';
import React from 'react';
Removing duplicate imports
This feature detects and removes duplicate import statements. After running ESLint with this plugin, only one import statement will remain: import { a } from 'module';
import { a } from 'module';
import { a } from 'module';
This package provides a set of rules that help enforce a convention in the order of require/import statements. It is more configurable than eslint-plugin-simple-import-sort and includes a variety of other rules to ensure proper imports, prevent misspellings, and manage dependencies.
This is not an ESLint plugin but a standalone tool that sorts imports using various style configurations. It can be used in conjunction with ESLint but requires separate configuration and execution.
This package extends ESLint's autofixing capabilities and can be used to sort imports among other things. However, it is not solely focused on import sorting and requires additional configuration to achieve similar functionality to eslint-plugin-simple-import-sort.
Easy autofixable import sorting.
eslint --fix
– no new toolinggit diff
friendlyrequire
This is for those who use eslint --fix
(autofix) a lot and want to completely forget about sorting imports!
Version 10.0.0 (2023-01-27)
This release might move some imported items with type
around. This is a breaking formatting change (that only affects TypeScript and Flow), but only in the form of that you need to autofix your files.
In previous versions, type
specifiers came first:
import { type B, a } from "a";
export { type B, a } from "a";
Now, all specifiers are sorted alphabetically, regardless of type
:
import { a, type B } from "a";
export { a, type B } from "a";
Motivation:
You might import a class for a type annotation using:
<!-- prettier-ignore -->import {
type MyClass,
coolFunction,
} from "example";
Later, you also start instantiating that class in the same file (new MyClass()
), so you remove type
.
Previously, this resulted in a messy diff due to the class moving:
import {
- type MyClass,
coolFunction,
+ MyClass,
} from "example";
Now, the sorting with the type
keyword would be:
import {
coolFunction,
type MyClass,
} from "example";
Now there’s no reordering diff, just the type
keyword being removed:
import {
coolFunction,
- type MyClass,
+ MyClass,
} from "example";
This is consistent with [“Why sort on from
?”][sort-from].
Thanks to Jake Bailey (@jakebailey) for reporting and suggesting the fix!
FAQs
Easy autofixable import sorting
The npm package eslint-plugin-simple-import-sort receives a total of 1,473,052 weekly downloads. As such, eslint-plugin-simple-import-sort popularity was classified as popular.
We found that eslint-plugin-simple-import-sort demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We're introducing a new Analytics feature in the Socket dashboard so you can view changes in your organization's and repositories' alerts over time.
Security News
A new OpenSSF report uncovers critical gaps in secure software training, with 75% of new developers unfamiliar with secure practices, highlighting urgent educational needs.
Security News
The 2023 Python Developers Survey reveals key trends in packaging, web frameworks, and developer demographics, highlighting a shift toward innovative tools as the Python community diversifies and grows among less experienced developers.