|
| 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 | +} |
0 commit comments