eslint-plugin-orderly-functions
v1.1.0
Published
An ESLint plugin to sort exported function declarations alphabetically while respecting dependencies.
Downloads
29
Maintainers
Readme
An ESLint plugin to sort exported function declarations alphabetically while respecting their dependencies.
Installation
You'll first need to install ESLint:
npm install eslint --save-dev
# or
yarn add -D eslint
# or
pnpm i -D eslint
npm install -D eslint-plugin-orderly-functions
# or
yarn add -D eslint-plugin-orderly-functions
# or
pnpm i -D eslint-plugin-orderly-functions
Usage
In your ESLint configuration file (.eslintrc.js
or eslint.config.js
for ESLint v9+), add the plugin and configure the rule.
// eslint.config.js for ESLint v9+ (flat config)
import orderlyFunctions from 'eslint-plugin-orderly-functions';
export default [
{
plugins: {
'orderly-functions': orderlyFunctions,
},
rules: {
'orderly-functions/sort-functions': 'error',
},
},
];
Enabling the Autofixer:
// eslint.config.js
import orderlyFunctions from 'eslint-plugin-orderly-functions';
export default [
{
plugins: {
'orderly-functions': orderlyFunctions,
},
rules: {
'orderly-functions/sort-functions': [
'error',
{
enableFixer: true,
},
],
},
},
];
Note: Enabling the autofixer will reorder your exported functions according to the rule. Use it with caution and ensure you have proper version control and testing in place.
Rule Details
This rule enforces that exported functions are sorted alphabetically while respecting their dependencies.
Options
enableFixer
(boolean, default:false
): Enables the autofixer to automatically reorder functions.
Examples of incorrect code:
export const c = () => {
return a() + b();
};
export const a = () => 'a';
export const b = () => 'b';
Examples of correct code:
export const a = () => 'a';
export const b = () => 'b';
export const c = () => {
return a() + b();
};