Package Exports
- eslint-plugin-command
- eslint-plugin-command/config
Readme
eslint-plugin-command
Support one-off comment-as-command to do code transformation with ESLint.
Use ESLint as a codemod tool, on-demand.
[!IMPORTANT] Experimental, feedbacks are welcome!
Install
npm i eslint-plugin-command -DIn your Flat config:
// eslint.config.mjs
import command from 'eslint-plugin-command/config'
export default [
// ... your other flat config
command(),
]Built-in Commands
to-function
Provide a quick way to convert an arrow function to a standard function declaration.
Trigger with /// to-function comment (triple slashes) one line above the arrow function.
Triggers:
/// to-function/// to-fn/// 2f
/// to-function
const foo = async (msg: string): void => {
console.log(msg)
}Will be converted to (the command comment will also be removed):
async function foo(msg: string): void {
console.log(msg)
}to-arrow
Provide a quick way to convert a standard function declaration to an arrow function.
Triggers:
/// to-arrow/// 2a
/// to-arrow
function foo(msg: string): void {
console.log(msg)
}Will be converted to:
const foo = (msg: string): void => {
console.log(msg)
}keep-sorted
Keep the object keys or array items sorted.
Triggers:
/// keep-sorted// @keep-sorted
/// keep-sorted
const obj = {
b: 2,
a: 1,
c: 3,
}Will be converted to:
/// keep-sorted
const obj = {
a: 1,
b: 2,
c: 3,
}Different from the other commands, the comment will not be removed after transformation to keep the sorting.
Sponsors
License
MIT License © 2023-PRESENT Anthony Fu