@zhangyu1818/oxlint-config 1.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 ADDED
@@ -0,0 +1,125 @@
1
+ # @zhangyu1818/oxlint-config
2
+
3
+ Native `oxlint` + `oxfmt` presets for JavaScript and TypeScript projects.
4
+
5
+ Core presets in this package use functionality implemented natively in Oxc. The `reactAgentRules` preset is backed by an Oxlint JS plugin that ships with this package and auto-enables when `react` is installed.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pnpm add -D @zhangyu1818/oxlint-config oxlint oxlint-tsgolint oxfmt
11
+ ```
12
+
13
+ ## Oxlint
14
+
15
+ Create `oxlint.config.ts`:
16
+
17
+ ```ts
18
+ import { defineConfig } from '@zhangyu1818/oxlint-config'
19
+
20
+ export default defineConfig({
21
+ presets: {
22
+ node: true,
23
+ react: true,
24
+ test: true,
25
+ typescript: true,
26
+ },
27
+ })
28
+ ```
29
+
30
+ Available presets:
31
+
32
+ - `ignores`
33
+ - `imports`
34
+ - `javascript`
35
+ - `node`
36
+ - `react`
37
+ - `reactAgentRules`
38
+ - `next`
39
+ - `test`
40
+ - `typescript`
41
+ - `unicorn`
42
+
43
+ Default line limits:
44
+
45
+ - source files: `300`
46
+ - component files (`*.jsx`, `*.tsx`, `*.mtsx`, `*.ctsx`): `200`
47
+ - test files: `500`
48
+
49
+ `react` preset options:
50
+
51
+ ```ts
52
+ react: {
53
+ options: {
54
+ a11y: true,
55
+ framework: {
56
+ next: true,
57
+ vite: false,
58
+ },
59
+ },
60
+ }
61
+ ```
62
+
63
+ `reactAgentRules` adds the bundled `react-agent-rules` JS plugin preset and applies:
64
+
65
+ - `react-agent-rules/no-manual-memoization`
66
+ - `react-agent-rules/no-forward-ref`
67
+ - `react-agent-rules/effect-empty-deps-only`
68
+
69
+ ```ts
70
+ export default defineConfig({
71
+ presets: {
72
+ react: true,
73
+ },
74
+ })
75
+ ```
76
+
77
+ ## Oxfmt
78
+
79
+ Create `oxfmt.config.ts`:
80
+
81
+ ```ts
82
+ import { defineOxfmtConfig } from '@zhangyu1818/oxlint-config'
83
+
84
+ export default defineOxfmtConfig({
85
+ presets: {
86
+ imports: true,
87
+ packageJson: true,
88
+ tailwindcss: false,
89
+ },
90
+ })
91
+ ```
92
+
93
+ Default formatter options:
94
+
95
+ - `semi: false`
96
+ - `singleQuote: true`
97
+ - `tabWidth: 2`
98
+ - `useTabs: false`
99
+ - `printWidth: 80`
100
+ - `endOfLine: 'lf'`
101
+
102
+ ## Scripts
103
+
104
+ ```json
105
+ {
106
+ "scripts": {
107
+ "lint": "oxlint",
108
+ "lint:fix": "oxlint --fix",
109
+ "format": "oxfmt -c oxfmt.config.ts .",
110
+ "format:check": "oxfmt --check -c oxfmt.config.ts ."
111
+ }
112
+ }
113
+ ```
114
+
115
+ ## Migration Notes
116
+
117
+ This migration keeps `264` native rules and drops `139` rules from the previous ESLint-based package.
118
+
119
+ ## Exports
120
+
121
+ - `defineConfig`
122
+ - `defineOxlintConfig`
123
+ - `defineOxfmtConfig`
124
+ - `defaultIgnorePatterns`
125
+ - `defaultSortImports`
@@ -0,0 +1,169 @@
1
+ declare const defaultIgnorePatterns: string[];
2
+
3
+ type Severity = 'off' | 'warn' | 'error';
4
+ type JsonPrimitive = boolean | null | number | string;
5
+ type JsonValue = JsonObject | JsonPrimitive | JsonValue[];
6
+ interface JsonObject {
7
+ [key: string]: JsonValue;
8
+ }
9
+ type RuleConfig = Severity | [Severity, ...JsonValue[]];
10
+ type Rules = Record<string, RuleConfig>;
11
+ interface OxlintJsPluginAlias {
12
+ name: string;
13
+ specifier: string;
14
+ }
15
+ type OxlintJsPlugin = OxlintJsPluginAlias | string;
16
+ type OxlintPlugin = 'eslint' | 'import' | 'jest' | 'jsdoc' | 'jsx-a11y' | 'nextjs' | 'node' | 'oxc' | 'promise' | 'react' | 'react-perf' | 'typescript' | 'unicorn' | 'vitest' | 'vue';
17
+ interface OxlintOverride {
18
+ env?: Record<string, boolean>;
19
+ files: string[];
20
+ jsPlugins?: OxlintJsPlugin[];
21
+ plugins?: OxlintPlugin[];
22
+ rules?: Rules;
23
+ }
24
+ interface OxlintConfig {
25
+ $schema?: string;
26
+ categories?: Record<string, Severity>;
27
+ env?: Record<string, boolean>;
28
+ ignorePatterns?: string[];
29
+ jsPlugins?: OxlintJsPlugin[];
30
+ options?: {
31
+ typeAware?: boolean;
32
+ typeCheck?: boolean;
33
+ };
34
+ overrides?: OxlintOverride[];
35
+ plugins?: OxlintPlugin[];
36
+ rules?: Rules;
37
+ settings?: Record<string, JsonValue>;
38
+ }
39
+ interface OxlintPresetConfig<TOptions = undefined> {
40
+ enabled?: boolean;
41
+ options?: TOptions;
42
+ rules?: Rules;
43
+ }
44
+ interface IgnorePresetConfig {
45
+ enabled?: boolean;
46
+ patterns?: string[];
47
+ }
48
+ interface ReactOptions {
49
+ next?: boolean;
50
+ vite?: boolean;
51
+ }
52
+ interface ReactPresetOptions {
53
+ a11y?: boolean;
54
+ framework?: ReactOptions;
55
+ }
56
+ interface TypeScriptOptions {
57
+ typeAware?: boolean;
58
+ }
59
+ interface OxlintPresets {
60
+ ignores?: boolean | IgnorePresetConfig;
61
+ imports?: boolean | OxlintPresetConfig;
62
+ javascript?: boolean | OxlintPresetConfig;
63
+ next?: boolean | OxlintPresetConfig;
64
+ node?: boolean | OxlintPresetConfig;
65
+ react?: boolean | OxlintPresetConfig<ReactPresetOptions>;
66
+ reactAgentRules?: boolean | OxlintPresetConfig;
67
+ test?: boolean | OxlintPresetConfig;
68
+ typescript?: boolean | OxlintPresetConfig<TypeScriptOptions>;
69
+ unicorn?: boolean | OxlintPresetConfig;
70
+ }
71
+ interface DefineOxlintConfigOptions {
72
+ categories?: Record<string, Severity>;
73
+ env?: Record<string, boolean>;
74
+ ignorePatterns?: string[];
75
+ jsPlugins?: OxlintJsPlugin[];
76
+ overrides?: OxlintOverride[];
77
+ presets?: OxlintPresets;
78
+ rules?: Rules;
79
+ settings?: Record<string, JsonValue>;
80
+ }
81
+ interface SortImportCustomGroup {
82
+ elementNamePattern?: string[];
83
+ groupName: string;
84
+ modifiers?: string[];
85
+ selector?: string;
86
+ }
87
+ type SortImportGroup = {
88
+ newlinesBetween: boolean;
89
+ } | string | string[];
90
+ interface SortImportsOptions {
91
+ customGroups?: SortImportCustomGroup[];
92
+ groups?: SortImportGroup[];
93
+ ignoreCase?: boolean;
94
+ internalPattern?: string[];
95
+ newlinesBetween?: boolean;
96
+ order?: 'asc' | 'desc';
97
+ partitionByComment?: boolean;
98
+ partitionByNewline?: boolean;
99
+ sortSideEffects?: boolean;
100
+ }
101
+ interface SortPackageJsonOptions {
102
+ sortScripts?: boolean;
103
+ }
104
+ interface TailwindSortOptions {
105
+ attributes?: string[];
106
+ config?: string;
107
+ functions?: string[];
108
+ preserveDuplicates?: boolean;
109
+ preserveWhitespace?: boolean;
110
+ stylesheet?: string;
111
+ }
112
+ interface OxfmtOverrideOptions {
113
+ endOfLine?: 'cr' | 'crlf' | 'lf';
114
+ printWidth?: number;
115
+ semi?: boolean;
116
+ singleQuote?: boolean;
117
+ sortImports?: boolean | SortImportsOptions;
118
+ sortPackageJson?: boolean | SortPackageJsonOptions;
119
+ sortTailwindcss?: boolean | TailwindSortOptions;
120
+ tabWidth?: number;
121
+ trailingComma?: 'all' | 'es5' | 'none';
122
+ useTabs?: boolean;
123
+ }
124
+ interface OxfmtOverride {
125
+ excludeFiles?: string[];
126
+ files: string[];
127
+ options: OxfmtOverrideOptions;
128
+ }
129
+ interface OxfmtConfig extends OxfmtOverrideOptions {
130
+ $schema?: string;
131
+ ignorePatterns?: string[];
132
+ overrides?: OxfmtOverride[];
133
+ }
134
+ interface OxfmtPresetConfig<TOptions = undefined> {
135
+ enabled?: boolean;
136
+ options?: TOptions;
137
+ }
138
+ interface OxfmtPresets {
139
+ imports?: boolean | OxfmtPresetConfig<SortImportsOptions>;
140
+ packageJson?: boolean | OxfmtPresetConfig<SortPackageJsonOptions>;
141
+ tailwindcss?: boolean | OxfmtPresetConfig<TailwindSortOptions>;
142
+ }
143
+ interface DefineOxfmtConfigOptions extends OxfmtOverrideOptions {
144
+ ignorePatterns?: string[];
145
+ overrides?: OxfmtOverride[];
146
+ presets?: OxfmtPresets;
147
+ }
148
+
149
+ declare const defaultOxlintPresets: {
150
+ ignores: true;
151
+ imports: true;
152
+ javascript: true;
153
+ next: boolean;
154
+ node: false;
155
+ react: boolean;
156
+ reactAgentRules: boolean;
157
+ test: boolean;
158
+ typescript: boolean;
159
+ unicorn: true;
160
+ };
161
+ declare function defineOxlintConfig(options?: DefineOxlintConfigOptions): OxlintConfig;
162
+ declare const defineConfig: typeof defineOxlintConfig;
163
+
164
+ declare const defaultSortImports: SortImportsOptions;
165
+
166
+ declare const defaultOxfmtPresets: Required<OxfmtPresets>;
167
+ declare function defineOxfmtConfig(options?: DefineOxfmtConfigOptions): OxfmtConfig;
168
+
169
+ export { type DefineOxfmtConfigOptions, type DefineOxlintConfigOptions, type OxfmtConfig, type OxfmtOverride, type OxfmtPresetConfig, type OxfmtPresets, type OxlintConfig, type OxlintJsPlugin, type OxlintJsPluginAlias, type OxlintOverride, type OxlintPlugin, type OxlintPresetConfig, type OxlintPresets, type ReactOptions, type ReactPresetOptions, type RuleConfig, type Rules, type Severity, type SortImportsOptions, type SortPackageJsonOptions, type TailwindSortOptions, type TypeScriptOptions, defaultIgnorePatterns, defaultOxfmtPresets, defaultOxlintPresets, defaultSortImports, defineConfig, defineOxfmtConfig, defineOxlintConfig };