123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- import type { Linter } from 'eslint';
- export async function jsonc(): Promise<Linter.FlatConfig[]> {
- const [pluginJsonc, parserJsonc] = await Promise.all([
- import('eslint-plugin-jsonc'),
- import('jsonc-eslint-parser'),
- ] as const);
- return [
- {
- files: ['**/*.json', '**/*.json5', '**/*.jsonc', '*.code-workspace'],
- languageOptions: {
- parser: parserJsonc as any,
- },
- plugins: {
- jsonc: pluginJsonc as any,
- },
- rules: {
- 'jsonc/no-bigint-literals': 'error',
- 'jsonc/no-binary-expression': 'error',
- 'jsonc/no-binary-numeric-literals': 'error',
- 'jsonc/no-dupe-keys': 'error',
- 'jsonc/no-escape-sequence-in-identifier': 'error',
- 'jsonc/no-floating-decimal': 'error',
- 'jsonc/no-hexadecimal-numeric-literals': 'error',
- 'jsonc/no-infinity': 'error',
- 'jsonc/no-multi-str': 'error',
- 'jsonc/no-nan': 'error',
- 'jsonc/no-number-props': 'error',
- 'jsonc/no-numeric-separators': 'error',
- 'jsonc/no-octal': 'error',
- 'jsonc/no-octal-escape': 'error',
- 'jsonc/no-octal-numeric-literals': 'error',
- 'jsonc/no-parenthesized': 'error',
- 'jsonc/no-plus-sign': 'error',
- 'jsonc/no-regexp-literals': 'error',
- 'jsonc/no-sparse-arrays': 'error',
- 'jsonc/no-template-literals': 'error',
- 'jsonc/no-undefined-value': 'error',
- 'jsonc/no-unicode-codepoint-escapes': 'error',
- 'jsonc/no-useless-escape': 'error',
- 'jsonc/space-unary-ops': 'error',
- 'jsonc/valid-json-number': 'error',
- 'jsonc/vue-custom-block/no-parsing-error': 'error',
- },
- },
- sortTsconfig(),
- sortPackageJson(),
- ];
- }
- function sortPackageJson(): Linter.FlatConfig {
- return {
- files: ['**/package.json'],
- rules: {
- 'jsonc/sort-array-values': [
- 'error',
- {
- order: { type: 'asc' },
- pathPattern: '^files$|^pnpm.neverBuiltDependencies$',
- },
- ],
- 'jsonc/sort-keys': [
- 'error',
- {
- order: [
- 'publisher',
- 'name',
- 'description',
- 'version',
- 'author',
- 'private',
- 'displayName',
- 'type',
- 'license',
- 'funding',
- 'homepage',
- 'repository',
- 'bugs',
- 'keywords',
- 'categories',
- 'scripts',
- 'files',
- 'sideEffects',
- 'bin',
- 'main',
- 'module',
- 'unpkg',
- 'jsdelivr',
- 'types',
- 'typesVersions',
- 'imports',
- 'exports',
- 'publishConfig',
- 'icon',
- 'activationEvents',
- 'contributes',
- 'peerDependencies',
- 'peerDependenciesMeta',
- 'dependencies',
- 'optionalDependencies',
- 'devDependencies',
- 'engines',
- 'packageManager',
- 'pnpm',
- 'overrides',
- 'resolutions',
- 'husky',
- 'simple-git-hooks',
- 'lint-staged',
- 'eslintConfig',
- ],
- pathPattern: '^$',
- },
- {
- order: { type: 'asc' },
- pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$',
- },
- {
- order: { type: 'asc' },
- pathPattern: '^(?:resolutions|overrides|pnpm.overrides)$',
- },
- {
- order: ['types', 'import', 'require', 'default'],
- pathPattern: '^exports.*$',
- },
- ],
- },
- };
- }
- function sortTsconfig(): Linter.FlatConfig {
- return {
- files: [
- '**/tsconfig.json',
- '**/tsconfig.*.json',
- 'internal/tsconfig/*.json',
- ],
- rules: {
- 'jsonc/sort-keys': [
- 'error',
- {
- order: [
- 'extends',
- 'compilerOptions',
- 'references',
- 'files',
- 'include',
- 'exclude',
- ],
- pathPattern: '^$',
- },
- {
- order: [
- /* Projects */
- 'incremental',
- 'composite',
- 'tsBuildInfoFile',
- 'disableSourceOfProjectReferenceRedirect',
- 'disableSolutionSearching',
- 'disableReferencedProjectLoad',
- /* Language and Environment */
- 'target',
- 'jsx',
- 'jsxFactory',
- 'jsxFragmentFactory',
- 'jsxImportSource',
- 'lib',
- 'moduleDetection',
- 'noLib',
- 'reactNamespace',
- 'useDefineForClassFields',
- 'emitDecoratorMetadata',
- 'experimentalDecorators',
- /* Modules */
- 'baseUrl',
- 'rootDir',
- 'rootDirs',
- 'customConditions',
- 'module',
- 'moduleResolution',
- 'moduleSuffixes',
- 'noResolve',
- 'paths',
- 'resolveJsonModule',
- 'resolvePackageJsonExports',
- 'resolvePackageJsonImports',
- 'typeRoots',
- 'types',
- 'allowArbitraryExtensions',
- 'allowImportingTsExtensions',
- 'allowUmdGlobalAccess',
- /* JavaScript Support */
- 'allowJs',
- 'checkJs',
- 'maxNodeModuleJsDepth',
- /* Type Checking */
- 'strict',
- 'strictBindCallApply',
- 'strictFunctionTypes',
- 'strictNullChecks',
- 'strictPropertyInitialization',
- 'allowUnreachableCode',
- 'allowUnusedLabels',
- 'alwaysStrict',
- 'exactOptionalPropertyTypes',
- 'noFallthroughCasesInSwitch',
- 'noImplicitAny',
- 'noImplicitOverride',
- 'noImplicitReturns',
- 'noImplicitThis',
- 'noPropertyAccessFromIndexSignature',
- 'noUncheckedIndexedAccess',
- 'noUnusedLocals',
- 'noUnusedParameters',
- 'useUnknownInCatchVariables',
- /* Emit */
- 'declaration',
- 'declarationDir',
- 'declarationMap',
- 'downlevelIteration',
- 'emitBOM',
- 'emitDeclarationOnly',
- 'importHelpers',
- 'importsNotUsedAsValues',
- 'inlineSourceMap',
- 'inlineSources',
- 'mapRoot',
- 'newLine',
- 'noEmit',
- 'noEmitHelpers',
- 'noEmitOnError',
- 'outDir',
- 'outFile',
- 'preserveConstEnums',
- 'preserveValueImports',
- 'removeComments',
- 'sourceMap',
- 'sourceRoot',
- 'stripInternal',
- /* Interop Constraints */
- 'allowSyntheticDefaultImports',
- 'esModuleInterop',
- 'forceConsistentCasingInFileNames',
- 'isolatedModules',
- 'preserveSymlinks',
- 'verbatimModuleSyntax',
- /* Completeness */
- 'skipDefaultLibCheck',
- 'skipLibCheck',
- ],
- pathPattern: '^compilerOptions$',
- },
- ],
- },
- };
- }
|