Skip to content

Commit

Permalink
feat: add configuration for Next.js and export configs using a functi…
Browse files Browse the repository at this point in the history
…on (#39)
  • Loading branch information
mfeltscher authored Dec 9, 2024
1 parent ace8d02 commit 2f56861
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 2f56861

Please sign in to comment.