Skip to content

Commit

Permalink
doc: Simplified Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bfanger committed Apr 8, 2024
1 parent 35d001f commit ace7293
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,34 @@

![status](https://github.com/bfanger/eslint-plugin-only-warn/actions/workflows/lint-and-test.yml/badge.svg)

## Installation

You'll first need to install [ESLint](http://eslint.org):

```
$ npm i eslint --save-dev
```
Downgrade [ESLint](http://eslint.org) errors to warnings.

Next, install `eslint-plugin-only-warn`:
## Installation

```
$ npm install eslint-plugin-only-warn --save-dev
```sh
npm install --save-dev eslint-plugin-only-warn
```

**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-only-warn` globally.
## Usage

## Usage (Flat Config)
Using [flat config files](https://eslint.org/docs/latest/use/configure/configuration-files):

```js
// eslint.config.js
import "eslint-plugin-only-warn";

export default [
...
```

Getting `SyntaxError: Cannot use import statement outside a module`? Change your _package.json_ to `"type": "module",` or use require:
Or, when the package.json that doesn't have `"type": "module"`:

```js
// eslint.config.js
require("eslint-plugin-only-warn");`
require("eslint-plugin-only-warn");
```

## Usage (Old style ESLint config)

Not using the new flat config from ESLint 9+?
<details>
<summary>ESLint 8.x and earlier</summary>

Add `only-warn` to the plugins section of your `.eslintrc` configuration file:

Expand All @@ -44,17 +39,22 @@ Add `only-warn` to the plugins section of your `.eslintrc` configuration file:
}
```

## Recommendations
</details>

### --max-warnings=0

Add `--max-warnings=0` to the lint script in your package.json.
Add [--max-warnings=0](https://eslint.org/docs/latest/use/command-line-interface#--max-warnings) to the eslint command in package.json

```json
"lint": "eslint --max-warnings=0 ...",
```

This will make eslint cli report an errorcode which can be detected in a git hook or CI pipeline.
Adding the option allows git hooks or CI pipelines to detect failed linting rules.
Because the cli now has a nonzero exitcode when it encountered linting warnings.

### Git integration

Tip: Use [husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/okonet/lint-staged) to prevent committing eslint warnings.
Use [Husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/okonet/lint-staged) to prevent committing code that contain eslint warnings.

# Why only warnings?

Expand Down

0 comments on commit ace7293

Please sign in to comment.