> For the complete documentation index, see [llms.txt](https://notes.lirenxn.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.lirenxn.com/featured/deep-dive-eslint/eslint-with-fix.md).

# eslint with fix

pitfall with CLIEngine()

### **eslint pitfall in custom CLI tool:**

In `cli.js`, passing default fix as **`null`** to eslint.

```javascript
yargs.command(
    "eslint",
    "run the linter",
    yargs => {
      yargs
        .option("fix", {
          describe: "enable auto fixing option in eslint",
// ------***** BELOW *****---------
          default: null 
// ------***** ABOVE *****---------
        });
    },
    argv => {
      const eslint = require("./eslint").default;

      eslint(argv);
    }
  )
```

Consuming `fix` directly in `CLIEngine`

```javascript
const eslintCLI = new CLIEngine({
      useEslintrc,
      ...eslintArgs,
      ...( !useEslintrc ? { configFile: DEFAULT_ESLINTRC } : {}),
      fix
    });
```

&#x20;The following code, will be transpiled by babel to

```javascript
// ...
{ fix: fix }
// ...
```

**Key bug :** in eslint `CLIEngine`, `null` will be treated as `true` and the fixed file could be listed on the fly. The check in eslint `fixer` is

```javascript
if(shouldFix === false){
	// DO NOT FIX
}
// APPLY FIX
```

#### Programmatically linting (in custom cli)

`eslint` have a `CliEngine` which loads the cli options. `--print-config` will trigger `engine.getConfigForFile(PATH_TO_SINGLE_FILE)` to load the config for single file. Cos the config can vary for different type of files, you need to specify single file here.

**vscode eslint extension**

> **The extension uses the ESLint library installed in the opened workspace folder. If the folder doesn't provide one the extension looks for a global install version.**
