From 5f4c79568d38a72c051008acc68bd35ce0e09e15 Mon Sep 17 00:00:00 2001 From: jimmy-guzman Date: Thu, 31 Oct 2024 07:47:09 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20enable=20auto=20detection?= =?UTF-8?q?=20by=20default?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: 💥 `autoDetect` is now `true` by default --- README.md | 18 +++++++++--------- eslint.config.ts | 2 +- scripts/typegen.ts | 2 +- src/configs/react.spec.ts | 4 +++- src/configs/react.ts | 2 +- src/configs/testing.spec.ts | 4 ++-- src/configs/testing.ts | 2 +- src/factory.spec.ts | 21 +++++++++++++++------ src/factory.ts | 2 +- src/types.ts | 12 ++++++------ 10 files changed, 40 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index e474046..0558109 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,6 @@ > 🔍 another opinionated [eslint](https://eslint.org) config -_This is an evolution of [eslint-config-jimmy-guzman](https://github.com/jimmy-guzman/eslint-config-jimmy-guzman)_ - ## 🛠️ Usage _For a better experience, make sure to use [@jimmy.codes/prettier-config](https://github.com/jimmy-guzman/prettier-config) as well_ @@ -42,6 +40,8 @@ And if you're using [VS Code](https://code.visualstudio.com), make sure to enabl ### 🔧 Configuration +**By default all rules are enabled based on the project's dependencies.** + This package contains rules that can be enabled or disabled as follows: ```js @@ -49,34 +49,34 @@ import jimmyDotCodes from "@jimmy.codes/eslint-config"; export default jimmyDotCodes({ /** - * Are TypeScript rules are enabled? + * Are TypeScript rules enabled? * @default false */ typescript: true, /** - * Are React rules are enabled? + * Are React rules enabled? * @default false */ react: true, /** - * Are Astro rules are enabled? + * Are Astro rules enabled? * @default false */ astro: true, /** - * Are testing rules are enabled? + * Are testing rules enabled? * @default false */ testing: true, }); ``` -Or you can enable auto detection to enable rules based on a project's dependencies +Or you can turn off auto detection to enable rules based on a project's dependencies ```js import jimmyDotCodes from "@jimmy.codes/eslint-config"; -export default jimmyDotCodes({ autoDetect: true }); +export default jimmyDotCodes({ autoDetect: false }); ``` #### TypeScript @@ -122,7 +122,7 @@ export default jimmyDotCodes({ }); ``` -#### Overrides +#### Extending the Configuration You can also extend the configuration: diff --git a/eslint.config.ts b/eslint.config.ts index 2d2a0df..aa79555 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -1,3 +1,3 @@ import jimmyDotCodes from "./src"; -export default jimmyDotCodes({ autoDetect: true }); +export default jimmyDotCodes(); diff --git a/scripts/typegen.ts b/scripts/typegen.ts index ce09087..48483bb 100644 --- a/scripts/typegen.ts +++ b/scripts/typegen.ts @@ -15,7 +15,7 @@ const ruleDts = await flatConfigsToRulesDTS( }, }, // @ts-expect-error TODO: config types don't seem to match - ...config({ autoDetect: true }), + ...config(), ], { includeAugmentation: false, diff --git a/src/configs/react.spec.ts b/src/configs/react.spec.ts index 2d0d022..fb7a5cb 100644 --- a/src/configs/react.spec.ts +++ b/src/configs/react.spec.ts @@ -2,7 +2,9 @@ import reactConfig from "./react"; describe("reactConfig", () => { it("should create config w/ @tanstack/query rules", () => { - expect(reactConfig({ utilities: ["@tanstack/query"] })).toStrictEqual( + expect( + reactConfig({ utilities: ["@tanstack/query"] }, false), + ).toStrictEqual( expect.arrayContaining([ expect.objectContaining({ name: "jimmy.codes/react/query", diff --git a/src/configs/react.ts b/src/configs/react.ts index 4f2ba4a..432abc7 100644 --- a/src/configs/react.ts +++ b/src/configs/react.ts @@ -13,7 +13,7 @@ import { type ReactOptions, type TypedConfigItem } from "../types"; const reactConfig = ( { utilities = [] }: ReactOptions = {}, - autoDetect = false, + autoDetect = true, ) => { const includeReactQuery = utilities.includes("@tanstack/query") || (autoDetect && hasReactQuery()); diff --git a/src/configs/testing.spec.ts b/src/configs/testing.spec.ts index 38239ad..9ff8e70 100644 --- a/src/configs/testing.spec.ts +++ b/src/configs/testing.spec.ts @@ -3,7 +3,7 @@ import testingConfig from "./testing"; describe("testingConfig", () => { it("should create default config w/ vitest overrides", () => { - const [, vitest] = testingConfig(); + const [, vitest] = testingConfig({}, false); expect(vitest?.rules).toStrictEqual( expect.objectContaining({ @@ -19,7 +19,7 @@ describe("testingConfig", () => { }); it("should create default config w/o vitest overrides", () => { - const [, jest] = testingConfig({ framework: "jest" }); + const [, jest] = testingConfig({ framework: "jest" }, false); expect(jest?.rules).toStrictEqual( expect.not.objectContaining({ diff --git a/src/configs/testing.ts b/src/configs/testing.ts index b10c23e..85ed061 100644 --- a/src/configs/testing.ts +++ b/src/configs/testing.ts @@ -8,7 +8,7 @@ import testingLibraryConfig from "./testing-library"; const testingConfig = ( { framework = "vitest", utilities }: TestingOptions = {}, - autoDetect = false, + autoDetect = true, ) => { const isVitest = autoDetect ? hasVitest() : framework === "vitest"; const isJest = framework === "jest" || (autoDetect && hasJest()); diff --git a/src/factory.spec.ts b/src/factory.spec.ts index 9ca570e..82cdabb 100644 --- a/src/factory.spec.ts +++ b/src/factory.spec.ts @@ -6,7 +6,9 @@ vi.mock("local-pkg"); describe("jimmyDotCodes", () => { it("should create configuration w/ typescript", () => { - expect(jimmyDotCodes({ typescript: true })).toStrictEqual( + expect( + jimmyDotCodes({ typescript: true, autoDetect: false }), + ).toStrictEqual( expect.arrayContaining([ expect.objectContaining({ name: "jimmy.codes/typescript" }), expect.objectContaining({ name: "jimmy.codes/imports/typescript" }), @@ -15,7 +17,7 @@ describe("jimmyDotCodes", () => { }); it("should create configuration w/ react", () => { - expect(jimmyDotCodes({ react: true })).toStrictEqual( + expect(jimmyDotCodes({ react: true, autoDetect: false })).toStrictEqual( expect.arrayContaining([ expect.objectContaining({ name: "jimmy.codes/react" }), ]), @@ -24,7 +26,10 @@ describe("jimmyDotCodes", () => { it("should create configuration w/ react & @tanstack/query", () => { expect( - jimmyDotCodes({ react: { utilities: ["@tanstack/query"] } }), + jimmyDotCodes({ + react: { utilities: ["@tanstack/query"] }, + autoDetect: false, + }), ).toStrictEqual( expect.arrayContaining([ expect.objectContaining({ name: "jimmy.codes/react" }), @@ -34,7 +39,9 @@ describe("jimmyDotCodes", () => { }); it("should create configuration w/ jest", () => { - expect(jimmyDotCodes({ testing: { framework: "jest" } })).toStrictEqual( + expect( + jimmyDotCodes({ testing: { framework: "jest" }, autoDetect: false }), + ).toStrictEqual( expect.arrayContaining([ expect.objectContaining({ name: "jimmy.codes/testing" }), expect.objectContaining({ name: "jimmy.codes/testing/disabled" }), @@ -45,7 +52,7 @@ describe("jimmyDotCodes", () => { }); it("should create configuration w/ vitest", () => { - expect(jimmyDotCodes({ testing: true })).toStrictEqual( + expect(jimmyDotCodes({ testing: true, autoDetect: false })).toStrictEqual( expect.arrayContaining([ expect.objectContaining({ name: "jimmy.codes/testing" }), expect.objectContaining({ name: "jimmy.codes/testing/disabled" }), @@ -60,6 +67,7 @@ describe("jimmyDotCodes", () => { jimmyDotCodes({ react: true, testing: { framework: "jest", utilities: ["testing-library"] }, + autoDetect: false, }), ).toStrictEqual( expect.arrayContaining([ @@ -82,6 +90,7 @@ describe("jimmyDotCodes", () => { jimmyDotCodes({ react: true, testing: { utilities: ["testing-library"] }, + autoDetect: false, }), ).toStrictEqual( expect.arrayContaining([ @@ -100,7 +109,7 @@ describe("jimmyDotCodes", () => { }); it("should create configuration w/ astro", () => { - expect(jimmyDotCodes({ astro: true })).toStrictEqual( + expect(jimmyDotCodes({ astro: true, autoDetect: false })).toStrictEqual( expect.arrayContaining([ expect.objectContaining({ name: "jimmy.codes/astro", diff --git a/src/factory.ts b/src/factory.ts index c261b4b..a8ab1d7 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -23,7 +23,7 @@ export const jimmyDotCodes = ( react = false, testing = false, astro = false, - autoDetect = false, + autoDetect = true, configs = [], }: Options = {}, ...moreConfigs: TypedConfigItem[] | Linter.Config[] diff --git a/src/types.ts b/src/types.ts index 55cfbf8..982b4bf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -51,26 +51,26 @@ export type TypedConfigItem = Omit< export interface Options { /** - * Are TypeScript rules are enabled? + * Are TypeScript rules enabled? * @default false */ typescript?: boolean | TypescriptOptions; /** - * Are React rules are enabled? + * Are React rules enabled? * @default false */ react?: boolean | ReactOptions; /** - * Are Jest rules are enabled? + * Are Jest rules enabled? * @default false */ /** - * Are testing rules are enabled? + * Are testing rules enabled? * @default false */ testing?: boolean | TestingOptions; /** - * Are astro rules are enabled? + * Are astro rules enabled? * @default false */ astro?: boolean; @@ -81,7 +81,7 @@ export interface Options { configs?: TypedConfigItem[] | Linter.Config[]; /** * Is auto detection enabled? - * @default false + * @default true */ autoDetect?: boolean; }