Skip to content

Commit

Permalink
feat: eslint 9 support (#627)
Browse files Browse the repository at this point in the history
* feat!: eslint 9 support

Requires Node 18 (due to globals update)

* chore: update deps and devDeps.
  • Loading branch information
brettz9 authored Jul 11, 2024
1 parent eaaad6a commit a2db2d6
Show file tree
Hide file tree
Showing 16 changed files with 2,620 additions and 6,509 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github
CHANGELOG.md
CODE_OF_CONDUCT.md
28 changes: 13 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ npm install eslint-plugin-compat
#### New Config (`eslint.config.mjs`)

```js
import compat from "eslint-plugin-compat"
import compat from "eslint-plugin-compat";

export default [
compat.configs['flat/recommended']
];
export default [compat.configs["flat/recommended"]];
```

#### Legacy Config (`.eslintrc.json`)
Expand All @@ -38,8 +36,8 @@ export default [
"plugins": ["compat"],
"extends": ["plugin:compat/recommended"],
"env": {
"browser": true
}
"browser": true,
},
// ...
}
```
Expand All @@ -53,7 +51,7 @@ Browser targets are configured using [browserslist](https://github.com/browsersl
```jsonc
{
// ...
"browserslist": ["defaults"]
"browserslist": ["defaults"],
}
```

Expand All @@ -77,9 +75,9 @@ Add polyfills to the settings section of your eslint config. Append the name of
// Example of API with no property (i.e. a function)
"fetch",
// Example of instance method, must add `.prototype.`
"Array.prototype.push"
]
}
"Array.prototype.push",
],
},
}
```

Expand All @@ -91,8 +89,8 @@ This plugin also supports linting the compatibility of ES APIs in addition to We
{
// ...
"settings": {
"lintAllEsApis": true
}
"lintAllEsApis": true,
},
}
```

Expand Down Expand Up @@ -123,9 +121,9 @@ Target `modern` browserslist environment:
{
"settings": {
"browserslistOpts": {
"env": "modern"
}
}
"env": "modern",
},
},
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/rules/compat.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ This rule enables linting your code for browser compatibility.

```js
// Targeting IE
fetch('https://exmaple.com');
fetch("https://exmaple.com");
```

## This will not be reported

```js
// Using default browser targets
fetch('https://exmaple.com');
fetch("https://exmaple.com");
```
50 changes: 50 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import path from "node:path";
import { fileURLToPath } from "node:url";

import { includeIgnoreFile } from "@eslint/compat";
import eslint from "@eslint/js";
import eslintPlugin from "eslint-plugin-eslint-plugin";
import eslintConfigPrettier from "eslint-config-prettier";
import tseslint from "typescript-eslint";
import globals from "globals";
import compat from "./lib/esm/src/index.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const gitignorePath = path.resolve(__dirname, ".gitignore");

export default [
includeIgnoreFile(gitignorePath),
eslint.configs.recommended,
...tseslint.configs.recommended,
eslintPlugin.configs["flat/recommended"],
compat.configs["flat/recommended"],
eslintConfigPrettier,
{
files: ["**/*.ts", "**/*.js", "**/*.mjs"],
rules: {
"no-template-curly-in-string": ["error"],
"no-console": ["warn"],
},
languageOptions: {
globals: {
...globals.jest,
...globals.node,
},
},
},
];

/*
parserOptions: {
project: './tsconfig.json'
},
"extends": [
"airbnb-typescript/base",
"plugin:import/typescript",
],
"rules": {
"import/extensions": "off",
"import/no-extraneous-dependencies": "off"
},
*/
Loading

0 comments on commit a2db2d6

Please sign in to comment.