ESLint plugin to sort loadable imports
npm install eslint-plugin-loadable-importsAn ESLint plugin to automatically sort loadable imports alphabetically in your JavaScript files.
You can install this plugin using either npm or yarn:
``bashnpm
npm install eslint-plugin-loadable-imports --save-dev
Usage
After installing the plugin, you need to add it to your ESLint configuration file (.eslintrc.js or equivalent).$3
Add loadable-imports to the plugins array and the sort-loadable-imports rule to the rules section:`js
module.exports = {
plugins: [
'loadable-imports',
],
rules: {
'loadable-imports/sort-loadable-imports': 'error', // or warn
},
};
`$3
Before running ESLint:`js
const SecondComponent = loadable(() => import('@/components/SecondComponent'));
const FirstComponent = loadable(() => import('@/components/FirstComponent'));
const ThirdComponent = loadable(() => import('@/components/ThirdComponent'));
`After applying the rule (sorted alphabetically):
`js
const FirstComponent = loadable(() => import('@/components/FirstComponent'));
const SecondComponent = loadable(() => import('@/components/SecondComponent'));
const ThirdComponent = loadable(() => import('@/components/ThirdComponent'));
``Currently, sort-loadable-imports does not have any options. It simply sorts the imports wrapped in loadable() alphabetically based on the variable names.
You can use ESLint's --fix option to automatically sort the imports.