@mouse_484/oxc-config 0.6.10 → 0.7.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 +39 -2
- package/package.json +2 -3
- package/src/configs/import.js +5 -2
- package/src/configs/index.d.ts +0 -13
- package/src/configs/index.js +0 -4
- package/src/format.js +17 -0
- package/src/index.d.ts +4 -1
- package/src/index.js +2 -64
- package/src/lint.js +64 -0
- package/src/configs/stylistic.js +0 -20
- package/src/configs/tailwind.js +0 -29
package/README.md
CHANGED
|
@@ -4,11 +4,12 @@ Oxlint Config by me
|
|
|
4
4
|
|
|
5
5
|
## Requirements
|
|
6
6
|
- Oxlint: recomended latest (required `jsPlugin` support)
|
|
7
|
+
- Oxfmt: recomended latest (for formatting)
|
|
7
8
|
|
|
8
9
|
## Usage
|
|
9
10
|
Install the packages
|
|
10
11
|
```sh
|
|
11
|
-
npm install -D oxlint @mouse_484/oxc-config
|
|
12
|
+
npm install -D oxlint oxfmt @mouse_484/oxc-config
|
|
12
13
|
```
|
|
13
14
|
|
|
14
15
|
Create a `oxlint.config.ts` and add the following code:
|
|
@@ -25,5 +26,41 @@ export default lint(
|
|
|
25
26
|
)
|
|
26
27
|
```
|
|
27
28
|
|
|
29
|
+
Create a `oxfmt.config.ts` and add the following code:
|
|
30
|
+
```js
|
|
31
|
+
import { format } from '@mouse_484/oxc-config'
|
|
32
|
+
|
|
33
|
+
export default format(
|
|
34
|
+
{
|
|
35
|
+
// oxfmt config
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Formatting rules are not provided by `lint()`, they are left to `format()`.
|
|
41
|
+
|
|
42
|
+
### With Vite+
|
|
43
|
+
If you use [Vite+](https://viteplus.dev/config), put the same configs in the `lint` and `fmt` blocks of `vite.config.ts`:
|
|
44
|
+
```js
|
|
45
|
+
import { format, lint } from '@mouse_484/oxc-config'
|
|
46
|
+
import { defineConfig } from 'vite-plus'
|
|
47
|
+
|
|
48
|
+
export default defineConfig({
|
|
49
|
+
lint: lint(
|
|
50
|
+
{
|
|
51
|
+
// custom options
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
// oxlint config
|
|
55
|
+
}
|
|
56
|
+
),
|
|
57
|
+
fmt: format(
|
|
58
|
+
{
|
|
59
|
+
// oxfmt config
|
|
60
|
+
}
|
|
61
|
+
),
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
28
65
|
## Features
|
|
29
|
-
See [configs](https://github.com/mouse484/config/tree/main/packages/oxc/src/configs) for all available presets and options.
|
|
66
|
+
See [configs](https://github.com/mouse484/config/tree/main/packages/oxc/src/configs) for all available presets and options.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mouse_484/oxc-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"author": "mouse_484",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/mouse484/config/tree/main/packages/oxc",
|
|
@@ -18,11 +18,10 @@
|
|
|
18
18
|
"typegen": "node scripts/typegen.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@stylistic/eslint-plugin": "^5.10.0",
|
|
22
21
|
"eslint-plugin-antfu": "^3.2.3",
|
|
23
|
-
"eslint-plugin-better-tailwindcss": "^4.8.0",
|
|
24
22
|
"eslint-plugin-perfectionist": "^5.12.1",
|
|
25
23
|
"local-pkg": "^1.2.1",
|
|
24
|
+
"oxfmt": "^0.72.0",
|
|
26
25
|
"oxlint": "^1.87.0",
|
|
27
26
|
"oxlint-tsgolint": "^7.0.2003"
|
|
28
27
|
},
|
package/src/configs/import.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import perfectionist from 'eslint-plugin-perfectionist'
|
|
2
1
|
import { createConfigs } from '../lib/factory.js'
|
|
3
2
|
|
|
4
3
|
export default createConfigs({
|
|
@@ -8,7 +7,11 @@ export default createConfigs({
|
|
|
8
7
|
{
|
|
9
8
|
jsPlugins: ['eslint-plugin-perfectionist'],
|
|
10
9
|
rules: {
|
|
11
|
-
|
|
10
|
+
// `sort-imports` is handled by oxfmt (`sortImports`)
|
|
11
|
+
'perfectionist/sort-imports': 'off',
|
|
12
|
+
'perfectionist/sort-named-imports': ['error', { type: 'natural', order: 'asc' }],
|
|
13
|
+
'perfectionist/sort-named-exports': ['error', { type: 'natural', order: 'asc' }],
|
|
14
|
+
'perfectionist/sort-exports': ['error', { type: 'natural', order: 'asc' }],
|
|
12
15
|
},
|
|
13
16
|
},
|
|
14
17
|
{
|
package/src/configs/index.d.ts
CHANGED
|
@@ -23,19 +23,6 @@ export interface Options {
|
|
|
23
23
|
* @default true
|
|
24
24
|
*/
|
|
25
25
|
import?: boolean
|
|
26
|
-
/**
|
|
27
|
-
* `stylistic` option
|
|
28
|
-
* @default true
|
|
29
|
-
*/
|
|
30
|
-
stylistic?: boolean
|
|
31
|
-
/**
|
|
32
|
-
* `tailwind` option
|
|
33
|
-
* @default false
|
|
34
|
-
* @options {
|
|
35
|
-
* entryPoint: 'src/global.css',
|
|
36
|
-
* }
|
|
37
|
-
*/
|
|
38
|
-
tailwind?: boolean | { entryPoint: string } | undefined
|
|
39
26
|
/**
|
|
40
27
|
* `tanstack` option
|
|
41
28
|
* @default true
|
package/src/configs/index.js
CHANGED
|
@@ -6,8 +6,6 @@ import node from './node.js'
|
|
|
6
6
|
import opinionated from './opinionated.js'
|
|
7
7
|
import oxc from './oxc.js'
|
|
8
8
|
import react from './react.js'
|
|
9
|
-
import stylistic from './stylistic.js'
|
|
10
|
-
import tailwind from './tailwind.js'
|
|
11
9
|
import tanstack from './tanstack.js'
|
|
12
10
|
import typescript from './typescript.js'
|
|
13
11
|
import unicorn from './unicorn.js'
|
|
@@ -18,8 +16,6 @@ const CONFIGS = /** @type {const} */[
|
|
|
18
16
|
opinionated,
|
|
19
17
|
oxc,
|
|
20
18
|
importConfig,
|
|
21
|
-
stylistic,
|
|
22
|
-
tailwind,
|
|
23
19
|
tanstack,
|
|
24
20
|
typescript,
|
|
25
21
|
react,
|
package/src/format.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const DEFAULT_FORMAT = /** @type {import('oxfmt').OxfmtConfig} */ ({
|
|
2
|
+
printWidth: 120,
|
|
3
|
+
semi: false,
|
|
4
|
+
singleQuote: true,
|
|
5
|
+
sortImports: true,
|
|
6
|
+
tabWidth: 2,
|
|
7
|
+
trailingComma: 'all',
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create an `oxfmt` config with the defaults of this config.
|
|
12
|
+
* Formatting rules are not provided by `lint()`, so use this for your formatting.
|
|
13
|
+
* @param {import('oxfmt').OxfmtConfig} [config]
|
|
14
|
+
*/
|
|
15
|
+
export function format(config = {}) {
|
|
16
|
+
return { ...DEFAULT_FORMAT, ...config }
|
|
17
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import type { OxfmtConfig } from 'oxfmt'
|
|
1
2
|
import type { OxlintConfig } from 'oxlint'
|
|
2
3
|
import type { Options } from './configs'
|
|
3
4
|
|
|
4
5
|
declare function lint(options: Options, config?: OxlintConfig): OxlintConfig
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
declare function format(config?: OxfmtConfig): OxfmtConfig
|
|
8
|
+
|
|
9
|
+
export { format, lint }
|
|
7
10
|
export { type Options } from './configs'
|
package/src/index.js
CHANGED
|
@@ -1,64 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const DEFAULT_CATEGORIES = {
|
|
4
|
-
correctness: 'error',
|
|
5
|
-
suspicious: 'warn',
|
|
6
|
-
pedantic: 'warn',
|
|
7
|
-
perf: 'warn',
|
|
8
|
-
style: 'warn',
|
|
9
|
-
restriction: 'warn',
|
|
10
|
-
nursery: 'warn',
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const OBJECT_KEYS = ['settings', 'env', 'globals', 'options']
|
|
14
|
-
const ARRAY_KEYS = ['ignorePatterns']
|
|
15
|
-
const HOISTED_KEYS = [...OBJECT_KEYS, ...ARRAY_KEYS, 'categories']
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
@type {import('.').lint}
|
|
19
|
-
*/
|
|
20
|
-
export function lint(options, config = {}) {
|
|
21
|
-
const all = [...buildConfigs(options), config]
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
@type {Record<string, any>}
|
|
25
|
-
*/
|
|
26
|
-
const root = {
|
|
27
|
-
categories: { ...DEFAULT_CATEGORIES, ...config.categories },
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
for (const item of all) {
|
|
31
|
-
for (const key of OBJECT_KEYS) {
|
|
32
|
-
// @ts-expect-error - hoisted keys are not part of the OxlintConfig index signature
|
|
33
|
-
// eslint-disable-next-line ts/no-unsafe-assignment
|
|
34
|
-
const value = item[key]
|
|
35
|
-
if (value !== undefined) {
|
|
36
|
-
// eslint-disable-next-line ts/no-unsafe-assignment
|
|
37
|
-
root[key] = { ...root[key], ...value }
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
for (const key of ARRAY_KEYS) {
|
|
41
|
-
// @ts-expect-error - hoisted keys are not part of the OxlintConfig index signature
|
|
42
|
-
// eslint-disable-next-line ts/no-unsafe-assignment
|
|
43
|
-
const value = item[key]
|
|
44
|
-
if (value !== undefined) {
|
|
45
|
-
// eslint-disable-next-line ts/no-unsafe-assignment
|
|
46
|
-
root[key] = [...new Set([...(root[key] ?? []), ...value])]
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
...root,
|
|
53
|
-
extends: all
|
|
54
|
-
.map((item) => {
|
|
55
|
-
const rest = { ...item }
|
|
56
|
-
for (const key of HOISTED_KEYS) {
|
|
57
|
-
// @ts-expect-error - delete hoisted keys
|
|
58
|
-
delete rest[key]
|
|
59
|
-
}
|
|
60
|
-
return rest
|
|
61
|
-
})
|
|
62
|
-
.filter(item => Object.keys(item).length > 0),
|
|
63
|
-
}
|
|
64
|
-
}
|
|
1
|
+
export { format } from './format.js'
|
|
2
|
+
export { lint } from './lint.js'
|
package/src/lint.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import buildConfigs from './configs/index.js'
|
|
2
|
+
|
|
3
|
+
const DEFAULT_CATEGORIES = {
|
|
4
|
+
correctness: 'error',
|
|
5
|
+
suspicious: 'warn',
|
|
6
|
+
pedantic: 'warn',
|
|
7
|
+
perf: 'warn',
|
|
8
|
+
style: 'warn',
|
|
9
|
+
restriction: 'warn',
|
|
10
|
+
nursery: 'warn',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const OBJECT_KEYS = ['settings', 'env', 'globals', 'options']
|
|
14
|
+
const ARRAY_KEYS = ['ignorePatterns']
|
|
15
|
+
const HOISTED_KEYS = [...OBJECT_KEYS, ...ARRAY_KEYS, 'categories']
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
@type {import('.').lint}
|
|
19
|
+
*/
|
|
20
|
+
export function lint(options, config = {}) {
|
|
21
|
+
const all = [...buildConfigs(options), config]
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
@type {Record<string, any>}
|
|
25
|
+
*/
|
|
26
|
+
const root = {
|
|
27
|
+
categories: { ...DEFAULT_CATEGORIES, ...config.categories },
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (const item of all) {
|
|
31
|
+
for (const key of OBJECT_KEYS) {
|
|
32
|
+
// @ts-expect-error - hoisted keys are not part of the OxlintConfig index signature
|
|
33
|
+
// eslint-disable-next-line ts/no-unsafe-assignment
|
|
34
|
+
const value = item[key]
|
|
35
|
+
if (value !== undefined) {
|
|
36
|
+
// eslint-disable-next-line ts/no-unsafe-assignment
|
|
37
|
+
root[key] = { ...root[key], ...value }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
for (const key of ARRAY_KEYS) {
|
|
41
|
+
// @ts-expect-error - hoisted keys are not part of the OxlintConfig index signature
|
|
42
|
+
// eslint-disable-next-line ts/no-unsafe-assignment
|
|
43
|
+
const value = item[key]
|
|
44
|
+
if (value !== undefined) {
|
|
45
|
+
// eslint-disable-next-line ts/no-unsafe-assignment
|
|
46
|
+
root[key] = [...new Set([...(root[key] ?? []), ...value])]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
...root,
|
|
53
|
+
extends: all
|
|
54
|
+
.map((item) => {
|
|
55
|
+
const rest = { ...item }
|
|
56
|
+
for (const key of HOISTED_KEYS) {
|
|
57
|
+
// @ts-expect-error - delete hoisted keys
|
|
58
|
+
delete rest[key]
|
|
59
|
+
}
|
|
60
|
+
return rest
|
|
61
|
+
})
|
|
62
|
+
.filter(item => Object.keys(item).length > 0),
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/configs/stylistic.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import stylistic from '@stylistic/eslint-plugin'
|
|
2
|
-
import { createConfigs } from '../lib/factory.js'
|
|
3
|
-
|
|
4
|
-
const { rules } = stylistic.configs.customize({
|
|
5
|
-
indent: 2,
|
|
6
|
-
quotes: 'single',
|
|
7
|
-
semi: false,
|
|
8
|
-
jsx: true,
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
export default createConfigs ({
|
|
12
|
-
name: 'stylistic',
|
|
13
|
-
enable: true,
|
|
14
|
-
configs: [
|
|
15
|
-
{
|
|
16
|
-
jsPlugins: ['@stylistic/eslint-plugin'],
|
|
17
|
-
rules,
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
})
|
package/src/configs/tailwind.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import eslintPluginBetterTailwindcss from 'eslint-plugin-better-tailwindcss'
|
|
2
|
-
import { createConfigs } from '../lib/factory.js'
|
|
3
|
-
|
|
4
|
-
export default createConfigs({
|
|
5
|
-
name: 'tailwind',
|
|
6
|
-
enable: false,
|
|
7
|
-
// enable: ({ isPackageExists }) => isPackageExists('tailwindcss'),
|
|
8
|
-
options: {
|
|
9
|
-
entryPoint: 'src/global.css',
|
|
10
|
-
},
|
|
11
|
-
configs: [
|
|
12
|
-
({ options: { entryPoint } }) => ({
|
|
13
|
-
jsPlugins: [
|
|
14
|
-
'eslint-plugin-better-tailwindcss',
|
|
15
|
-
],
|
|
16
|
-
rules: {
|
|
17
|
-
...eslintPluginBetterTailwindcss.configs.recommended.rules,
|
|
18
|
-
'better-tailwindcss/no-unknown-classes': ['error', {
|
|
19
|
-
detectComponentClasses: true,
|
|
20
|
-
}],
|
|
21
|
-
},
|
|
22
|
-
settings: {
|
|
23
|
-
'better-tailwindcss': {
|
|
24
|
-
entryPoint,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
}),
|
|
28
|
-
],
|
|
29
|
-
})
|