Skip to content

Commit

Permalink
feat: support flat config (#609)
Browse files Browse the repository at this point in the history
* chore: bump deps

* test: update snapshots

* chore: babel-eslint to @babel/eslint-parser

* feat: support flat config

Resolves: #603

* test: add typing tests for flat configs

* docs: add flat config example to README

* chore: deprecate named export

* feat: provide type declaration

* 5.0.0-0

* fix: add esm/cjs support

* 5.0.0-1

* 5.0.0-2

---------

Co-authored-by: Amila Welihinda <amilajack@gmail.com>
  • Loading branch information
nix6839 and amilajack committed May 22, 2024
1 parent 6ffb8ad commit f51dad7
Show file tree
Hide file tree
Showing 13 changed files with 3,317 additions and 4,655 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ npm install eslint-plugin-compat

### 2. Update ESLint Config

#### `.eslintrc.json`
#### New Config (`eslint.config.mjs`)

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

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

#### Legacy Config (`.eslintrc.json`)

```jsonc
{
Expand Down
4,963 changes: 2,303 additions & 2,660 deletions package-lock.json

Large diffs are not rendered by default.

78 changes: 47 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-compat",
"version": "4.2.0",
"version": "5.0.0-2",
"description": "Lint browser compatibility of API used",
"keywords": [
"eslint",
Expand All @@ -25,13 +25,26 @@
"Amila Welihinda <amilajack@gmail.com> (https://github.com/amilajack)",
"John Tran <jptran318@gmail.com> (https://github.com/jooohhn)"
],
"main": "lib/index.js",
"main": "./lib/cjs/src/index.js",
"types": "./lib/cjs/src/index.d.ts",
"exports": {
".": {
"import": {
"types": "./lib/esm//src/index.d.mts",
"default": "./lib/esm/src/index.js"
},
"require": {
"types": "./lib/cjs/src/index.d.ts",
"default": "./lib/cjs/src/index.js"
}
}
},
"files": [
"lib"
],
"scripts": {
"benchmarks": "ts-node-transpile-only test/benchmarks.ts",
"build": "rm -rf lib && tsc --project tsconfig.build.json",
"build": "rm -rf lib && tsc --project tsconfig.build.json && tsc --project tsconfig.esm.json",
"lint": "eslint --ignore-path .gitignore --ext .js,.ts .",
"spec": "jest --testPathIgnorePatterns test/e2e-repo.spec.ts /benchmarks-tmp",
"spec:e2e": "jest test/e2e-repo.spec.ts",
Expand Down Expand Up @@ -73,45 +86,48 @@
]
},
"dependencies": {
"@mdn/browser-compat-data": "^5.3.16",
"@mdn/browser-compat-data": "^5.5.19",
"ast-metadata-inferer": "^0.8.0",
"browserslist": "^4.21.10",
"caniuse-lite": "^1.0.30001534",
"browserslist": "^4.23.0",
"caniuse-lite": "^1.0.30001605",
"find-up": "^5.0.0",
"globals": "^13.24.0",
"lodash.memoize": "^4.1.2",
"semver": "^7.5.4"
"semver": "^7.6.0"
},
"devDependencies": {
"@babel/core": "^7.24.3",
"@babel/eslint-parser": "^7.24.1",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@tsconfig/node16": "^16.1.1",
"@types/benchmark": "^2.1.3",
"@types/browserslist": "^4.15.0",
"@types/caniuse-lite": "^1.0.2",
"@types/eslint": "^8.44.2",
"@types/jest": "^29.5.5",
"@types/lodash.memoize": "^4.1.7",
"@types/semver": "7.5.2",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"babel-eslint": "^10.1.0",
"@tsconfig/node16": "^16.1.3",
"@types/benchmark": "^2.1.5",
"@types/caniuse-lite": "^1.0.5",
"@types/eslint": "^8.56.7",
"@types/jest": "^29.5.12",
"@types/lodash.memoize": "^4.1.9",
"@types/semver": "7.5.8",
"@typescript-eslint/eslint-plugin": "^7.5.0",
"@typescript-eslint/parser": "^7.5.0",
"benchmark": "^2.1.4",
"browserslist-config-erb": "^0.0.3",
"electron": "^26.x.x",
"eslint": "^8.49.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"electron": "^29.x.x",
"eslint": "^8.57.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-config-bliss-typescript": "^6.0.2",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-eslint-plugin": "^5.1.1",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-eslint-plugin": "^5.5.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"expect-type": "^0.19.0",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"semantic-release": "^22.0.0",
"simple-git": "^3.19.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"prettier": "^3.2.5",
"semantic-release": "^22.0.12",
"simple-git": "^3.24.0",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.4.3",
"typescript-eslint": "^7.5.0"
},
"peerDependencies": {
"eslint": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
Expand Down
33 changes: 28 additions & 5 deletions src/config/recommended.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
// Reconmmended configs for this plugin
export default {
plugins: ["compat"],
env: {
browser: true,
/**
* @file Recommended configs for this plugin
*/

import globals from "globals";
import type { ESLint, Linter } from "eslint";

// Flat config: https://eslint.org/docs/latest/use/configure/configuration-files-new
const flat = {
languageOptions: {
globals: {
...globals.browser,
},
},
rules: {
"compat/compat": "error",
},
} satisfies Linter.FlatConfig;

// eslintrc config: https://eslint.org/docs/latest/use/configure/configuration-files
const legacy = {
env: {
browser: true,
},
rules: flat.rules,
} satisfies ESLint.ConfigData;

const recommended = {
flat,
legacy,
};

export default recommended;
37 changes: 31 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// Requirements
//------------------------------------------------------------------------------
import recommended from "./config/recommended";
import pkg from "../package.json";
import type { Linter } from "eslint";

//------------------------------------------------------------------------------
// Plugin Definition
Expand All @@ -15,13 +17,36 @@ import recommended from "./config/recommended";
// import all rules in lib/rules
import compat from "./rules/compat";

export const configs = {
recommended,
const rules = {
compat,
};

// Kept for backwards compatibility
export const config = configs;
const plugin = {
meta: {
name: pkg.name,
version: pkg.version,
},
configs: {},
rules,
};

export const rules = {
compat,
const configs = {
"flat/recommended": {
plugins: { compat: plugin },
...recommended.flat,
} as Linter.FlatConfig,
recommended: {
plugins: ["compat"],
...recommended.legacy,
} as Linter.Config,
};
plugin.configs = configs;

export = {
...(plugin as typeof plugin & { configs: typeof configs }),
// TODO: Remove this in next major release
/**
* @deprecated Use `.configs` instead. This will be removed in the next major release.
*/
config: configs,
};
2 changes: 1 addition & 1 deletion src/rules/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,4 @@ export default {
},
};
},
};
} as Rule.RuleModule;
Loading

0 comments on commit f51dad7

Please sign in to comment.