Skip to content

Commit ab96fd2

Browse files
committed
feat: add eslint-plugin-yml plugin
1 parent 5bc16d9 commit ab96fd2

File tree

7 files changed

+139
-0
lines changed

7 files changed

+139
-0
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"eslint-plugin-unicorn": "^57.0.0",
102102
"eslint-plugin-unused-imports": "^4.1.4",
103103
"eslint-plugin-vue": "^10.0.0",
104+
"eslint-plugin-yml": "^1.17.0",
104105
"eslint-typegen": "^2.0.0",
105106
"globals": "^16.0.0",
106107
"jsonc-eslint-parser": "^2.4.0",
@@ -110,6 +111,7 @@
110111
"prettier": "^3.5.3",
111112
"prompts": "^2.4.2",
112113
"vue-eslint-parser": "^9.4.3",
114+
"yaml-eslint-parser": "^1.3.0",
113115
"yargs": "^17.7.2"
114116
},
115117
"devDependencies": {

pnpm-lock.yaml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/configs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ export * from './typescript'
2020
export * from './unicorn'
2121
export * from './unocss'
2222
export * from './vue'
23+
export * from './yaml'

src/configs/sort.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export function sortPackageJson(): TypedFlatConfigItem[] {
6464
'husky',
6565
'simple-git-hooks',
6666
'lint-staged',
67+
'nano-staged',
6768
'eslintConfig',
6869
],
6970
pathPattern: '^$',

src/configs/yaml.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { GLOB_YAML } from '../constants/glob'
2+
import { interopDefault } from '../shared'
3+
4+
import type {
5+
OptionsFiles,
6+
OptionsOverrides,
7+
TypedFlatConfigItem,
8+
} from '../types'
9+
10+
export async function yaml(
11+
options: OptionsOverrides & OptionsFiles = {},
12+
): Promise<TypedFlatConfigItem[]> {
13+
const { files = [GLOB_YAML], overrides = {} } = options
14+
15+
const [pluginYaml, parserYaml] = await Promise.all([
16+
interopDefault(import('eslint-plugin-yml')),
17+
interopDefault(import('yaml-eslint-parser')),
18+
] as const)
19+
20+
return [
21+
{
22+
name: 'coderwyd/yaml/setup',
23+
plugins: {
24+
yaml: pluginYaml,
25+
},
26+
},
27+
{
28+
files,
29+
languageOptions: {
30+
parser: parserYaml,
31+
},
32+
name: 'coderwyd/yaml/rules',
33+
rules: {
34+
'yaml/block-mapping': 'error',
35+
'yaml/block-sequence': 'error',
36+
'yaml/no-empty-key': 'error',
37+
'yaml/no-empty-sequence-entry': 'error',
38+
'yaml/no-irregular-whitespace': 'error',
39+
'yaml/plain-scalar': 'error',
40+
41+
'yaml/vue-custom-block/no-parsing-error': 'error',
42+
43+
...overrides,
44+
},
45+
},
46+
{
47+
files: ['pnpm-workspace.yaml'],
48+
name: 'coderwyd/yaml/pnpm-workspace',
49+
rules: {
50+
'yaml/sort-keys': [
51+
'error',
52+
{
53+
order: [
54+
'packages',
55+
'overrides',
56+
'patchedDependencies',
57+
'hoistPattern',
58+
'catalog',
59+
'catalogs',
60+
61+
'allowedDeprecatedVersions',
62+
'allowNonAppliedPatches',
63+
'configDependencies',
64+
'ignoredBuiltDependencies',
65+
'ignoredOptionalDependencies',
66+
'neverBuiltDependencies',
67+
'onlyBuiltDependencies',
68+
'onlyBuiltDependenciesFile',
69+
'packageExtensions',
70+
'peerDependencyRules',
71+
'supportedArchitectures',
72+
],
73+
pathPattern: '^$',
74+
},
75+
{
76+
order: { type: 'asc' },
77+
pathPattern: '.*',
78+
},
79+
],
80+
},
81+
},
82+
]
83+
}

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
unicorn,
2424
unocss,
2525
vue,
26+
yaml,
2627
} from './configs'
2728
import { isUsingTypeScript, isUsingVue } from './env'
2829
import {
@@ -222,6 +223,16 @@ export async function defineConfig(
222223
)
223224
}
224225

226+
227+
228+
if (options.yaml ?? true) {
229+
configs.push(
230+
yaml({
231+
overrides: getOverrides(options, 'yaml'),
232+
}),
233+
)
234+
}
235+
225236
configs.push(specials(), prettier())
226237

227238
if ('files' in options) {

src/types/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ export interface OptionsConfig extends OptionsComponentExts {
146146
*/
147147
jsonc?: boolean | OptionsOverrides
148148

149+
/**
150+
* Enable YAML support.
151+
*
152+
* @default true
153+
*/
154+
yaml?: boolean | OptionsOverrides
155+
149156
/**
150157
* Enable react rules.
151158
*
@@ -185,6 +192,8 @@ export interface OptionsConfig extends OptionsComponentExts {
185192
*/
186193
unocss?: boolean | OptionsUnoCSS
187194

195+
196+
188197
/**
189198
* Enable regexp rules.
190199
*

0 commit comments

Comments
 (0)