Skip to content

Commit

Permalink
feat(usage/linter): add auto fix page (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac authored Sep 22, 2024
1 parent f998505 commit b0a06fb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .vitepress/config/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export const enConfig = defineLocaleConfig("root", {
text: "Rules",
link: "/docs/guide/usage/linter/rules",
},
{
text: "Automatic Fixes",
link: "/docs/guide/usage/linter/automatic-fixes",
},
],
},
{ text: "Parser", link: "/docs/guide/usage/parser" },
Expand Down
54 changes: 54 additions & 0 deletions src/docs/guide/usage/linter/automatic-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
outline: [2, 3]
editLink: false
---

# Automatic Fixes

In some cases, Oxlint is able to automatically fix lint violations in your code.
There are two categories of automatic fixes:

- **Fixes**: These are changes that will not change your program's behavior. It
is generally safe to run them in a pre-lint hook.
- **Suggestions**: Changes that may change your program's behavior or make a
change you may not want (e.g. removing `console.log`s). These should be
reviewed before being committed to your codebase.

```sh
oxlint --fix # Safe fixes only
oxlint --fix-suggestions # Safe suggestions only
oxlint --fix --fix-suggestions # Safe fixes and suggestions
```

You can find which rules are fixable from the [rules page](./rules.md).

## Dangerous Fixes and Suggestions

Some fixes and suggestions are considered dangerous. Being more aggressive in
nature, **these may produce invalid code and/or change the behavior of your
program**. These are disabled by default and can be enabled with the
`--fix-dangerous` flag. You should review each change carefully before
committing it to your codebase.

:::warning
If you are using git, you should stage your changes before running any of the
commands below using `git add -A`.
:::

```sh
# Safe and dangerous fixes only
oxlint --fix-dangerous

# Safe and dangerous suggestions only
oxlint --fix-suggestions --fix-dangerous

# Applies all possible fixes and suggestions
oxlint --fix --fix-suggestions --fix-dangerous
```

## Pending Fixes

You may notice that some rules have a 🚧 next to their name. This indicate that
they could be automatically fixed, but they are missing an auto-fixer
implementation. You can help improve Oxlint by contributing an auto fixer for
rules that need them.

2 comments on commit b0a06fb

@orta
Copy link

@orta orta commented on b0a06fb Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this doc is targeting an unreleased version, but:

❯ yarn oxlint --fix --fix-suggestions --fix-dangerous
Error: no such flag: --fix-dangerous, did you mean --fix-dangerously?
❯ yarn why oxlint
└─ puzzmo-monorepo@workspace:.
   └─ oxlint@npm:0.9.6 (via npm:^0.9.6)

@Boshen
Copy link
Member

@Boshen Boshen commented on b0a06fb Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for noticing the erratum, it should be --fix-dangerously, which can be obtained from --help. I'll correct the doc.

Please sign in to comment.