Skip to content

Commit

Permalink
feat: support flat config
Browse files Browse the repository at this point in the history
Resolves: amilajack#603
  • Loading branch information
nix6839 committed Mar 11, 2024
1 parent cfdea10 commit 4f2a6eb
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 75 deletions.
98 changes: 35 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"browserslist": "^4.23.0",
"caniuse-lite": "^1.0.30001594",
"find-up": "^5.0.0",
"globals": "^13.24.0",
"lodash.memoize": "^4.1.2",
"semver": "^7.6.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;
34 changes: 28 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 { ESLint, Linter } from "eslint";

//------------------------------------------------------------------------------
// Plugin Definition
Expand All @@ -15,13 +17,33 @@ 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: ESLint.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 }),
// Kept for backwards compatibility
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;
3 changes: 3 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
},
"include": ["src"]
}

0 comments on commit 4f2a6eb

Please sign in to comment.