Skip to content

Commit

Permalink
docs: readme
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 3, 2024
1 parent 82b85bc commit 90bc041
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,53 @@

Comment-as-command for one-off codemod with ESLint.

## Introduction

**ESLint Plugin Command** is a special kind of ESLint plugin, that by default, **does nothing**. Instead of checking for code quality, it serves as a micro-codemod tool triggers by special comments on-demand, resuse the infrastructure of ESLint.

For example, one of the built-in commands, `/// to-function` allows you to convert a single arrow function expression to a function declaration.

<!-- eslint-skip -->

```ts
/// to-function
const foo = async <T>(msg: T): void => {
console.log(msg)
}
```

Will be transformed to this when you hit save with your editor or run `eslint . --fix`. After executing the command, the comment will also be removed along with the transformation:

```ts
async function foo<T>(msg: T): void {
console.log(msg)
}
```

One more example that `/// to-promis-all` converts a sequence of `await` expressions to `await Promise.all()`:

<!-- eslint-skip -->

```ts
/// to-promise-all
const foo = await bar().then
const { get } = await import('lodash-es')
```

Will be transformed to:

```ts
const [
foo,
{ get },
] = await Promise.all([
bar(),
import('lodash-es'),
] as const)
```

Refer to the [documentation](https://eslint-plugin-command.antfu.me/) for more details.

## Sponsors

<p align="center">
Expand Down

0 comments on commit 90bc041

Please sign in to comment.