Skip to content

Commit

Permalink
feat: ✨ enable auto detection by default
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 💥 `autoDetect` is now `true` by default
  • Loading branch information
jimmy-guzman committed Oct 31, 2024
1 parent 11e521b commit 52a6f4b
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 29 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down Expand Up @@ -42,41 +40,43 @@ 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
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
Expand Down Expand Up @@ -122,7 +122,7 @@ export default jimmyDotCodes({
});
```

#### Overrides
#### Extending the Configuration

You can also extend the configuration:

Expand Down
2 changes: 1 addition & 1 deletion eslint.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import jimmyDotCodes from "./src";

export default jimmyDotCodes({ autoDetect: true });
export default jimmyDotCodes();
2 changes: 1 addition & 1 deletion scripts/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/configs/react.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/configs/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/configs/testing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/configs/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
21 changes: 15 additions & 6 deletions src/factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }),
Expand All @@ -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" }),
]),
Expand All @@ -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" }),
Expand All @@ -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" }),
Expand All @@ -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" }),
Expand All @@ -60,6 +67,7 @@ describe("jimmyDotCodes", () => {
jimmyDotCodes({
react: true,
testing: { framework: "jest", utilities: ["testing-library"] },
autoDetect: false,
}),
).toStrictEqual(
expect.arrayContaining([
Expand All @@ -82,6 +90,7 @@ describe("jimmyDotCodes", () => {
jimmyDotCodes({
react: true,
testing: { utilities: ["testing-library"] },
autoDetect: false,
}),
).toStrictEqual(
expect.arrayContaining([
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const jimmyDotCodes = (
react = false,
testing = false,
astro = false,
autoDetect = false,
autoDetect = true,
configs = [],
}: Options = {},
...moreConfigs: TypedConfigItem[] | Linter.Config[]
Expand Down
12 changes: 6 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -81,7 +81,7 @@ export interface Options {
configs?: TypedConfigItem[] | Linter.Config[];
/**
* Is auto detection enabled?
* @default false
* @default true
*/
autoDetect?: boolean;
}

0 comments on commit 52a6f4b

Please sign in to comment.