Skip to content

Commit

Permalink
🚚 rename flat config export to flat
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineKM committed Dec 10, 2024
1 parent 5753c08 commit 96837ad
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 68 deletions.
14 changes: 3 additions & 11 deletions packages/eslint-config-antoine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ npm install --save-dev eslint typescript prettier eslint-config-antoine
### ESLint v9 (`eslint.config.js`)

```js
import { flatConfig } from "eslint-config-antoine";
import { flat } from "eslint-config-antoine";

export default [
...flatConfig,
...flat,
// Your additional rules here...
];
```
Expand All @@ -35,12 +35,4 @@ module.exports = {
- 🎯 TypeScript and React best practices
- 🎨 Prettier integration
- ⚡️ Zero config setup
- 🔄 Auto-detects React version

## What's included

- TypeScript support via `@typescript-eslint`
- React rules and best practices
- Prettier formatting rules
- Modern JavaScript features (ES2022)
- Browser and Node.js environments
- 🔄 Auto-detects React version
15 changes: 8 additions & 7 deletions packages/eslint-config-antoine/__tests__/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import eslintrcConfig, { flatConfig } from "../src";
const config = require("../src");
import { flat } from "../src";

interface FlatESLintConfig {
files?: string[];
Expand Down Expand Up @@ -26,7 +27,7 @@ interface FlatESLintConfig {

describe("ESLint V8 Configuration (eslintrc)", () => {
test("has valid ecmaVersion", () => {
expect(eslintrcConfig.parserOptions?.ecmaVersion).toBe(2022);
expect(config.parserOptions?.ecmaVersion).toBe(2022);
});

test("extends standard configs", () => {
Expand All @@ -36,25 +37,25 @@ describe("ESLint V8 Configuration (eslintrc)", () => {
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
];
expect(eslintrcConfig.extends).toEqual(extendsList);
expect(config.extends).toEqual(extendsList);
});

test("has TypeScript parser configuration", () => {
expect(eslintrcConfig.parser).toBe("@typescript-eslint/parser");
expect(config.parser).toBe("@typescript-eslint/parser");
});

test("has all required plugins", () => {
const requiredPlugins = ["react", "@typescript-eslint"];
expect(eslintrcConfig.plugins).toEqual(expect.arrayContaining(requiredPlugins));
expect(config.plugins).toEqual(expect.arrayContaining(requiredPlugins));
});

test("has react settings", () => {
expect(eslintrcConfig.settings?.react?.version).toBe("detect");
expect(config.settings?.react?.version).toBe("detect");
});
});

describe("ESLint V9 Configuration (flat config)", () => {
const configs = flatConfig as FlatESLintConfig[];
const configs = flat as FlatESLintConfig[];

test("includes base configurations", () => {
expect(configs.length).toBeGreaterThan(1);
Expand Down
103 changes: 53 additions & 50 deletions packages/eslint-config-antoine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,56 @@ import reactPlugin from "eslint-plugin-react";
import typescriptPlugin from "@typescript-eslint/eslint-plugin";
import typescriptParser from "@typescript-eslint/parser";

export const flatConfig = [
js.configs.recommended,
// ESLint v8 configuration (main export)
const config: Linter.Config = {
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
],
env: {
browser: true,
node: true,
es2022: true,
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2022,
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
plugins: ["react", "@typescript-eslint"],
settings: {
react: {
version: "detect",
},
},
rules: {
"react/jsx-filename-extension": ["warn", { extensions: [".tsx", ".ts"] }],
"react/jsx-props-no-spreading": "off",
"react/react-in-jsx-scope": "off",
"react/jsx-indent-props": ["error", 2],
"react/jsx-curly-brace-presence": ["error", { props: "always", children: "always" }],
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": [
"error",
{
vars: "all",
varsIgnorePattern: "^_",
args: "after-used",
argsIgnorePattern: "^_",
ignoreRestSiblings: false,
},
],
},
};

// ESLint v9 flat configuration (named export)
export const flat = [
js.configs.recommended,
{
linterOptions: {
reportUnusedDisableDirectives: "warn",
Expand All @@ -28,8 +75,6 @@ export const flatConfig = [
},
},
},

// Config TypeScript/React
{
files: ["**/*.{ts,tsx}"],
plugins: {
Expand All @@ -42,7 +87,6 @@ export const flatConfig = [
},
},
rules: {
// React rules
"react/jsx-filename-extension": ["warn", { extensions: [".tsx", ".ts"] }],
"react/jsx-props-no-spreading": "off",
"react/react-in-jsx-scope": "off",
Expand All @@ -51,8 +95,6 @@ export const flatConfig = [
"error",
{ props: "always", children: "always" },
],

// TypeScript rules
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": [
"error",
Expand All @@ -66,49 +108,10 @@ export const flatConfig = [
],
},
},

prettierConfig,
];

const eslintrcConfig: Linter.Config = {
extends: ["eslint:recommended", "plugin:react/recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
env: {
browser: true,
node: true,
es2022: true,
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2022,
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
plugins: ["react", "@typescript-eslint"],
settings: {
react: {
version: "detect",
},
},
rules: {
"react/jsx-filename-extension": ["warn", { extensions: [".tsx", ".ts"] }],
"react/jsx-props-no-spreading": "off",
"react/react-in-jsx-scope": "off",
"react/jsx-indent-props": ["error", 2],
"react/jsx-curly-brace-presence": ["error", { props: "always", children: "always" }],
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": [
"error",
{
vars: "all",
varsIgnorePattern: "^_",
args: "after-used",
argsIgnorePattern: "^_",
ignoreRestSiblings: false,
},
],
},
};

export default eslintrcConfig;
// Export v8 config as module.exports
module.exports = config;
// Also expose the v9 config
module.exports.flat = flat;

0 comments on commit 96837ad

Please sign in to comment.