Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ drop all deprecated options, now simpler #109

Merged
merged 1 commit into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://semantic-release.gitbook.io/semantic-release)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square&logo=prettier)](https://github.com/prettier/prettier)

> 🔍 another opinionated [eslint](https://eslint.org) config
> 🔍 Another opinionated [ESLint](https://eslint.org) config

## 🛠️ Usage

Expand All @@ -15,25 +15,33 @@

### 🔨 Getting Started

First install the package, by running the following:
First, install the package:

```
pnpm add -D @jimmy.codes/eslint-config
```

Then all you need to in your `eslint.config.js` is:
Then, in your `eslint.config.js`, simply add:

```mjs
import eslintConfig from "@jimmy.codes/eslint-config";

export default eslintConfig();
```

Which will enable rules based on your project dependencies.
This automatically applies rules based on your installed dependencies.

### 🔧 Configuration

This package contains rules that can be enabled or disabled as follows:
By default, this config automatically enables rules based on your installed dependencies (e.g., `react`, `vitest`). Set `autoDetect: false` to disable this behavior.

```ts
import eslintConfig from "@jimmy.codes/eslint-config";

export default eslintConfig({ autoDetect: false });
```

You can also manually enable or disable specific rule sets:

```ts
import eslintConfig from "@jimmy.codes/eslint-config";
Expand All @@ -52,17 +60,9 @@ export default eslintConfig({
});
```

Or you can turn off auto detection to disable rules based on a project's dependencies:
#### Extending/Overriding the Configuration

```ts
import eslintConfig from "@jimmy.codes/eslint-config";

export default eslintConfig({ autoDetect: false });
```

#### Extending/overriding the Configuration

You can also extend or override the configuration:
You can extend or override the configuration using the `overrides` option:

```ts
import eslintConfig from "@jimmy.codes/eslint-config";
Expand All @@ -85,7 +85,7 @@ export default eslintConfig({
});
```

Or pass configs as additional arguments:
Alternatively, you can pass additional configurations as separate arguments:

```ts
import eslintConfig from "@jimmy.codes/eslint-config";
Expand All @@ -107,7 +107,9 @@ export default eslintConfig(
);
```

#### Ignores
> This approach is useful if you prefer to separate rule overrides into multiple objects instead of nesting them inside `overrides`.

#### Ignoring Files

You can also extend what is ignored:

Expand Down
5 changes: 1 addition & 4 deletions scripts/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { builtinRules } from "eslint/use-at-your-own-risk";
import eslintConfig from "../src";

const configs = await eslintConfig({
testing: {
// TODO: remove when framework approach is removed
framework: "jest",
},
jest: true,
});

const ruleDts = await flatConfigsToRulesDTS(
Expand Down
2 changes: 1 addition & 1 deletion src/configs/__snapshots__/typescript.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9201,7 +9201,7 @@ If your function does not access \`this\`, you can annotate it with \`this: void
{
"languageOptions": {
"parserOptions": {
"project": "/",
"projectService": true,
"tsconfigRootDir": "/",
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/configs/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createTypeScriptImportResolver } from "eslint-import-resolver-typescrip
import importX from "eslint-plugin-import-x";
import nodePlugin from "eslint-plugin-n";

import type { TypedConfigItem, TypescriptOptions } from "../types";
import type { TypedConfigItem } from "../types";

import { importsRules } from "../rules/imports";

Expand All @@ -29,7 +29,7 @@ const importsTypescriptConfig = () => {
};

interface ImportsConfigOptions {
typescript?: boolean | TypescriptOptions;
typescript?: boolean;
}

export const importsConfig = ({
Expand Down
19 changes: 19 additions & 0 deletions src/configs/jest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { TypedConfigItem } from "../types";

import { GLOB_E2E, GLOB_TESTS } from "../constants";
import { jestRules } from "../rules/jest";
import { interopDefault } from "../utils/interop-default";

export const jestConfig = async () => {
const jestPlugin = await interopDefault(import("eslint-plugin-jest"));

return [
{
files: GLOB_TESTS,
ignores: GLOB_E2E,
...jestPlugin.configs["flat/recommended"],
name: "jimmy.codes/jest",
rules: await jestRules(),
},
] satisfies TypedConfigItem[];
};
18 changes: 0 additions & 18 deletions src/configs/testing.spec.ts

This file was deleted.

43 changes: 0 additions & 43 deletions src/configs/testing.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/configs/typescript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe("typescriptConfig", () => {
it("should create config", () => {
vi.spyOn(process, "cwd").mockReturnValue("/");

expect(typescriptConfig({ project: "/" })).toMatchSnapshot();
expect(typescriptConfig()).toMatchSnapshot();
});

it("should create config w/ projectService", () => {
Expand Down
8 changes: 2 additions & 6 deletions src/configs/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { configs } from "typescript-eslint";

import type { TypescriptOptions } from "../types";

import { GLOB_JS, GLOB_JSX, GLOB_TESTS } from "../constants";
import { typescriptRules } from "../rules/typescript";

export const typescriptConfig = (options?: TypescriptOptions) => {
export const typescriptConfig = () => {
return [
...configs.strictTypeChecked,
...configs.stylisticTypeChecked.filter((config) => {
Expand All @@ -14,9 +12,7 @@ export const typescriptConfig = (options?: TypescriptOptions) => {
{
languageOptions: {
parserOptions: {
...(options?.project
? { project: options.project }
: { projectService: true }),
projectService: true,
tsconfigRootDir: process.cwd(),
},
},
Expand Down
19 changes: 19 additions & 0 deletions src/configs/vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { TypedConfigItem } from "../types";

import { GLOB_E2E, GLOB_TESTS } from "../constants";
import { vitestRules } from "../rules/vitest";
import { interopDefault } from "../utils/interop-default";

export const vitestConfig = async () => {
const vitestPlugin = await interopDefault(import("@vitest/eslint-plugin"));

return [
{
files: GLOB_TESTS,
ignores: GLOB_E2E,
...vitestPlugin.configs.recommended,
name: "jimmy.codes/vitest",
rules: await vitestRules(),
},
] satisfies TypedConfigItem[];
};
Loading