From 2f56861dce859ffa96efcb3a4c4808c3841e0ac6 Mon Sep 17 00:00:00 2001 From: Moreno Feltscher Date: Mon, 9 Dec 2024 10:40:01 +0100 Subject: [PATCH] feat: add configuration for Next.js and export configs using a function (#39) --- README.md | 10 ++++++---- package.json | 1 - src/index.ts | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dcc5835..9775272 100644 --- a/README.md +++ b/README.md @@ -15,16 +15,18 @@ This package offers two different rule sets, one for plain TypeScript applicatio ### Flat Config (`eslint.config.mjs`) ```javascript -import { configs } from '@smartive/eslint-config' +import { config } from '@smartive/eslint-config' // For plain TS applications .. -export default configs.typescript; +export default config('typescript'); // .. or React applications -export default configs.react; +export default config('react'); // .. or Next.js applications -export default configs.nextjs; +// make sure to add `eslint-config-next` +// to your devDependencies +export default config('nextjs'); ``` ### Legacy Config (`.eslintrc`) diff --git a/package.json b/package.json index 0cd7f09..bc15fc9 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,6 @@ "cz-conventional-changelog": "^3.3.0", "esbuild": "0.24.0", "eslint": "^9.15.0", - "eslint-config-next": "^15.0.4", "husky": "^9.1.7", "prettier": "^3.3.3", "typescript": "^5.6.3" diff --git a/src/index.ts b/src/index.ts index 6c02f89..3c1da35 100644 --- a/src/index.ts +++ b/src/index.ts @@ -111,11 +111,27 @@ const flatConfigReact = (includeNextJsConfig = false) => { rules: reactRules }, ); +/** + * @deprecated Use `config(type)` instead + */ export const configs = { typescript: flatConfigTypescript, react: flatConfigReact(), }; +export const config = (type: string) => { + switch (type) { + case 'typescript': + return flatConfigTypescript; + case 'react': + return flatConfigReact(); + case 'nextjs': + return flatConfigReact(true); + default: + throw new Error(`Unknown config type: ${type}`); + } +}; + export const generateLegacyConfig = (react: boolean): Linter.LegacyConfig => ({ rules: rules(react), env: {