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 Dec 17, 2023
1 parent af9dc42 commit 1812ab9
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 70 deletions.
90 changes: 31 additions & 59 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.22.2",
"caniuse-lite": "^1.0.30001570",
"find-up": "^5.0.0",
"globals": "^13.24.0",
"lodash.memoize": "^4.1.2",
"semver": "^7.5.4"
},
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: 29 additions & 5 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, Rule } from "eslint";

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

export const rules = {
compat,
} satisfies Record<string, Rule.RuleModule>;

const plugin = {
meta: {
name: pkg.name,
version: pkg.version,
},
configs: {},
rules,
} satisfies ESLint.Plugin;

export const configs = {
recommended,
};
recommended: {
plugins: ["compat"],
...recommended.legacy,
},
"flat/recommended": {
plugins: {
compat: plugin,
},
...recommended.flat,
},
} satisfies ESLint.Plugin["configs"];

plugin.configs = configs;

// Kept for backwards compatibility
export const config = configs;

export const rules = {
compat,
};
export default plugin;
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 1812ab9

Please sign in to comment.