@paratco/eslint-config 3.3.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,88 +1,70 @@
1
1
  # `@paratco/eslint-config`
2
-
3
2
  Paratco ESLint configs for JavaScript and TypeScript projects.
4
-
5
3
  - TypeScript
6
4
  - React (optional)
7
5
  - Node.js
8
6
  - Import plugin (optional)
9
7
  - Stylistic or Prettier formatting
10
-
11
8
  ## Installation
12
-
13
-
14
9
  NPM:
15
10
  ```bash
16
11
  # prettier is optional, just use it if you want to use prettier formatting
17
12
  npm install --save-dev @paratco/eslint-config eslint prettier
18
13
  ```
19
-
20
14
  Yarn:
21
15
  ```bash
22
16
  # prettier is optional, just use it if you want to use prettier formatting
23
17
  yarn add -D @paratco/eslint-config eslint prettier
24
18
  ```
25
-
19
+ Bun:
20
+ ```bash
21
+ # prettier is optional, just use it if you want to use prettier formatting
22
+ bun add -d @paratco/eslint-config eslint prettier
23
+ ```
26
24
  ## Usage (ESLint Flat Config)
27
-
28
25
  Create an `eslint.config.{js,mjs,ts}` file in your project root:
29
-
30
26
  ```javascript
31
27
  import { createConfig } from "@paratco/eslint-config";
32
-
33
28
  export default createConfig({
34
29
  // Required: Specify the platform
35
30
  platform: "node", // or "react"
36
-
37
31
  // Required: Choose your formatting style
38
32
  style: "prettier", // or "stylistic"
39
-
40
33
  // Optional: Enable import plugin rules
41
34
  useImport: true,
42
-
43
35
  // Optional: TypeScript configuration
44
36
  typescript: {
45
37
  tsconfigRootDir: import.meta.dirname,
46
38
  project: "./tsconfig.json"
47
39
  },
48
-
49
40
  // Optional: Add custom overrides
50
41
  overrides: [
51
42
  // Your custom ESLint configurations
52
43
  ],
53
-
54
44
  // Optional: Specify patterns to ignore
55
45
  ignores: ["dist/**", "node_modules/**"]
56
46
  });
57
47
  ```
58
-
59
48
  ## Configuration Options
60
-
61
49
  The `createConfig` function accepts an options object with the following properties:
62
-
63
50
  | Option | Type | Required | Default | Description |
64
51
  |--------|------|----------|---------|-------------|
65
52
  | `platform` | `"node" \| "react"` | Yes | - | Specifies the platform for the ESLint configuration |
66
53
  | `style` | `"stylistic" \| "prettier"` | Yes | - | Specifies the style formatter to use |
67
54
  | `useImport` | `boolean` | No | `false` | Enable import plugin rules |
55
+ | `files` | `string[]` | No | `undefined` | Scope all rules to these file globs only |
68
56
  | `typescript` | `TypescriptOptions` | No | `undefined` | TypeScript configuration options |
69
57
  | `overrides` | `Linter.Config[]` | No | `undefined` | Additional ESLint configurations to override defaults |
70
58
  | `ignores` | `string[]` | No | `undefined` | Patterns to ignore |
71
-
72
59
  ### TypeScript Options
73
-
74
60
  | Option | Type | Required | Default | Description |
75
61
  |--------|------|----------|---------|-------------|
76
62
  | `tsconfigRootDir` | `string` | No | `undefined` | The root directory for TypeScript configuration |
77
63
  | `project` | `string \| string[]` | No | `undefined` | Path to tsconfig.json file(s) |
78
-
79
64
  ## Examples
80
-
81
65
  ### Node.js Configuration
82
-
83
66
  ```javascript
84
67
  import { createConfig } from "@paratco/eslint-config";
85
-
86
68
  export default createConfig({
87
69
  platform: "node",
88
70
  style: "prettier",
@@ -92,12 +74,9 @@ export default createConfig({
92
74
  }
93
75
  });
94
76
  ```
95
-
96
77
  ### React Configuration
97
-
98
78
  ```javascript
99
79
  import { createConfig } from "@paratco/eslint-config";
100
-
101
80
  export default createConfig({
102
81
  platform: "react",
103
82
  style: "stylistic",
@@ -108,105 +87,47 @@ export default createConfig({
108
87
  }
109
88
  });
110
89
  ```
111
-
112
90
  ### JavaScript-only Configuration
113
-
114
91
  ```javascript
115
92
  import { createConfig } from "@paratco/eslint-config";
116
-
117
93
  export default createConfig({
118
94
  platform: "node",
119
95
  style: "prettier"
120
96
  });
121
97
  ```
122
-
123
- ## Using oxlint alongside ESLint
124
-
125
- [oxlint](https://oxc-project.github.io/) is a fast JavaScript/TypeScript linter written in Rust that can be used alongside ESLint to improve performance and catch additional issues. This package supports using both linters together.
126
-
127
- ### Installation
128
-
129
- Install oxlint alongside ESLint:
130
-
131
- NPM:
132
- ```bash
133
- npm install --save-dev --save-exact oxlint@1.7.0 eslint-plugin-oxlint@1.7.0
134
- ```
135
-
136
- Yarn:
137
- ```bash
138
- yarn add -D -E oxlint@1.7.0 eslint-plugin-oxlint@1.7.0
139
- ```
140
-
141
- note: Ensure you have the latest and exact version of oxlint and eslint-plugin-oxlint installed.
142
-
143
- ### Configuration
144
-
145
- 1. Create an `.oxlintrc.json` file with @oxlint/migrate:
146
-
147
- ```bash
148
- # version match with oxlint installed before
149
- npx @oxlint/migrate@1.7.0
150
- ```
151
- This will generate or update your `.oxlintrc.json` file based on your ESLint configuration. The tool analyzes your ESLint config and converts compatible rules to their oxlint equivalents.
152
-
153
- 2. Update your `package.json` scripts to run both linters (run oxlint first for performance):
154
-
155
- ```json
156
- {
157
- "scripts": {
158
- "lint": "oxlint --max-warnings=0 && eslint --max-warnings=0",
159
- "lint:fix": "oxlint --fix && eslint --fix"
160
- }
161
- }
162
- ```
163
-
164
- 3. integrate oxlint with ESLint by adding the ESLint plugin to your configuration:
165
-
98
+ ### Scoping Rules to Specific Directories
99
+ Use the `files` option to restrict all rules to a specific set of file globs. This is useful when a single ESLint config covers multiple platforms (e.g. an Electron app with a renderer and a main process each targeting a different `tsconfig.json`), or when working in a monorepo where different sub-trees have different configs.
100
+ When `files` is provided, `createConfig` internally wraps the returned configs with [`eslint.defineConfig()`](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file) so that all plugin registrations and rules are correctly scoped — no extra wrapper is needed in your config file.
166
101
  ```javascript
167
102
  import { createConfig } from "@paratco/eslint-config";
168
- import oxlintPlugin from "eslint-plugin-oxlint";
169
-
170
- export default createConfig({
171
- platform: "node", // or "react"
172
- style: "prettier", // or "stylistic"
173
-
174
- // Add oxlint plugin as the LAST item in your overrides
175
- // This ensures ESLint rules that are handled by oxlint are turned off
176
- overrides: [
177
- // Your other overrides go here
178
-
179
- // eslint-plugin-oxlint must be the last config
180
- ...oxlintPlugin.configs["flat/all"]
181
- ]
182
- });
183
- ```
184
-
185
- ### Running Linters
186
-
187
- Run both linters with a single command:
188
-
189
- ```bash
190
- npm run lint
191
- # or
192
- yarn lint
193
- ```
194
-
195
- Fix issues automatically when possible:
196
-
197
- ```bash
198
- npm run lint:fix
199
- # or
200
- yarn lint:fix
103
+ export default [
104
+ // Renderer process — React + browser globals
105
+ ...createConfig({
106
+ files: ["./src/**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}"],
107
+ platform: "react",
108
+ style: "stylistic",
109
+ useImport: true,
110
+ typescript: {
111
+ tsconfigRootDir: import.meta.dirname,
112
+ project: "./tsconfig.app.json"
113
+ }
114
+ }),
115
+ // Main process — Node.js globals
116
+ ...createConfig({
117
+ files: ["./electron/**/*.{js,mjs,cjs,ts}"],
118
+ platform: "node",
119
+ style: "stylistic",
120
+ useImport: true,
121
+ typescript: {
122
+ tsconfigRootDir: import.meta.dirname,
123
+ project: "./tsconfig.electron.json"
124
+ }
125
+ }),
126
+ {
127
+ ignores: ["dist", "dist-electron", ".vite"]
128
+ }
129
+ ];
201
130
  ```
202
-
203
- ### Benefits of Using Both Linters
204
-
205
- - **Performance**: oxlint is significantly faster than ESLint, especially on large codebases
206
- - **Complementary Rules**: Each linter has unique rules that can catch different issues
207
- - **Gradual Migration**: You can gradually migrate from ESLint to oxlint or use both permanently
208
- - **Modern JavaScript Support**: oxlint has excellent support for modern JavaScript and TypeScript features
209
-
131
+ > **Note:** When `files` is used and multiple `createConfig` calls are combined, spread each result (`...createConfig(...)`) into the top-level array instead of returning a single `createConfig` call directly.
210
132
  ## License
211
-
212
133
  Licensed under [MIT License](./LICENSE)
@@ -0,0 +1,3 @@
1
+ import type { Linter } from "eslint";
2
+ declare const _default: Linter.Config[];
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { Linter } from "eslint";
2
+ import type { TypescriptOptions } from "../types";
3
+ export default function importConfig(typescript?: TypescriptOptions): Linter.Config[];
@@ -0,0 +1 @@
1
+ export { default } from "./base";
@@ -0,0 +1,3 @@
1
+ import type { Linter } from "eslint";
2
+ declare const _default: Linter.Config[];
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { Linter } from "eslint";
2
+ declare const _default: Linter.Config[];
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { Linter } from "eslint";
2
+ declare const _default: Linter.Config[];
3
+ export default _default;
package/dist/index.d.ts CHANGED
@@ -1,20 +1,3 @@
1
- import { Linter } from "eslint";
2
-
3
- //#region src/types.d.ts
4
- interface TypescriptOptions {
5
- tsconfigRootDir?: string;
6
- project?: string | string[];
7
- }
8
- interface Options {
9
- platform: "node" | "react";
10
- style: "stylistic" | "prettier";
11
- useImport?: boolean;
12
- overrides?: Linter.Config[];
13
- ignores?: string[];
14
- typescript?: TypescriptOptions;
15
- }
16
- //#endregion
17
- //#region src/index.d.ts
18
- declare function createConfig(opt: Options): Linter.Config[];
19
- //#endregion
20
- export { createConfig };
1
+ import type { Linter } from "eslint";
2
+ import type { Options } from "./types";
3
+ export declare function createConfig(opt: Options): Linter.Config[];