feat: lint add yaml config

This commit is contained in:
xingyu4j
2025-12-03 16:01:27 +08:00
parent 6753834054
commit d42a9b2409
7 changed files with 128 additions and 2 deletions

View File

@@ -49,8 +49,10 @@
"eslint-plugin-unused-imports": "catalog:",
"eslint-plugin-vitest": "catalog:",
"eslint-plugin-vue": "catalog:",
"eslint-plugin-yml": "catalog:",
"globals": "catalog:",
"jsonc-eslint-parser": "catalog:",
"vue-eslint-parser": "catalog:"
"vue-eslint-parser": "catalog:",
"yaml-eslint-parser": "catalog:"
}
}

View File

@@ -46,6 +46,8 @@ export async function ignores(): Promise<Linter.Config[]> {
'**/*.sh',
'**/*.ttf',
'**/*.woff',
'**/.github',
'**/lefthook.yml',
],
},
];

View File

@@ -15,3 +15,4 @@ export * from './turbo';
export * from './typescript';
export * from './unicorn';
export * from './vue';
export * from './yaml';

View File

@@ -0,0 +1,87 @@
import type { Linter } from 'eslint';
import { interopDefault } from '../util';
export async function yaml(): Promise<Linter.Config[]> {
const [pluginYaml, parserYaml] = await Promise.all([
interopDefault(import('eslint-plugin-yml')),
interopDefault(import('yaml-eslint-parser')),
] as const);
return [
{
files: ['**/*.y?(a)ml'],
plugins: {
yaml: pluginYaml as any,
},
languageOptions: {
parser: parserYaml,
},
rules: {
'style/spaced-comment': 'off',
'yaml/block-mapping': 'error',
'yaml/block-sequence': 'error',
'yaml/no-empty-key': 'error',
'yaml/no-empty-sequence-entry': 'error',
'yaml/no-irregular-whitespace': 'error',
'yaml/plain-scalar': 'error',
'yaml/vue-custom-block/no-parsing-error': 'error',
'yaml/block-mapping-question-indicator-newline': 'error',
'yaml/block-sequence-hyphen-indicator-newline': 'error',
'yaml/flow-mapping-curly-newline': 'error',
'yaml/flow-mapping-curly-spacing': 'error',
'yaml/flow-sequence-bracket-newline': 'error',
'yaml/flow-sequence-bracket-spacing': 'error',
'yaml/indent': ['error', 2],
'yaml/key-spacing': 'error',
'yaml/no-tab-indent': 'error',
'yaml/quotes': [
'error',
{
avoidEscape: true,
prefer: 'single',
},
],
'yaml/spaced-comment': 'error',
},
},
{
files: ['pnpm-workspace.yaml'],
rules: {
'yaml/sort-keys': [
'error',
{
order: [
'packages',
'overrides',
'patchedDependencies',
'hoistPattern',
'catalog',
'catalogs',
'allowedDeprecatedVersions',
'allowNonAppliedPatches',
'configDependencies',
'ignoredBuiltDependencies',
'ignoredOptionalDependencies',
'neverBuiltDependencies',
'onlyBuiltDependencies',
'onlyBuiltDependenciesFile',
'packageExtensions',
'peerDependencyRules',
'supportedArchitectures',
],
pathPattern: '^$',
},
{
order: { type: 'asc' },
pathPattern: '.*',
},
],
},
},
];
}

View File

@@ -18,6 +18,7 @@ import {
typescript,
unicorn,
vue,
yaml,
} from './configs';
import { customConfig } from './custom-config';
@@ -48,6 +49,7 @@ async function defineConfig(config: FlatConfig[] = []) {
regexp(),
command(),
turbo(),
yaml(),
...customConfig,
...config,
];