UNPKG

@minko-fe/eslint-config

Version:
1,111 lines (1,090 loc) 33.5 kB
import * as _pluginAntfu from 'eslint-plugin-antfu'; import * as _pluginComments from 'eslint-plugin-eslint-comments'; import * as _pluginMarkdown from 'eslint-plugin-markdown'; import * as _pluginUnicorn from 'eslint-plugin-unicorn'; import default2 from 'eslint-plugin-vue'; export { default as pluginVue } from 'eslint-plugin-vue'; import * as parserVue from 'vue-eslint-parser'; export { parserVue }; import * as _pluginReact from 'eslint-plugin-react'; import * as _pluginReactHooks from 'eslint-plugin-react-hooks'; import * as pluginImport from 'eslint-plugin-import-x'; export { pluginImport }; import * as pluginJsonc from 'eslint-plugin-jsonc'; export { pluginJsonc }; import * as _pluginPerfectionist from 'eslint-plugin-perfectionist'; import * as _pluginUnusedImports from 'eslint-plugin-unused-imports'; import * as pluginYml from 'eslint-plugin-yml'; export { pluginYml }; import * as parserJsonc from 'jsonc-eslint-parser'; export { parserJsonc }; import * as parserYml from 'yaml-eslint-parser'; export { parserYml }; import * as _pluginNode from 'eslint-plugin-n'; import default3 from 'eslint-plugin-prettier'; export { default as pluginPrettier } from 'eslint-plugin-prettier'; import default4 from 'eslint-plugin-prettier/recommended'; export { default as pluginPrettierRecommended } from 'eslint-plugin-prettier/recommended'; import default5 from 'typescript-eslint'; export { default as tseslint } from 'typescript-eslint'; import * as _pluginAstro from 'eslint-plugin-astro'; import * as _parserAstro from 'astro-eslint-parser'; import findUp from 'find-up'; import fs from 'node:fs'; import parseGitignore from 'parse-gitignore'; import globals from 'globals'; import { isPackageExists } from 'local-pkg'; import process2 from 'node:process'; import prettierConfig from '@minko-fe/prettier-config'; import { createConsola, LogLevels } from 'consola'; // utils/index.ts function interopDefault(m) { return "default" in m ? interopDefault(m.default) : m; } // configs/astro.ts async function resolveAstro() { const eslintPluginAstro = interopDefault(await import('eslint-plugin-astro')); return [...eslintPluginAstro.configs["flat/recommended"]]; } var pluginAntfu = interopDefault(_pluginAntfu); var pluginComments = interopDefault(_pluginComments); var pluginMarkdown = interopDefault(_pluginMarkdown); var pluginUnicorn = interopDefault(_pluginUnicorn); var pluginReact = interopDefault(_pluginReact); var pluginReactHooks = interopDefault(_pluginReactHooks); var pluginPerfectionist = interopDefault(_pluginPerfectionist); var pluginUnusedImports = interopDefault(_pluginUnusedImports); var pluginNode = interopDefault(_pluginNode); var pluginAstro = interopDefault(_pluginAstro); var parserAstro = interopDefault(_parserAstro); // configs/comments.ts var comments = () => [ { plugins: { "eslint-comments": pluginComments }, rules: { ...pluginComments.configs.recommended.rules, "eslint-comments/disable-enable-pair": "off", "eslint-comments/no-aggregating-enable": "error", "eslint-comments/no-duplicate-disable": "error", "eslint-comments/no-unlimited-disable": "off", "eslint-comments/no-unused-enable": "error" } } ]; // globs.ts var GLOB_SRC_EXT = "?([cm])[jt]s?(x)"; var GLOB_SRC = "**/*.?([cm])[jt]s?(x)"; var GLOB_JS = "**/*.?([cm])js"; var GLOB_JSX = "**/*.?([cm])jsx"; var GLOB_TS = "**/*.?([cm])ts"; var GLOB_TSX = "**/*.?([cm])tsx"; var GLOB_ASTRO = "**/*.astro"; var GLOB_SVELTE = ["**/*.svelte", "**/*.svelte.ts", "**/*.svelte.js"]; var GLOB_STYLE = "**/*.{c,le,sc}ss"; var GLOB_CSS = "**/*.css"; var GLOB_LESS = "**/*.less"; var GLOB_SCSS = "**/*.scss"; var GLOB_JSON = "**/*.json"; var GLOB_JSON5 = "**/*.json5"; var GLOB_JSONC = "**/*.jsonc"; var GLOB_MARKDOWN = "**/*.md"; var GLOB_VUE = "**/*.vue"; var GLOB_YAML = "**/*.y?(a)ml"; var GLOB_HTML = "**/*.htm?(l)"; var GLOB_ALL_SRC = ( /** @type {const} */ [ GLOB_SRC, GLOB_STYLE, GLOB_JSON, GLOB_JSON5, GLOB_MARKDOWN, GLOB_VUE, GLOB_YAML, GLOB_HTML ] ); var GLOB_TSCONFIG = ( /** @type {const} */ ["**/tsconfig.json", "**/tsconfig.*.json"] ); var GLOB_PACKAGEJSON = ( /** @type {const} */ "**/package.json" ); var GLOB_NODE_MODULES = ( /** @type {const} */ "**/node_modules" ); var GLOB_DIST = ( /** @type {const} */ "**/dist" ); var GLOB_LOCKFILE = ( /** @type {const} */ [ "**/package-lock.json", "**/yarn.lock", "**/pnpm-lock.yaml", "**/bun.lockb" ] ); var GLOB_EXCLUDE = ( /** @type {const} */ [ GLOB_NODE_MODULES, GLOB_DIST, ...GLOB_LOCKFILE, "**/public", "**/output", "**/coverage", "**/temp", "**/fixtures", "**/.vitepress/cache", "**/.next", "**/.nuxt", "**/.vercel", "**/.changeset", "**/.turbo", "**/.cache", "**/.tsup", "**/.idea", "**/.output", "**/.vite-inspect", "**/.astro", "**/.svelte-kit", "**/.react-router", "**/CHANGELOG*.md", "**/*.min.*", "**/LICENSE*", "**/__snapshots__", "**/auto-import?(s).d.ts", "**/components.d.ts" ] ); // configs/ignores.ts var parse = interopDefault(parseGitignore); function gitignore(options = {}) { const ignores2 = []; const { files: _files = ".gitignore" } = options; const files = Array.isArray(_files) ? _files : [_files]; for (const file of files) { const _file = findUp.sync(file); if (!_file) continue; const content = fs.readFileSync(_file, "utf8"); const parsed = parse(content); const globs = parsed.globs(); for (const glob of globs) { if (glob.type === "ignore") ignores2.push(...glob.patterns); else if (glob.type === "unignore") ignores2.push(...glob.patterns.map((pattern) => `!${pattern}`)); } } return { ignores: ignores2 }; } var ignores = () => [{ ignores: GLOB_EXCLUDE }]; var gitignores = [{ ignores: gitignore().ignores }]; // configs/imports.ts var imports = () => [ { plugins: { antfu: pluginAntfu, import: pluginImport }, rules: { "antfu/import-dedupe": "error", "import/first": "error", "import/namespace": "off", "import/no-absolute-path": "off", "import/no-default-export": "off", "import/no-duplicates": ["error"], "import/no-mutable-exports": "off", "import/no-named-default": "off", "import/no-self-import": "error", "import/no-unresolved": "off", "import/no-webpack-loader-syntax": "error", "import/order": "off" } }, { files: [ `**/src/${GLOB_SRC}`, `**/*config*.${GLOB_SRC_EXT}`, `**/{views,pages,routes,middleware,plugins,api}/${GLOB_SRC}`, `**/{index,vite,esbuild,rollup,rolldown,webpack,rspack}.ts`, "**/*.d.ts", `${GLOB_MARKDOWN}/**`, "**/.prettierrc*" ], plugins: { import: pluginImport }, rules: { "import/no-default-export": "off" } } ]; var isInEditor = !!((process2.env.VSCODE_PID || process2.env.VSCODE_CWD || process2.env.JETBRAINS_IDE || process2.env.VIM) && !process2.env.CI); var hasTypeScript = isPackageExists("typescript"); var hasVue = ["vue", "nuxt", "vitepress", "@slidev/cli"].some((t) => isPackageExists(t)); var hasReact = ["react", "next"].some((t) => isPackageExists(t)); var hasSvelte = ["svelte", "svelte-kit", "@sveltejs/kit"].some((t) => isPackageExists(t)); var hasSveltePrettier = isPackageExists("prettier-plugin-svelte"); var hasAstro = ["astro", "@astrojs/check"].some((t) => isPackageExists(t)); var hasAstroPrettier = isPackageExists("prettier-plugin-astro"); var hasTailwindcss = isPackageExists("tailwindcss"); var hasTailwindcssPrettire = isPackageExists("prettier-plugin-tailwindcss"); // configs/javascript.ts var javascript = () => [ { languageOptions: { globals: { ...globals.browser, ...globals.es2021, ...globals.node }, parserOptions: { ecmaFeatures: { jsx: true }, sourceType: "module" }, sourceType: "module" }, plugins: { "unused-imports": pluginUnusedImports }, rules: { "array-callback-return": "error", "block-scoped-var": "error", "consistent-return": "off", "constructor-super": "error", "dot-notation": "off", "eqeqeq": ["error", "smart"], "for-direction": "error", "getter-return": "error", "no-alert": "warn", "no-async-promise-executor": "off", "no-case-declarations": "error", "no-class-assign": "error", "no-compare-neg-zero": "error", "no-cond-assign": "error", "no-console": "off", "no-const-assign": "error", "no-constant-condition": "off", "no-control-regex": "error", "no-debugger": "warn", "no-delete-var": "error", "no-dupe-args": "error", "no-dupe-class-members": "error", "no-dupe-else-if": "error", "no-dupe-keys": "error", "no-duplicate-case": "error", "no-duplicate-imports": "off", "no-empty": ["error", { allowEmptyCatch: true }], "no-empty-character-class": "error", "no-empty-pattern": "off", "no-ex-assign": "error", "no-extra-boolean-cast": "error", "no-fallthrough": ["warn", { commentPattern: "break[\\s\\w]*omitted" }], "no-func-assign": "error", "no-global-assign": "error", "no-import-assign": "error", "no-inner-declarations": "off", "no-invalid-regexp": "error", "no-irregular-whitespace": "error", "no-lonely-if": "off", "no-loss-of-precision": "error", "no-misleading-character-class": "error", "no-mixed-spaces-and-tabs": "error", "no-multi-str": "error", "no-new-symbol": "error", "no-nonoctal-decimal-escape": "error", "no-obj-calls": "error", "no-octal": "error", "no-prototype-builtins": "error", "no-redeclare": "error", "no-regex-spaces": "error", "no-restricted-syntax": "off", "no-return-assign": "off", "no-return-await": "off", "no-self-assign": "error", "no-setter-return": "error", "no-shadow-restricted-names": "error", "no-sparse-arrays": "error", "no-this-before-super": "error", "no-undef": "error", "no-unexpected-multiline": "error", "no-unreachable": "error", "no-unsafe-finally": "error", "no-unsafe-negation": "error", "no-unsafe-optional-chaining": "error", "no-unused-expressions": [ "error", { allowShortCircuit: true, allowTaggedTemplates: true, allowTernary: true } ], "no-unused-labels": "error", "no-unused-vars": "off", "no-useless-backreference": "error", "no-useless-catch": "error", "no-useless-escape": "off", "no-var": "off", "no-void": "error", "no-with": "error", "object-shorthand": ["error", "always", { avoidQuotes: true, ignoreConstructors: false }], "operator-linebreak": "off", "prefer-arrow-callback": ["error", { allowNamedFunctions: false, allowUnboundThis: true }], "prefer-const": ["warn", { destructuring: "all", ignoreReadBeforeAssign: true }], "prefer-exponentiation-operator": "error", "prefer-regex-literals": ["error", { disallowRedundantWrapping: true }], "prefer-rest-params": "error", "prefer-spread": "error", "prefer-template": "error", "require-await": "off", "require-yield": "error", "unicode-bom": ["error", "never"], "unused-imports/no-unused-imports": isInEditor ? "warn" : "error", "unused-imports/no-unused-vars": [ "warn", { args: "after-used", argsIgnorePattern: "^_", destructuredArrayIgnorePattern: "^_", ignoreRestSiblings: true, varsIgnorePattern: "^_" } ], "use-isnan": ["error", { enforceForIndexOf: true, enforceForSwitchCase: true }], "valid-typeof": ["error", { requireStringLiterals: true }], "vars-on-top": "off", "wrap-iife": ["error", "any", { functionPrototypeMethods: true }] } }, { files: ["**/scripts/*", "**/cli.*"], rules: { "no-console": "off" } }, { files: ["**/*.{test,spec}.js?(x)"], rules: { "no-unused-expressions": "off" } } ]; // configs/jsonc.ts var jsonc = () => [ { files: [GLOB_JSON, GLOB_JSON5, GLOB_JSONC], languageOptions: { parser: parserJsonc }, plugins: { jsonc: pluginJsonc }, rules: { ...pluginJsonc.configs["recommended-with-jsonc"].rules, "jsonc/quote-props": "off", "jsonc/quotes": "off" } } ]; // configs/markdown.ts var markdown = () => [ ...pluginMarkdown.configs.recommended, { files: [`${GLOB_MARKDOWN}/${GLOB_SRC}`, `${GLOB_MARKDOWN}/${GLOB_VUE}`], rules: { "@typescript-eslint/comma-dangle": "off", "@typescript-eslint/consistent-type-imports": "off", "@typescript-eslint/no-extraneous-class": "off", "@typescript-eslint/no-invalid-void-type": "off", "@typescript-eslint/no-namespace": "off", "@typescript-eslint/no-redeclare": "off", "@typescript-eslint/no-require-imports": "off", "@typescript-eslint/no-unused-vars": "off", "@typescript-eslint/no-use-before-define": "off", "@typescript-eslint/no-var-requires": "off", "no-alert": "off", "no-console": "off", "no-restricted-imports": "off", "no-undef": "off", "no-unused-expressions": "off", "no-unused-vars": "off", "react/jsx-no-comment-textnodes": "off", "react/jsx-no-undef": "off", "unused-imports/no-unused-imports": "off", "unused-imports/no-unused-vars": "off" } } ]; // configs/node.ts var node = () => [ { plugins: { node: pluginNode }, rules: { "node/handle-callback-err": ["error", "^(err|error)$"], "node/no-deprecated-api": "off", "node/no-exports-assign": "error", "node/no-new-require": "error", "node/no-path-concat": "error", "node/no-unsupported-features/es-builtins": "error", "node/process-exit-as-throw": "error" } } ]; // configs/perfectionist.ts var sortImports = () => [ { plugins: { perfectionist: pluginPerfectionist }, rules: { "perfectionist/sort-imports": [ "error", { customGroups: { type: { react: ["react", "react-*"] }, value: { react: ["react", "react-*"] } }, groups: [ "type", "react", ["builtin", "external"], "internal-type", "internal", ["parent-type", "sibling-type", "index-type"], ["parent", "sibling", "index"], "style", "object", "unknown" ], internalPattern: ["^[~@#]/.*"], newlinesBetween: "never", order: "asc", type: "natural" } ], "perfectionist/sort-named-imports": [ "error", { order: "asc", type: "natural" } ] } } ]; var sortObjects = () => [ { files: [GLOB_SRC], plugins: { perfectionist: pluginPerfectionist }, rules: { "perfectionist/sort-objects": "error" } } ]; var rules = { ...default4.rules }; delete rules["vue/html-self-closing"]; delete rules["vue/html-closing-bracket-newline"]; var prettier = () => [ { plugins: { prettier: default3 }, rules: { ...rules, "prettier/prettier": ["warn", interopDefault(prettierConfig)] } } ]; // configs/react.ts var react = () => [ { files: [GLOB_JSX, GLOB_TSX], languageOptions: { ...pluginReact.configs.flat?.["jsx-runtime"].languageOptions, ecmaVersion: "latest", sourceType: "module" }, plugins: { ...pluginReact.configs.flat?.recommended.plugins }, rules: { ...pluginReact.configs.flat?.recommended.rules, ...pluginReact.configs.flat?.["jsx-runtime"].rules, "react/display-name": "off", "react/jsx-child-element-spacing": "off", "react/jsx-closing-tag-location": "off", "react/jsx-key": "off", "react/jsx-no-target-blank": "off", "react/no-danger": "off", "react/no-unescaped-entities": "off", "react/prop-types": "off", "react/react-in-jsx-scope": "off" }, settings: { react: { version: "detect" } } }, { files: [GLOB_JSX, GLOB_TSX], plugins: { "react-hooks": pluginReactHooks }, rules: { ...pluginReactHooks.configs.recommended.rules, "react-hooks/exhaustive-deps": "off" } } ]; // configs/sort.ts var sortPackageJson = () => [ { files: [GLOB_PACKAGEJSON], rules: { "jsonc/sort-array-values": [ "error", { order: { type: "asc" }, pathPattern: "^files$" } ], "jsonc/sort-keys": [ "error", { order: [ "name", "version", "private", "packageManager", "description", "type", "keywords", "license", "homepage", "bugs", "repository", "author", "contributors", "funding", "files", "main", "module", "types", "exports", "typesVersions", "sideEffects", "unpkg", "jsdelivr", "browser", "bin", "man", "directories", "publishConfig", "scripts", "peerDependencies", "peerDependenciesMeta", "optionalDependencies", "dependencies", "devDependencies", "engines", "config", "overrides", "pnpm", "husky", "lint-staged", "eslintConfig", "prettier" ], pathPattern: "^$" }, { order: { type: "asc" }, pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies$" }, { order: ["types", "require", "import", "default"], pathPattern: "^exports.*$" }, { order: { type: "asc" }, pathPattern: "^resolutions$" }, { order: { type: "asc" }, pathPattern: "^pnpm.overrides$" } ] } } ]; var sortTsconfig = () => [ { files: GLOB_TSCONFIG, 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", "lib", "jsx", "experimentalDecorators", "emitDecoratorMetadata", "jsxFactory", "jsxFragmentFactory", "jsxImportSource", "reactNamespace", "noLib", "useDefineForClassFields", "moduleDetection", /* Modules */ "module", "rootDir", "moduleResolution", "baseUrl", "paths", "rootDirs", "typeRoots", "types", "allowUmdGlobalAccess", "moduleSuffixes", "allowImportingTsExtensions", "resolvePackageJsonExports", "resolvePackageJsonImports", "customConditions", "resolveJsonModule", "allowArbitraryExtensions", "noResolve", /* JavaScript Support */ "allowJs", "checkJs", "maxNodeModuleJsDepth", /* Emit */ "declaration", "declarationMap", "emitDeclarationOnly", "sourceMap", "inlineSourceMap", "outFile", "outDir", "removeComments", "noEmit", "importHelpers", "importsNotUsedAsValues", "downlevelIteration", "sourceRoot", "mapRoot", "inlineSources", "emitBOM", "newLine", "stripInternal", "noEmitHelpers", "noEmitOnError", "preserveConstEnums", "declarationDir", "preserveValueImports", /* Interop Constraints */ "isolatedModules", "verbatimModuleSyntax", "allowSyntheticDefaultImports", "esModuleInterop", "preserveSymlinks", "forceConsistentCasingInFileNames", /* Type Checking */ "strict", "strictBindCallApply", "strictFunctionTypes", "strictNullChecks", "strictPropertyInitialization", "allowUnreachableCode", "allowUnusedLabels", "alwaysStrict", "exactOptionalPropertyTypes", "noFallthroughCasesInSwitch", "noImplicitAny", "noImplicitOverride", "noImplicitReturns", "noImplicitThis", "noPropertyAccessFromIndexSignature", "noUncheckedIndexedAccess", "noUnusedLocals", "noUnusedParameters", "useUnknownInCatchVariables", /* Completeness */ "skipDefaultLibCheck", "skipLibCheck" ], pathPattern: "^compilerOptions$" } ] } } ]; // configs/svelte.ts async function asyncSvelte() { const eslintPluginSvelte = await import('eslint-plugin-svelte'); return [ ...eslintPluginSvelte.configs.recommended, { files: GLOB_SVELTE, languageOptions: { parserOptions: { extraFileExtensions: [".svelte"], parser: default5.parser, projectService: true } } } ]; } // configs/typescript.ts var typescriptCore = default5.config({ extends: [...default5.configs.recommended], files: [GLOB_TS, GLOB_TSX], languageOptions: { parser: default5.parser, parserOptions: { sourceType: "module" } }, rules: { "@typescript-eslint/ban-ts-comment": "off", "@typescript-eslint/ban-ts-ignore": "off", "@typescript-eslint/ban-types": "off", "@typescript-eslint/brace-style": "off", "@typescript-eslint/comma-dangle": "off", "@typescript-eslint/consistent-indexed-object-style": "off", "@typescript-eslint/consistent-type-assertions": "off", "@typescript-eslint/consistent-type-definitions": "off", "@typescript-eslint/consistent-type-imports": [ "error", { disallowTypeAnnotations: false, fixStyle: "inline-type-imports" } ], "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/explicit-member-accessibility": "off", "@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/method-signature-style": ["error", "property"], // https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful "@typescript-eslint/naming-convention": [ "error", { custom: { match: false, // no $ prefix regex: "^\\$[a-zA-Z][\\w\\d]*$" }, format: null, selector: ["variable", "variableLike"] } ], "@typescript-eslint/no-dynamic-delete": "off", "@typescript-eslint/no-empty-function": "off", "@typescript-eslint/no-empty-interface": "off", "@typescript-eslint/no-empty-object-type": "off", "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-extra-semi": "off", "@typescript-eslint/no-extraneous-class": "off", "@typescript-eslint/no-floating-promises": "off", "@typescript-eslint/no-import-type-side-effects": "off", "@typescript-eslint/no-invalid-void-type": "off", "@typescript-eslint/no-namespace": "off", "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-redeclare": "error", "@typescript-eslint/no-require-imports": "off", "@typescript-eslint/no-unsafe-function-type": "off", "@typescript-eslint/no-unused-expressions": "off", // handled by unused-imports/no-unused-imports "@typescript-eslint/no-unused-vars": "off", "@typescript-eslint/no-use-before-define": "off", "@typescript-eslint/no-var-requires": "off", "@typescript-eslint/parameter-properties": "off", "@typescript-eslint/prefer-as-const": "warn", "@typescript-eslint/prefer-literal-enum-member": ["error", { allowBitwiseExpressions: true }], "@typescript-eslint/quotes": "off", "@typescript-eslint/semi": "off", "@typescript-eslint/triple-slash-reference": "off", "no-restricted-syntax": "off", "no-var": "off", "prefer-const": ["warn", { destructuring: "all", ignoreReadBeforeAssign: true }] } }); var typescript = () => [ ...typescriptCore, { files: ["**/*.d.ts"], rules: { "eslint-comments/no-unlimited-disable": "off", "import/no-duplicates": "off", "no-restricted-syntax": "off", "no-var": "off", "unused-imports/no-unused-vars": "off", "vars-on-top": "off" } }, { files: ["**/*.{test,spec}.ts?(x)"], rules: { "no-unused-expressions": "off" } }, { files: [GLOB_JS, "**/*.cjs"], rules: {} } ]; // configs/unicorn.ts var unicorn = () => [ { plugins: { unicorn: pluginUnicorn }, rules: { // Pass error message when throwing errors "unicorn/error-message": "error", // Uppercase regex escapes "unicorn/escape-case": "error", // Prevent deprecated `new Buffer()` "unicorn/no-new-buffer": "error", // Lowercase number formatting for octal, hex, binary (0x1'error' instead of 0X1'error') "unicorn/number-literal-case": "error", // Prefer using the node: protocol "unicorn/prefer-node-protocol": "error", // Prefer using number properties like `Number.isNaN` rather than `isNaN` "unicorn/prefer-number-properties": "error", // String methods startsWith/endsWith instead of more complicated stuff "unicorn/prefer-string-starts-ends-with": "error", // Enforce throwing type error when throwing error while checking typeof "unicorn/prefer-type-error": "error", // Use new when throwing error "unicorn/throw-new-error": "error" } } ]; // configs/vue.ts var reactivityTransform = [ { languageOptions: { globals: { $: "readonly", $$: "readonly", $computed: "readonly", $customRef: "readonly", $ref: "readonly", $shallowRef: "readonly", $toRef: "readonly" } }, plugins: { vue: default2 }, rules: { "vue/no-setup-props-reactivity-loss": "off" } } ]; var recommendedRules = default2.configs["flat/recommended"].map((c) => c.rules).reduce((acc, c) => ({ ...acc, ...c }), {}); var vueTs = typescriptCore.filter((config) => config.name !== "typescript-eslint/base").map((config) => { return { ...config, files: [GLOB_VUE] }; }); var vue = () => [ ...vueTs, { files: [GLOB_VUE], languageOptions: { parser: parserVue, parserOptions: { ecmaFeatures: { jsx: true }, extraFileExtensions: [".vue"], parser: default5.parser, sourceType: "module" } }, plugins: { "@typescript-eslint": default5.plugin, "vue": default2 }, processor: default2.processors[".vue"], rules: { ...recommendedRules, "vue/block-order": ["error", { order: ["script", "template", "style"] }], "vue/custom-event-name-casing": ["error", "camelCase"], "vue/eqeqeq": ["error", "smart"], "vue/html-self-closing": "off", "vue/max-attributes-per-line": "off", "vue/multi-word-component-names": "off", "vue/no-constant-condition": "warn", "vue/no-empty-pattern": "error", "vue/no-loss-of-precision": "error", "vue/no-unused-refs": "error", "vue/no-useless-v-bind": "error", "vue/no-v-html": "off", "vue/object-shorthand": [ "error", "always", { avoidQuotes: true, ignoreConstructors: false } ], "vue/one-component-per-file": "off", "vue/padding-line-between-blocks": ["error", "always"], "vue/prefer-template": "error", "vue/require-default-prop": "off", "vue/require-prop-types": "off", "vue/singleline-html-element-content-newline": "off" } }, ...reactivityTransform ]; // configs/yml.ts var yml = () => [ { files: [GLOB_YAML], languageOptions: { parser: parserYml }, plugins: { yml: pluginYml }, rules: { ...pluginYml.configs.standard.rules, ...pluginYml.configs.prettier.rules, "yml/no-empty-document": "off", "yml/no-empty-mapping-value": "off", "yml/quotes": "off" } } ]; var logger = createConsola({ level: process.env.ESLINT_DEBUG ? LogLevels.debug : LogLevels.box }); var logger_default = logger; // presets.ts var presetJavaScript = [...javascript(), ...comments(), ...imports(), ...unicorn(), ...node(), ...ignores()]; var presetJsonc = [...jsonc(), ...sortPackageJson()]; var presetTypescript = [...typescript(), ...sortTsconfig()]; async function defineConfig(config = [], { astro: enableAstro = hasAstro, gitignore: enableGitignore = true, jsonc: enableJsonc = true, markdown: enableMarkdown = true, prettier: enablePrettier = true, react: enableReact = hasReact, sortImports: enableSortImports = true, sortObjects: enableSortObjects = false, svelte: enableSvelte = hasSvelte, typescript: enableTypescript = hasTypeScript, vue: enableVue = hasVue, yml: enableYml = true } = {}) { const configs = []; configs.push(...presetJavaScript); if (enablePrettier && hasTailwindcss) { logger_default.debug("Tailwindcss enabled"); if (!hasTailwindcssPrettire) { logger_default.warn( '[@minko-fe/eslint-config] Tailwindcss detected but "prettier-plugin-tailwindcss" not found, please install it to enable Tailwindcss support.' ); } } if (enableGitignore) { logger_default.debug("Gitignore enabled"); configs.push(...gitignores); } if (enableTypescript) { logger_default.debug("TypeScript enabled"); configs.push(...presetTypescript); } if (enablePrettier) { logger_default.debug("Prettier enabled"); configs.push(...prettier()); } if (enableSortObjects) { logger_default.debug("Sort objects enabled"); configs.push(...sortObjects()); } if (enableSortImports) { logger_default.debug("Sort imports enabled"); configs.push(...sortImports()); } if (enableMarkdown) { logger_default.debug("Markdown enabled"); configs.push(...markdown()); } if (enableJsonc) { logger_default.debug("Jsonc enabled"); configs.push(...presetJsonc); } if (enableYml) { logger_default.debug("Yml enabled"); configs.push(...yml()); } if (enableReact) { logger_default.debug("React enabled"); configs.push(...react()); } if (enableVue) { logger_default.debug("Vue enabled"); configs.push(...vue()); } if (enableAstro) { logger_default.debug("Astro enabled"); if (!hasAstroPrettier) { logger_default.warn( '[@minko-fe/eslint-config] Astro detected but "prettier-plugin-astro" not found, please install it to enable Astro support.' ); } configs.push(...await resolveAstro()); } if (enableSvelte) { logger_default.debug("Svelte enabled"); if (!hasSveltePrettier) { logger_default.warn( '[@minko-fe/eslint-config] Svelte detected but "prettier-plugin-svelte" not found, please install it to enable Svelte support.' ); } configs.push(...await asyncSvelte()); } if (Object.keys(config).length > 0) { configs.push(...Array.isArray(config) ? config : [config]); } return configs; } export { GLOB_ALL_SRC, GLOB_ASTRO, GLOB_CSS, GLOB_DIST, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_LOCKFILE, GLOB_MARKDOWN, GLOB_NODE_MODULES, GLOB_PACKAGEJSON, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVELTE, GLOB_TS, GLOB_TSCONFIG, GLOB_TSX, GLOB_VUE, GLOB_YAML, asyncSvelte, comments, defineConfig, gitignores, hasAstro, hasAstroPrettier, hasReact, hasSvelte, hasSveltePrettier, hasTailwindcss, hasTailwindcssPrettire, hasTypeScript, hasVue, ignores, imports, isInEditor, javascript, jsonc, markdown, node, parserAstro, pluginAntfu, pluginAstro, pluginComments, pluginMarkdown, pluginNode, pluginPerfectionist, pluginReact, pluginReactHooks, pluginUnicorn, pluginUnusedImports, prettier, react, resolveAstro, sortImports, sortObjects, sortPackageJson, sortTsconfig, typescript, typescriptCore, unicorn, vue, yml };