@airteam/oxc-config 0.0.0-stage → 0.1.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 +123 -2
- package/dist/oxfmt/config.d.ts +1 -0
- package/dist/oxfmt/config.js +3 -0
- package/dist/oxlint/config.d.ts +18 -0
- package/dist/oxlint/config.js +22 -0
- package/dist/oxlint/profiles/react-native.d.ts +2 -0
- package/dist/oxlint/profiles/react-native.js +18 -0
- package/package.json +64 -3
- package/tsconfig.base.json +3 -0
package/README.md
CHANGED
|
@@ -1,3 +1,124 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @airteam/oxc-config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Airteam's shared [Oxlint](https://oxc.rs/docs/guide/usage/linter.html) and [Oxfmt](https://oxc.rs/docs/guide/usage/formatter.html) configs for TypeScript and JavaScript projects.
|
|
4
|
+
|
|
5
|
+
## Set up a project
|
|
6
|
+
|
|
7
|
+
Install the package and its peers. It requires Node.js 22.23 or later.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add -D @airteam/oxc-config oxlint oxfmt oxlint-tsgolint
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Create `oxlint.config.ts` and `oxfmt.config.ts` in the project root:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createLintConfig } from "@airteam/oxc-config/oxlint";
|
|
17
|
+
|
|
18
|
+
export default createLintConfig({ nextjs: true, vitest: true });
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { createFormatConfig } from "@airteam/oxc-config/oxfmt";
|
|
23
|
+
|
|
24
|
+
export default createFormatConfig();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Add the scripts:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"scripts": {
|
|
32
|
+
"lint": "oxlint .",
|
|
33
|
+
"lint:fix": "oxlint --fix . && oxfmt . && oxlint .",
|
|
34
|
+
"format": "oxfmt .",
|
|
35
|
+
"format:check": "oxfmt --check ."
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Type-aware checking is on by default and needs a `tsconfig.json` that TypeScript 7 accepts. Pass `typeAware: false` if your project isn't ready for it.
|
|
41
|
+
|
|
42
|
+
The React profiles use a plugin that declares an ESLint peer even though it runs under Oxlint. To skip installing ESLint with pnpm, add this to the project's `pnpm-workspace.yaml` before installing:
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
autoInstallPeers: false
|
|
46
|
+
peerDependencyRules:
|
|
47
|
+
ignoreMissing:
|
|
48
|
+
- eslint
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
To share the strict compiler settings, extend the base config from the project's `tsconfig.json`:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"extends": "@airteam/oxc-config/tsconfig"
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Choose options
|
|
60
|
+
|
|
61
|
+
Enable only what the project uses. In a monorepo, scope each option to the files or directories that use it.
|
|
62
|
+
|
|
63
|
+
| Option | Value | Adds |
|
|
64
|
+
| -------------------- | ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
65
|
+
| `node` | `true` or globs | Node.js environment and rules |
|
|
66
|
+
| `react` | `true` or globs | React, React Compiler, accessibility and effect rules |
|
|
67
|
+
| `nextjs` | `true` or application directories | The React rules plus Next.js rules and its default-export entrypoints |
|
|
68
|
+
| `reactNative` | `true` or application directories | The React rules, with default exports allowed for `App` and `app/` |
|
|
69
|
+
| `vitest`, `jest` | `true` or globs | The test runner's rules. The globs join the test files |
|
|
70
|
+
| `effect` | `true` or globs | Effect error-tag and service-import rules |
|
|
71
|
+
| `electron` | `true` or `{ renderer: [...] }` | Electron security rules everywhere, and an import boundary keeping `electron` and `node:*` out of the renderer (`src/renderer/**` by default). Needs `root` |
|
|
72
|
+
| `tests` | Globs | Extra test files, such as Playwright tests |
|
|
73
|
+
| `env` | The modules that read the environment | `process.env` and `import.meta.env` reads only in those modules |
|
|
74
|
+
| `clock`, `random` | The modules that own each | Current-time reads and random values only in those modules |
|
|
75
|
+
| `boundaries` | Import boundaries | Imports that must not cross parts of the project. Needs `root` |
|
|
76
|
+
| `serverActionGuards` | Guard function names | `"use server"` actions that must start by awaiting a guard |
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { createLintConfig } from "@airteam/oxc-config/oxlint";
|
|
80
|
+
|
|
81
|
+
export default createLintConfig({
|
|
82
|
+
root: import.meta.dirname,
|
|
83
|
+
nextjs: ["apps/web"],
|
|
84
|
+
reactNative: ["apps/mobile"],
|
|
85
|
+
node: ["services/**"],
|
|
86
|
+
vitest: true,
|
|
87
|
+
env: ["apps/web/src/env.ts"],
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The [configuration guide](https://github.com/jameswyse/oxc-config/blob/main/docs/configuration.md) describes each option in detail, and its [rule reference](https://github.com/jameswyse/oxc-config/blob/main/REFERENCE.md) lists what each rule rejects.
|
|
92
|
+
|
|
93
|
+
## Add project exceptions
|
|
94
|
+
|
|
95
|
+
Pass `rules`, `overrides` and `ignorePatterns` to the same call:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { createLintConfig } from "@airteam/oxc-config/oxlint";
|
|
99
|
+
|
|
100
|
+
export default createLintConfig({
|
|
101
|
+
nextjs: true,
|
|
102
|
+
ignorePatterns: ["src/generated/**"],
|
|
103
|
+
rules: { "wyse/no-swallowed-errors": "off" },
|
|
104
|
+
overrides: [{ files: ["src/validation/**"], rules: { "wyse/no-runtime-typeof": "off" } }],
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- `rules` changes a rule wherever the shared config enables it, so a test rule stays scoped to test files. A severity on its own keeps the rule's options.
|
|
109
|
+
- `overrides` are added after the shared overrides, so they win.
|
|
110
|
+
- `ignorePatterns` are added to the shared ignore patterns.
|
|
111
|
+
|
|
112
|
+
`createFormatConfig` takes Oxfmt options the same way, such as `createFormatConfig({ singleQuote: true })`.
|
|
113
|
+
|
|
114
|
+
If several projects need the same exception, change the shared rules instead.
|
|
115
|
+
|
|
116
|
+
## Change the shared rules
|
|
117
|
+
|
|
118
|
+
The team owns this package. Open a pull request here to change what every project lints.
|
|
119
|
+
|
|
120
|
+
- [`src/oxlint/config.ts`](src/oxlint/config.ts) is the whole policy. `base` lists the rule profiles every project gets, `profiles` lists the options a project can switch on, and `rules` changes single rules.
|
|
121
|
+
- [`src/oxlint/profiles`](src/oxlint/profiles) holds Airteam's own profiles, such as `reactNative`.
|
|
122
|
+
- [`src/oxfmt/config.ts`](src/oxfmt/config.ts) holds the formatter defaults.
|
|
123
|
+
|
|
124
|
+
[Build a preset](https://github.com/jameswyse/oxc-config/blob/main/docs/presets.md) explains profiles, layers and how to write or extend one.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createFormatConfig: (options?: import("oxfmt").OxfmtConfig) => import("@jameswyse/oxc-config/oxfmt/preset").FormatConfig;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const createLintConfig: (options?: import("@jameswyse/oxc-config/oxlint/preset").LintOptions<{
|
|
2
|
+
node: import("@jameswyse/oxc-config/oxlint/preset").FileScope;
|
|
3
|
+
react: import("@jameswyse/oxc-config/oxlint/preset").FileScope;
|
|
4
|
+
nextjs: import("@jameswyse/oxc-config/oxlint/preset").AppRoots;
|
|
5
|
+
reactNative: import("@jameswyse/oxc-config/oxlint/preset").AppRoots;
|
|
6
|
+
vitest: import("@jameswyse/oxc-config/oxlint/preset").FileScope;
|
|
7
|
+
jest: import("@jameswyse/oxc-config/oxlint/preset").FileScope;
|
|
8
|
+
effect: import("@jameswyse/oxc-config/oxlint/preset").FileScope;
|
|
9
|
+
electron: true | {
|
|
10
|
+
renderer?: string[];
|
|
11
|
+
};
|
|
12
|
+
env: import("@jameswyse/oxc-config/oxlint/preset").OneOrMore<string>;
|
|
13
|
+
clock: import("@jameswyse/oxc-config/oxlint/preset").OneOrMore<string>;
|
|
14
|
+
random: import("@jameswyse/oxc-config/oxlint/preset").OneOrMore<string>;
|
|
15
|
+
boundaries: import("@jameswyse/oxc-config/oxlint/preset").ImportBoundary[];
|
|
16
|
+
serverActionGuards: import("@jameswyse/oxc-config/oxlint/preset").OneOrMore<string>;
|
|
17
|
+
}> | undefined) => import("@jameswyse/oxc-config/oxlint/preset").SharedLintConfig;
|
|
18
|
+
export type LintOptions = NonNullable<Parameters<typeof createLintConfig>[0]>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineLintPreset } from "@jameswyse/oxc-config/oxlint/preset";
|
|
2
|
+
import { boundaries, clock, comments, core, effect, electron, env, errors, jest, modules, mutation, nextjs, node, random, react, security, serverActionGuards, spacing, tests, types, vitest, } from "@jameswyse/oxc-config/oxlint/profiles";
|
|
3
|
+
import { reactNative } from "./profiles/react-native.js";
|
|
4
|
+
export const createLintConfig = defineLintPreset({
|
|
5
|
+
base: [core, types, security, errors, modules, comments, mutation, tests, spacing],
|
|
6
|
+
profiles: {
|
|
7
|
+
node,
|
|
8
|
+
react,
|
|
9
|
+
nextjs,
|
|
10
|
+
reactNative,
|
|
11
|
+
vitest,
|
|
12
|
+
jest,
|
|
13
|
+
effect,
|
|
14
|
+
electron,
|
|
15
|
+
env,
|
|
16
|
+
clock,
|
|
17
|
+
random,
|
|
18
|
+
boundaries,
|
|
19
|
+
serverActionGuards,
|
|
20
|
+
},
|
|
21
|
+
rules: { "wyse/no-comments": "off" },
|
|
22
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { appFiles, appPrefixes } from "@jameswyse/oxc-config/oxlint/preset";
|
|
2
|
+
import { react } from "@jameswyse/oxc-config/oxlint/profiles";
|
|
3
|
+
export const reactNative = (scope, roots) => [
|
|
4
|
+
...react(scope, appFiles(scope, roots)),
|
|
5
|
+
{
|
|
6
|
+
files: appFiles(scope, roots),
|
|
7
|
+
plugins: ["react", "jsx-a11y"],
|
|
8
|
+
rules: { "jsx-a11y/no-autofocus": "off" },
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
files: appPrefixes(roots).flatMap((prefix) => [
|
|
12
|
+
`${prefix}App.{js,jsx,ts,tsx}`,
|
|
13
|
+
`${prefix}{app,src/app}/**/*.{js,jsx,ts,tsx}`,
|
|
14
|
+
]),
|
|
15
|
+
excludeFiles: scope.tests,
|
|
16
|
+
rules: { "import/no-default-export": "off" },
|
|
17
|
+
},
|
|
18
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airteam/oxc-config",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Airteam's Oxlint and Oxfmt configs for TypeScript and JavaScript projects",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/airteamaus/oxc-config.git"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"tsconfig.base.json"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
"./oxlint": "./dist/oxlint/config.js",
|
|
17
|
+
"./oxfmt": "./dist/oxfmt/config.js",
|
|
18
|
+
"./tsconfig": "./tsconfig.base.json"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@jameswyse/oxc-config": "1.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@changesets/cli": "3.0.3",
|
|
25
|
+
"@types/node": "^22.20.5",
|
|
26
|
+
"oxfmt": "0.77.0",
|
|
27
|
+
"oxlint": "1.92.0",
|
|
28
|
+
"oxlint-tsgolint": "7.0.2006",
|
|
29
|
+
"typescript": "7.0.2"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"oxfmt": ">=0.71.0 <1",
|
|
33
|
+
"oxlint": ">=1.86.0 <2",
|
|
34
|
+
"oxlint-tsgolint": ">=7.0.2003 <8"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"oxfmt": {
|
|
38
|
+
"optional": true
|
|
39
|
+
},
|
|
40
|
+
"oxlint-tsgolint": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"devEngines": {
|
|
45
|
+
"packageManager": {
|
|
46
|
+
"name": "pnpm",
|
|
47
|
+
"version": "12.18.0"
|
|
48
|
+
},
|
|
49
|
+
"runtime": {
|
|
50
|
+
"name": "node",
|
|
51
|
+
"version": "26.13.0",
|
|
52
|
+
"onFail": "download"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=22.23.0"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsc -p tsconfig.build.json",
|
|
60
|
+
"check": "pnpm test && pnpm lint && pnpm typecheck && pnpm format:check && pnpm build",
|
|
61
|
+
"format": "oxfmt .",
|
|
62
|
+
"format:check": "oxfmt --check .",
|
|
63
|
+
"lint": "oxlint .",
|
|
64
|
+
"test": "node --test \"src/**/*.test.ts\"",
|
|
65
|
+
"typecheck": "tsc"
|
|
66
|
+
}
|
|
6
67
|
}
|