Skip to content

Commit

Permalink
feat: ✨ you can pass additional configs after the 1st argument
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 💥 `overrides` has been renamed to `configs`
  • Loading branch information
jimmy-guzman committed Oct 31, 2024
1 parent b7b7533 commit ea75350
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 36 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,28 @@ export default jimmyDotCodes({

#### Overrides

You can also extend or override the configuration:
You can also extend the configuration:

```js
import jimmyDotCodes from "@jimmy.codes/eslint-config";

export default jimmyDotCodes({
overrides: [
{
rules: {
"prefer-const": "error",
},
},
{
files: ["/**/*.js"],
rules: {
semi: "error",
export default jimmyDotCodes(
{
configs: [
{
files: ["**/*.js"],
rules: {
"prefer-spread": "error",
},
},
],
},
{
rules: {
"prefer-const": "error",
},
],
});
},
);
```

## ❤️ Credits
Expand Down
4 changes: 2 additions & 2 deletions src/configs/commonjs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import globals from "globals";

import { GLOB_CJS } from "../constants";
import { type FlatConfigItem } from "../types";
import { type TypedConfigItem } from "../types";

export const commonjsConfig = () => {
return [
Expand All @@ -12,5 +12,5 @@ export const commonjsConfig = () => {
globals: globals.commonjs,
},
},
] satisfies FlatConfigItem[];
] satisfies TypedConfigItem[];
};
4 changes: 2 additions & 2 deletions src/configs/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import globals from "globals";
import { GLOB_JSX, GLOB_TSX } from "../constants";
import { hasReactQuery } from "../has-dep";
import { reactRules } from "../rules/react";
import { type FlatConfigItem, type ReactOptions } from "../types";
import { type ReactOptions, type TypedConfigItem } from "../types";

const reactConfig = (
{ utilities = [] }: ReactOptions = {},
Expand Down Expand Up @@ -62,7 +62,7 @@ const reactConfig = (
},
]
: []),
] satisfies FlatConfigItem[];
] satisfies TypedConfigItem[];
};

export default reactConfig;
4 changes: 2 additions & 2 deletions src/configs/testing-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as jestDom from "eslint-plugin-jest-dom";
import testingLibrary from "eslint-plugin-testing-library";

import { GLOB_E2E, GLOB_TESTS } from "../constants";
import { type FlatConfigItem } from "../types";
import { type TypedConfigItem } from "../types";

const testingLibraryConfig = () => {
return [
Expand All @@ -25,7 +25,7 @@ const testingLibraryConfig = () => {
"testing-library/prefer-screen-queries": "off",
},
},
] satisfies FlatConfigItem[];
] satisfies TypedConfigItem[];
};

export default testingLibraryConfig;
25 changes: 15 additions & 10 deletions src/factory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type Linter } from "eslint";
import eslintConfigPrettier from "eslint-config-prettier";

import { astroConfig } from "./configs/astro";
Expand All @@ -9,21 +10,24 @@ import typescriptConfig from "./configs/typescript";
import { GLOB_IGNORES } from "./constants";
import { hasAstro, hasReact, hasTesting, hasTypescript } from "./has-dep";
import { baseRules } from "./rules/base";
import { type Options } from "./types";
import { type Options, type TypedConfigItem } from "./types";
import {
getReactOptions,
getTestingOptions,
getTypescriptOptions,
} from "./utils";

export const jimmyDotCodes = ({
typescript = false,
react = false,
testing = false,
astro = false,
overrides = [],
autoDetect = false,
}: Options = {}) => {
export const jimmyDotCodes = (
{
typescript = false,
react = false,
testing = false,
astro = false,
autoDetect = false,
configs = [],
}: Options = {},
...moreConfigs: TypedConfigItem[] | Linter.Config[]
) => {
const isTypescriptEnabled = typescript || (autoDetect && hasTypescript());
const isReactEnabled = react || (autoDetect && hasReact());
const isTestingEnabled = testing || (autoDetect && hasTesting());
Expand All @@ -45,6 +49,7 @@ export const jimmyDotCodes = ({
{
ignores: GLOB_IGNORES,
},
...overrides,
...configs,
...moreConfigs,
];
};
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { jimmyDotCodes } from "./factory";

export type * from "./types";

export default jimmyDotCodes;
18 changes: 12 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ export interface ReactOptions {
utilities?: ReactUtilities[];
}

export type FlatConfigItem = Omit<Linter.FlatConfig, "plugins"> & {
name?: string;
export type TypedConfigItem = Omit<
Linter.Config<Linter.RulesRecord & Rules>,
"plugins"
> & {
/**
* An object containing a name-value mapping of plugin names to plugin objects. When `files` is specified, these plugins are only available to the matching files.
*
* @see [Using plugins in your configuration](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#using-plugins-in-your-configuration)
*/
plugins?: Record<string, unknown>;
rules?: Linter.RulesRecord & Rules;
};

export interface Options {
Expand All @@ -59,7 +65,7 @@ export interface Options {
* @default false
*/
/**
* Are testing rules are enabled?
* Are testing rules are enabled?
* @default false
*/
testing?: boolean | TestingOptions;
Expand All @@ -69,10 +75,10 @@ export interface Options {
*/
astro?: boolean;
/**
* Additional flat configs to either extend or overrides configurations
* Additional configs to either extend or overrides configurations
* @default []
*/
overrides?: FlatConfigItem[];
configs?: TypedConfigItem[] | Linter.Config[];
/**
* Is auto detection enabled?
* @default false
Expand Down

0 comments on commit ea75350

Please sign in to comment.