"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { default: () => defineConfig }); module.exports = __toCommonJS(src_exports); // src/shared.ts var import_node_pkg = require("@anyions/node-pkg"); var import_eslint_flat_config_utils = require("eslint-flat-config-utils"); var defaultPluginRenaming = { "@typescript-eslint": "ts", "import-x": "import", n: "node" }; async function interopDefault(m) { const resolved = await m; return resolved.default || resolved; } function mergeProcessors(processors) { const cache = /* @__PURE__ */ new Map(); return { meta: { name: `merged-processor:${processors.map((processor) => processor.meta?.name || "unknown").join("+")}` }, supportsAutofix: true, preprocess(text, filename) { const counts = []; cache.set(filename, counts); return processors.flatMap((processor) => { const result = processor.preprocess?.(text, filename) || []; counts.push(result.length); return result; }); }, postprocess(messages, filename) { const counts = cache.get(filename); cache.delete(filename); let index = 0; return processors.flatMap((processor, idx) => { const msgs = messages.slice(index, index + counts[idx]); index += counts[idx]; return processor.postprocess?.(msgs, filename) || []; }); } }; } var processorPassThrough = { meta: { name: "pass-through" }, preprocess(text) { return [text]; }, postprocess(messages) { return messages[0]; } }; function toArray(value) { return Array.isArray(value) ? value : [value]; } // src/configs/comments.ts async function createCommentsConfig() { const pluginComments = await interopDefault(import("eslint-plugin-eslint-comments")); return [ { name: "@anyions/shared-config-eslint/comments/rules", plugins: { "eslint-comments": pluginComments }, rules: { "eslint-comments/no-aggregating-enable": "error", "eslint-comments/no-duplicate-disable": "error", "eslint-comments/no-unlimited-disable": "error", "eslint-comments/no-unused-enable": "error" } } ]; } // src/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_VUE = "**/*.vue"; var GLOB_HTML = "**/*.htm?(l)"; var GLOB_CSS = "**/*.css"; var GLOB_POSTCSS = "**/*.{p,post}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_MARKDOWN_IN_MARKDOWN = "**/*.md/*.md"; var GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`; var GLOB_PACKAGE_JSON = "**/package.json"; var GLOB_TS_CONFIG = "**/tsconfig.json"; var GLOB_TS_OTHER_CONFIG = "**/tsconfig.*.json"; var GLOB_TESTS = [ `**/__tests__/**/*.${GLOB_SRC_EXT}`, `**/*.spec.${GLOB_SRC_EXT}`, `**/*.test.${GLOB_SRC_EXT}`, `**/*.bench.${GLOB_SRC_EXT}`, `**/*.benchmark.${GLOB_SRC_EXT}` ]; var GLOB_EXCLUDES = [ "**/node_modules", "**/dist", "**/package-lock.json", "**/yarn.lock", "**/pnpm-lock.yaml", "**/bun.lockb", "**/output", "**/coverage", "**/temp", "**/.temp", "**/tmp", "**/.tmp", "**/.history", "**/.vitepress/cache", "**/.nuxt", "**/.next", "**/.vercel", "**/.changeset", "**/.idea", "**/.vscode", "**/.cache", "**/.output", "**/.vite-inspect", "**/CHANGELOG*.md", "**/*.min.*", "**/LICENSE*", "**/__snapshots__", "**/auto-import?(s).d.ts", "**/components.d.ts", "**/.github/workflows/*.yml" ]; // src/configs/formatter.ts var parserPlain = { meta: { name: "eslint-parser-plain" }, parseForESLint: (code) => ({ ast: { type: "Program", loc: { start: 0, end: code.length }, range: [0, code.length], body: [], comments: [], tokens: [] }, services: { isPlain: true }, scopeManager: null, visitorKeys: { Program: [] } }) }; async function createFormatterConfig(options = {}) { if (options === false) return []; const opts = options; const { html = true, css = true, json = true, markdown = true } = opts.formatters || {}; const prettierRules = opts.rules || {}; const pluginPrettier = await interopDefault(import("eslint-plugin-prettier")); function createPrettierFormatter(files, parser, plugins) { const rules = { ...prettierRules, ...parser === "markdown" ? { embeddedLanguageFormatting: "off" } : {}, parser }; if (plugins?.length) { rules.plugins = [...rules.plugins || [], ...plugins]; } const config = { name: `@anyions/shared-config-eslint/formatter-${parser}/rules`, files, languageOptions: { parser: parserPlain }, plugins: { prettier: pluginPrettier }, rules: { "prettier/prettier": ["warn", rules] } }; return config; } const configs = [ { name: "@anyions/shared-config-eslint/prettier/core", plugins: { prettier: pluginPrettier }, rules: { "prettier/prettier": ["warn", prettierRules], "arrow-body-style": "off", "prefer-arrow-callback": "off" } } ]; if (css) { const cssConfig = createPrettierFormatter([GLOB_CSS, GLOB_POSTCSS], "css"); const scssConfig = createPrettierFormatter([GLOB_SCSS], "scss"); const lessConfig = createPrettierFormatter([GLOB_LESS], "less"); configs.push(cssConfig, scssConfig, lessConfig); } if (html) { const htmlConfig = createPrettierFormatter([GLOB_HTML], "html"); configs.push(htmlConfig); } if (json) { const jsonConfig = createPrettierFormatter([GLOB_JSON, GLOB_JSONC], "json"); const json5Config = createPrettierFormatter([GLOB_JSON5], "json5"); configs.push(jsonConfig, json5Config); } if (markdown) { const markdownConfig = createPrettierFormatter([GLOB_MARKDOWN], "markdown"); configs.push(markdownConfig); } return configs; } // src/configs/ignores.ts async function createIgnoresConfig(ignores = [], flatignores = []) { const excludes = [...GLOB_EXCLUDES]; const ignore = await interopDefault(import("eslint-config-flat-gitignore")); if (flatignores.length > 0) { const config = ignore({ files: flatignores, strict: false }); excludes.push(...config.ignores); } return [ { name: "@anyions/shared-config-eslint/ignores/rules", ignores: [...excludes, ...ignores] } ]; } // src/configs/imports.ts async function createImportsConfig() { const pluginImport = await interopDefault(import("eslint-plugin-import-x")); const pluginUnusedImports = await interopDefault(import("eslint-plugin-unused-imports")); return [ { name: `@anyions/shared-config-eslint/imports/rules`, plugins: { import: pluginImport, "unused-imports": pluginUnusedImports }, rules: { "import/first": "error", "import/no-duplicates": "error", "import/no-mutable-exports": "error", "import/no-named-default": "error", "import/no-self-import": "error", "import/no-webpack-loader-syntax": "error", "import/newline-after-import": ["error", { count: 1 }], "import/order": [ "error", { groups: ["builtin", "external", "internal", "parent", "sibling", "index", "type", "object"], pathGroups: [ { group: "builtin", pattern: "{node:}**", position: "before" }, { group: "internal", pattern: "{{@,~}/,#}**", position: "before" } ], "newlines-between": "always", alphabetize: { order: "asc", orderImportKind: "asc", caseInsensitive: true } } ], "unused-imports/no-unused-imports": "warn", "unused-imports/no-unused-vars": [ "error", { args: "after-used", argsIgnorePattern: "^_", ignoreRestSiblings: true, vars: "all", varsIgnorePattern: "^_" } ] } } ]; } // src/configs/javascript.ts var import_globals = __toESM(require("globals"), 1); async function createJavascriptConfig(options = {}) { const { overrides = {} } = options; const pluginUnusedImports = await interopDefault(import("eslint-plugin-unused-imports")); return [ { name: `@anyions/shared-config-eslint/javascript/rules`, languageOptions: { ecmaVersion: 2022, globals: { ...import_globals.default.browser, ...import_globals.default.es2021, ...import_globals.default.node, document: "readonly", navigator: "readonly", window: "readonly" }, parserOptions: { ecmaFeatures: { jsx: true }, ecmaVersion: 2022, sourceType: "module" }, sourceType: "module" }, linterOptions: { reportUnusedDisableDirectives: false }, plugins: { "unused-imports": pluginUnusedImports }, rules: { "accessor-pairs": ["error", { enforceForClassMembers: true, setWithoutGet: true }], "array-callback-return": "error", "block-scoped-var": "error", "constructor-super": "error", "default-case-last": "error", "dot-notation": ["error", { allowKeywords: true }], eqeqeq: ["error", "smart"], "new-cap": ["error", { capIsNew: false, newIsCap: true, properties: true }], "no-alert": "error", "no-array-constructor": "error", "no-async-promise-executor": "error", "no-caller": "error", "no-case-declarations": "error", "no-class-assign": "error", "no-compare-neg-zero": "error", "no-cond-assign": ["error", "always"], "no-console": ["error", { allow: ["warn", "error"] }], "no-const-assign": "error", "no-control-regex": "error", "no-debugger": "error", "no-delete-var": "error", "no-dupe-args": "error", "no-dupe-class-members": "error", "no-dupe-keys": "error", "no-duplicate-case": "error", "no-empty": ["error", { allowEmptyCatch: true }], "no-empty-character-class": "error", "no-empty-pattern": "error", "no-eval": "error", "no-ex-assign": "error", "no-extend-native": "error", "no-extra-bind": "error", "no-extra-boolean-cast": "error", "no-fallthrough": "error", "no-func-assign": "error", "no-global-assign": "error", "no-implied-eval": "error", "no-import-assign": "error", "no-invalid-regexp": "error", "no-irregular-whitespace": "error", "no-iterator": "error", "no-labels": ["error", { allowLoop: false, allowSwitch: false }], "no-lone-blocks": "error", "no-loss-of-precision": "error", "no-misleading-character-class": "error", "no-multi-str": "error", "no-new": "error", "no-new-func": "error", "no-new-native-nonconstructor": "error", "no-new-wrappers": "error", "no-obj-calls": "error", "no-octal": "error", "no-octal-escape": "error", "no-proto": "error", "no-prototype-builtins": "error", "no-redeclare": ["error", { builtinGlobals: false }], "no-regex-spaces": "error", "no-restricted-globals": [ "error", { message: "Use `globalThis` instead.", name: "global" }, { message: "Use `globalThis` instead.", name: "self" } ], "no-restricted-properties": [ "error", { message: "Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.", property: "__proto__" }, { message: "Use `Object.defineProperty` instead.", property: "__defineGetter__" }, { message: "Use `Object.defineProperty` instead.", property: "__defineSetter__" }, { message: "Use `Object.getOwnPropertyDescriptor` instead.", property: "__lookupGetter__" }, { message: "Use `Object.getOwnPropertyDescriptor` instead.", property: "__lookupSetter__" } ], "no-restricted-syntax": [ "error", "DebuggerStatement", "LabeledStatement", "WithStatement", "TSEnumDeclaration[const=true]", "TSExportAssignment" ], "no-self-assign": ["error", { props: true }], "no-self-compare": "error", "no-sequences": "error", "no-shadow-restricted-names": "error", "no-sparse-arrays": "error", "no-template-curly-in-string": "error", "no-this-before-super": "error", "no-throw-literal": "error", "no-undef": "error", "no-undef-init": "error", "no-unexpected-multiline": "error", "no-unmodified-loop-condition": "error", "no-unneeded-ternary": ["error", { defaultAssignment: false }], "no-unreachable": "error", "no-unreachable-loop": "error", "no-unsafe-finally": "error", "no-unsafe-negation": "error", "no-unused-expressions": [ "error", { allowShortCircuit: true, allowTaggedTemplates: true, allowTernary: true } ], "no-unused-vars": [ "error", { args: "none", caughtErrors: "none", ignoreRestSiblings: true, vars: "all" } ], "no-use-before-define": ["error", { classes: false, functions: false, variables: true }], "no-useless-backreference": "error", "no-useless-call": "error", "no-useless-catch": "error", "no-useless-computed-key": "error", "no-useless-constructor": "error", "no-useless-rename": "error", "no-useless-return": "error", "no-var": "error", "no-with": "error", "object-shorthand": [ "error", "always", { avoidQuotes: true, ignoreConstructors: false } ], "one-var": ["error", { initialized: "never" }], "prefer-arrow-callback": [ "error", { allowNamedFunctions: false, allowUnboundThis: true } ], "prefer-const": [ "error", { destructuring: "all", ignoreReadBeforeAssign: true } ], "prefer-exponentiation-operator": "error", "prefer-promise-reject-errors": "error", "prefer-regex-literals": ["error", { disallowRedundantWrapping: true }], "prefer-rest-params": "error", "prefer-spread": "error", "prefer-template": "error", "sort-imports": [ "error", { allowSeparatedGroups: false, ignoreCase: false, ignoreDeclarationSort: true, ignoreMemberSort: false, memberSyntaxSortOrder: ["none", "all", "multiple", "single"] } ], "symbol-description": "error", "unicode-bom": ["error", "never"], "use-isnan": ["error", { enforceForIndexOf: true, enforceForSwitchCase: true }], "valid-typeof": ["error", { requireStringLiterals: true }], "vars-on-top": "error", yoda: ["error", "never"], "unused-imports/no-unused-imports": "error", "unused-imports/no-unused-vars": [ "error", { args: "after-used", argsIgnorePattern: "^_", ignoreRestSiblings: true, vars: "all", varsIgnorePattern: "^_" } ], ...overrides } }, { files: [`scripts/${GLOB_SRC}`, `cli.${GLOB_SRC_EXT}`], name: "@anyions/shared-config-eslint/javascript/disables/cli", rules: { "no-console": "off" } }, { name: `@anyions/shared-config-eslint/javascript/disables/test`, files: GLOB_TESTS, rules: { "no-unused-expressions": "off" } } ]; } // src/configs/jsdoc.ts async function createJsDocConfig() { const pluginJsdoc = await interopDefault(import("eslint-plugin-jsdoc")); return [ { name: "@anyions/shared-config-eslint/ignores/rules", plugins: { jsdoc: pluginJsdoc }, rules: { "jsdoc/check-access": "warn", "jsdoc/check-param-names": "warn", "jsdoc/check-property-names": "warn", "jsdoc/check-types": "warn", "jsdoc/empty-tags": "warn", "jsdoc/implements-on-classes": "warn", "jsdoc/no-defaults": "warn", "jsdoc/no-multi-asterisks": "warn", "jsdoc/require-param-name": "warn", "jsdoc/require-property": "warn", "jsdoc/require-property-description": "warn", "jsdoc/require-property-name": "warn", "jsdoc/require-returns-check": "warn", "jsdoc/require-returns-description": "warn", "jsdoc/require-yields-check": "warn", // stylelistic "jsdoc/check-alignment": "warn", "jsdoc/multiline-blocks": "warn" } } ]; } // src/configs/jsonc.ts async function createJSONConfig(options = {}) { if (options === false) return []; const { files = [GLOB_JSON, GLOB_JSON5, GLOB_JSONC], overrides = {} } = options; const pluginJsonc = await interopDefault(import("eslint-plugin-jsonc")); const parserJsonc = await interopDefault(import("jsonc-eslint-parser")); return [ { name: "@anyions/shared-config-eslint/jsonc/core", plugins: { jsonc: pluginJsonc } }, { name: "@anyions/shared-config-eslint/jsonc/global/rules", files, languageOptions: { parser: parserJsonc }, 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", //stylelistic "jsonc/array-bracket-spacing": ["error", "never"], "jsonc/comma-dangle": ["error", "never"], "jsonc/comma-style": ["error", "last"], // 'jsonc/indent': ['error', prettierIndent], // use prettier to style "jsonc/key-spacing": ["error", { afterColon: true, beforeColon: false }], "jsonc/object-curly-newline": ["error", { consistent: true, multiline: true }], "jsonc/object-curly-spacing": ["error", "always"], "jsonc/object-property-newline": ["error", { allowMultiplePropertiesPerLine: true }], "jsonc/quote-props": "error", "jsonc/quotes": "error", ...overrides } }, { name: "@anyions/shared-config-eslint/jsonc/package-json/rules", files: [GLOB_PACKAGE_JSON], rules: { "jsonc/sort-array-values": [ "error", { order: { type: "asc" }, pathPattern: "^files$" } ], "jsonc/sort-keys": [ "error", { order: [ "publisher", "name", "displayName", "type", "version", "private", "packageManager", "description", "author", "license", "funding", "homepage", "repository", "bugs", "keywords", "categories", "sideEffects", "exports", "main", "module", "unpkg", "jsdelivr", "types", "typesVersions", "bin", "icon", "files", "engines", "activationEvents", "contributes", "scripts", "peerDependencies", "peerDependenciesMeta", "dependencies", "optionalDependencies", "devDependencies", "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.*$" }, { order: [ // client hooks only "pre-commit", "prepare-commit-msg", "commit-msg", "post-commit", "pre-rebase", "post-rewrite", "post-checkout", "post-merge", "pre-push", "pre-auto-gc" ], pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$" } ] } }, { name: "@anyions/shared-config-eslint/jsonc/tsconfig-json/rules", files: [GLOB_TS_CONFIG, GLOB_TS_OTHER_CONFIG], 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$" } ] } } ]; } // src/configs/markdown.ts async function createMarkdownConfig(options = {}) { if (options === false) return []; const { componentExts = [], files = [GLOB_MARKDOWN], overrides = {} } = options; const markdown = await interopDefault(import("eslint-plugin-markdown")); return [ { name: "@anyions/shared-config-eslint/markdown/core", plugins: { markdown } }, { name: "@anyions/shared-config-eslint/markdown/processor", files, ignores: [GLOB_MARKDOWN_IN_MARKDOWN], processor: mergeProcessors([markdown.processors.markdown, processorPassThrough]) }, { files: [GLOB_MARKDOWN_CODE, ...componentExts.map((ext) => `${GLOB_MARKDOWN}/**/*.${ext}`)], languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } }, name: "@anyions/shared-config-eslint/markdown/rules", rules: { "import/newline-after-import": "off", "no-alert": "off", "no-console": "off", "no-labels": "off", "no-lone-blocks": "off", "no-restricted-syntax": "off", "no-undef": "off", "no-unused-expressions": "off", "no-unused-labels": "off", "no-unused-vars": "off", "node/prefer-global/process": "off", "style/comma-dangle": "off", "style/eol-last": "off", "ts/consistent-type-imports": "off", "ts/no-namespace": "off", "ts/no-redeclare": "off", "ts/no-require-imports": "off", "ts/no-unused-vars": "off", "ts/no-use-before-define": "off", "ts/no-var-requires": "off", "unicode-bom": "off", "unused-imports/no-unused-imports": "off", "unused-imports/no-unused-vars": "off", // Type aware rules ...{ "ts/await-thenable": "off", "ts/dot-notation": "off", "ts/no-floating-promises": "off", "ts/no-for-in-array": "off", "ts/no-implied-eval": "off", "ts/no-misused-promises": "off", "ts/no-throw-literal": "off", "ts/no-unnecessary-type-assertion": "off", "ts/no-unsafe-argument": "off", "ts/no-unsafe-assignment": "off", "ts/no-unsafe-call": "off", "ts/no-unsafe-member-access": "off", "ts/no-unsafe-return": "off", "ts/restrict-plus-operands": "off", "ts/restrict-template-expressions": "off", "ts/unbound-method": "off" }, ...overrides } } ]; } // src/configs/node.ts async function createNodeConfig() { const pluginNode = await interopDefault(import("eslint-plugin-n")); return [ { name: `@anyions/shared-config-eslint/node/rules`, plugins: { node: pluginNode }, rules: { "node/handle-callback-err": ["error", "^(err|error)$"], "node/no-deprecated-api": "error", "node/no-exports-assign": "error", "node/no-new-require": "error", "node/no-path-concat": "error", "node/prefer-global/buffer": ["error", "never"], "node/prefer-global/process": ["error", "never"], "node/process-exit-as-throw": "error" } } ]; } // src/configs/perfectionist.ts async function createPerfectionistConfig() { const pluginPerfectionist = await interopDefault(import("eslint-plugin-perfectionist")); return [ { name: "@anyions/shared-config-eslint/perfectionist/rules", plugins: { perfectionist: pluginPerfectionist } } ]; } // src/configs/typescript.ts var import_node_process = __toESM(require("process"), 1); async function createTsRules() { const pluginTs = await interopDefault(import("@typescript-eslint/eslint-plugin")); const tsRules = { ...pluginTs.configs.base.rules, ...pluginTs.configs.recommended.rules, ...pluginTs.configs.strict.rules, "no-undef": "off", "ts/ban-ts-comment": "off", "ts/ban-ts-ignore": "off", "ts/ban-types": "off", "ts/consistent-type-imports": ["error", { prefer: "type-imports", disallowTypeAnnotations: false }], "ts/explicit-module-boundary-types": "off", "ts/prefer-as-const": "warn", "ts/no-empty-function": "off", "ts/no-empty-interface": ["error", { allowSingleExtends: true }], "ts/no-explicit-any": "off", "ts/no-import-type-side-effects": "error", "ts/no-non-null-assertion": "off", "ts/no-redeclare": "error", "ts/prefer-literal-enum-member": ["error", { allowBitwiseExpressions: true }], "ts/no-unused-vars": [ "error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_" } ] }; return (0, import_eslint_flat_config_utils.renamePluginsInRules)(tsRules, { "@typescript-eslint": "ts" }); } async function createTypescriptConfig(options = {}) { if (options === false) return []; const opts = options; const { componentExts = [], overrides = {}, parserOptions = {} } = opts; const files = opts.files ?? [GLOB_SRC, ...componentExts.map((ext) => `**/*.${ext}`)]; const filesTypeAware = opts.filesTypeAware ?? [GLOB_TS, GLOB_TSX]; const tsconfigPath = opts?.tsconfigPath ? toArray(opts.tsconfigPath) : void 0; const isTypeAware = !!tsconfigPath; const pluginTs = await interopDefault(import("@typescript-eslint/eslint-plugin")); const parserTs = await interopDefault(import("@typescript-eslint/parser")); const typeAwareRules = { "dot-notation": "off", "no-implied-eval": "off", "no-throw-literal": "off", "ts/await-thenable": "error", "ts/dot-notation": ["error", { allowKeywords: true }], "ts/no-floating-promises": "error", "ts/no-for-in-array": "error", "ts/no-implied-eval": "error", "ts/no-misused-promises": "error", "ts/no-throw-literal": "error", "ts/no-unnecessary-type-assertion": "error", "ts/no-unsafe-argument": "error", "ts/no-unsafe-assignment": "error", "ts/no-unsafe-call": "error", "ts/no-unsafe-member-access": "error", "ts/no-unsafe-return": "error", "ts/restrict-plus-operands": "error", "ts/restrict-template-expressions": "error", "ts/unbound-method": "error" }; const tsRules = await createTsRules(); function makeParser(typeAware, files2, ignores) { return { name: `@anyions/shared-config-eslint/typescript/${typeAware ? "type-aware-parser" : "parser"}`, files: files2, ...ignores ? { ignores } : {}, languageOptions: { parser: parserTs, parserOptions: { extraFileExtensions: componentExts.map((ext) => `.${ext}`), sourceType: "module", ...typeAware ? { project: tsconfigPath, tsconfigRootDir: import_node_process.default.cwd() } : {}, ...parserOptions } } }; } return [ { name: "@anyions/shared-config-eslint/typescript/core", plugins: { ts: pluginTs } }, ...isTypeAware ? [makeParser(true, filesTypeAware), makeParser(false, files, filesTypeAware)] : [makeParser(false, files)], { name: "@anyions/shared-config-eslint/typescript/rules", files, rules: { ...tsRules, ...overrides } }, ...isTypeAware ? [ { name: "@anyions/shared-config-eslint/typescript/type-aware/rules", files: filesTypeAware, rules: { ...tsconfigPath ? typeAwareRules : {}, ...overrides } } ] : [], { name: "@anyions/shared-config-eslint/typescript/disables/dts", files: ["**/*.d.ts"], rules: { "eslint-comments/no-unlimited-disable": "off", "import/no-duplicates": "off", "no-restricted-syntax": "off", "unused-imports/no-unused-vars": "off" } }, { name: "@anyions/shared-config-eslint/typescript/disables/cjs", files: ["**/*.js", "**/*.cjs"], rules: { "ts/no-require-imports": "off", "ts/no-var-requires": "off" } } ]; } // src/configs/react.ts var ReactRefreshAllowConstantExportPackages = ["vite"]; var RemixPackages = ["@remix-run/node", "@remix-run/react", "@remix-run/serve", "@remix-run/dev"]; var NextJsPackages = ["next"]; async function createReactConfig(options = {}, tsOverrides = {}) { if (options === false) return []; const { files = [GLOB_JS, GLOB_JSX, GLOB_TS, GLOB_TSX], overrides = {} } = options; const [pluginReact, pluginReactHooks, pluginReactRefresh, parserTs] = await Promise.all([ interopDefault(import("@eslint-react/eslint-plugin")), interopDefault(import("eslint-plugin-react-hooks")), interopDefault(import("eslint-plugin-react-refresh")), interopDefault(import("@typescript-eslint/parser")) ]); const tsRules = await createTsRules(); const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((i) => (0, import_node_pkg.isPackageExists)(i)); const isUsingRemix = RemixPackages.some((i) => (0, import_node_pkg.isPackageExists)(i)); const isUsingNext = NextJsPackages.some((i) => (0, import_node_pkg.isPackageExists)(i)); const plugins = pluginReact.configs.all.plugins; return [ { name: "@anyions/shared-config-eslint/react/core", plugins: { react: plugins["@eslint-react"], "react-dom": plugins["@eslint-react/dom"], "react-hooks": pluginReactHooks, "react-hooks-extra": plugins["@eslint-react/hooks-extra"], "react-naming-convention": plugins["@eslint-react/naming-convention"], "react-refresh": pluginReactRefresh } }, { name: "@anyions/shared-config-eslint/react/rules", files, languageOptions: { parser: parserTs, parserOptions: { ecmaFeatures: { jsx: true } }, sourceType: "module" }, rules: { ...tsRules, ...tsOverrides, // recommended rules from @eslint-react/dom "react-dom/no-children-in-void-dom-elements": "warn", "react-dom/no-dangerously-set-innerhtml": "warn", "react-dom/no-dangerously-set-innerhtml-with-children": "error", "react-dom/no-find-dom-node": "error", "react-dom/no-missing-button-type": "warn", "react-dom/no-missing-iframe-sandbox": "warn", "react-dom/no-namespace": "error", "react-dom/no-render-return-value": "error", "react-dom/no-script-url": "warn", "react-dom/no-unsafe-iframe-sandbox": "warn", "react-dom/no-unsafe-target-blank": "warn", // recommended rules react-hooks "react-hooks/exhaustive-deps": "warn", "react-hooks/rules-of-hooks": "error", // react refresh "react-refresh/only-export-components": [ "warn", { allowConstantExport: isAllowConstantExport, allowExportNames: [ ...isUsingNext ? ["config", "generateStaticParams", "metadata", "generateMetadata", "viewport", "generateViewport"] : [], ...isUsingRemix ? ["meta", "links", "headers", "loader", "action"] : [] ] } ], // recommended rules from @eslint-react "react/ensure-forward-ref-using-ref": "warn", "react/no-access-state-in-setstate": "error", "react/no-array-index-key": "warn", "react/no-children-count": "warn", "react/no-children-for-each": "warn", "react/no-children-map": "warn", "react/no-children-only": "warn", "react/no-children-prop": "warn", "react/no-children-to-array": "warn", "react/no-clone-element": "warn", "react/no-comment-textnodes": "warn", "react/no-component-will-mount": "error", "react/no-component-will-receive-props": "error", "react/no-component-will-update": "error", "react/no-create-ref": "error", "react/no-direct-mutation-state": "error", "react/no-duplicate-key": "error", "react/no-implicit-key": "error", "react/no-missing-key": "error", "react/no-nested-components": "warn", "react/no-redundant-should-component-update": "error", "react/no-set-state-in-component-did-mount": "warn", "react/no-set-state-in-component-did-update": "warn", "react/no-set-state-in-component-will-update": "warn", "react/no-string-refs": "error", "react/no-unsafe-component-will-mount": "warn", "react/no-unsafe-component-will-receive-props": "warn", "react/no-unsafe-component-will-update": "warn", "react/no-unstable-context-value": "error", "react/no-unstable-default-props": "error", "react/no-unused-class-component-members": "warn", "react/no-unused-state": "warn", "react/no-useless-fragment": "warn", "react/prefer-destructuring-assignment": "warn", "react/prefer-shorthand-boolean": "warn", "react/prefer-shorthand-fragment": "warn", // overrides ...overrides } } ]; } // src/configs/unicorn.ts async function createUnicornConfig() { const pluginUnicorn = await interopDefault(import("eslint-plugin-unicorn")); return [ { name: "@anyions/shared-config-eslint/unicorn/rules", plugins: { unicorn: pluginUnicorn }, rules: { "unicorn/error-message": "error", "unicorn/escape-case": "error", "unicorn/no-instanceof-array": "error", "unicorn/no-new-array": "error", "unicorn/no-new-buffer": "error", "unicorn/number-literal-case": "error", "unicorn/prefer-dom-node-text-content": "error", "unicorn/prefer-includes": "error", "unicorn/prefer-node-protocol": "error", "unicorn/prefer-number-properties": "error", "unicorn/prefer-string-starts-ends-with": "error", "unicorn/prefer-type-error": "error", "unicorn/throw-new-error": "error" } } ]; } // src/configs/unocss.ts async function createUnocssConfig(options = {}) { if (options === false) return []; const { attributify = true, strict = false } = options; const unocss = await interopDefault(import("@unocss/eslint-config/flat")); return [ { name: "@anyions/shared-config-eslint/unocss/core", plugins: unocss.plugins, rules: unocss.rules }, { name: "@anyions/shared-config-eslint/unocss/rules", rules: { ...unocss.rules, ...attributify ? { "unocss/order-attributify": "warn" } : {}, ...strict ? { "unocss/blocklist": "error" } : {} } } ]; } // src/configs/vue.ts async function createVueConfig(options = {}, tsOverrides = {}) { if (options === false) return []; const { files = [GLOB_VUE], overrides = {} } = options; const [pluginVue, parserVue, parserTs] = await Promise.all([ interopDefault(import("eslint-plugin-vue")), interopDefault(import("vue-eslint-parser")), interopDefault(import("@typescript-eslint/parser")) ]); const tsRules = await createTsRules(); return [ { name: "@anyions/shared-config-eslint/vue/core", languageOptions: { globals: { computed: "readonly", defineEmits: "readonly", defineExpose: "readonly", defineProps: "readonly", onMounted: "readonly", onUnmounted: "readonly", reactive: "readonly", ref: "readonly", shallowReactive: "readonly", shallowRef: "readonly", toRef: "readonly", toRefs: "readonly", watch: "readonly", watchEffect: "readonly" } }, plugins: { vue: pluginVue } }, { name: "@anyions/shared-config-eslint/vue/rules", files, languageOptions: { parser: parserVue, parserOptions: { ecmaFeatures: { jsx: true }, parser: parserTs, extraFileExtensions: [".vue"], sourceType: "module" } }, processor: pluginVue.processors[".vue"], rules: { ...tsRules, ...tsOverrides, ...pluginVue.configs.base.rules, ...pluginVue.configs["vue3-essential"].rules, ...pluginVue.configs["vue3-strongly-recommended"].rules, ...pluginVue.configs["vue3-recommended"].rules, "node/prefer-global/process": "off", "vue/attribute-hyphenation": "off", "vue/block-order": [ "error", { order: ["template", "script", "style"] } ], "vue/component-name-in-template-casing": ["error", "kebab-case"], "vue/component-options-name-casing": ["error", "PascalCase"], "vue/custom-event-name-casing": ["error", "kebab-case"], "vue/define-macros-order": [ "error", { order: ["defineOptions", "defineProps", "defineEmits", "defineSlots"] } ], "vue/define-props-declaration": ["warn", "type-based"], "vue/dot-location": ["error", "property"], "vue/dot-notation": ["error", { allowKeywords: true }], "vue/eqeqeq": ["error", "smart"], "vue/html-indent": ["error", 2], "vue/html-quotes": ["error", "double"], "vue/html-closing-bracket-newline": "off", "vue/max-attributes-per-line": "off", "vue/multiline-html-element-content-newline": "off", "vue/multi-word-component-names": "off", "vue/no-empty-pattern": "error", "vue/no-irregular-whitespace": "error", "vue/no-loss-of-precision": "error", "vue/no-restricted-syntax": ["error", "DebuggerStatement", "LabeledStatement", "WithStatement"], "vue/no-restricted-v-bind": ["error", "/^v-/"], "vue/no-setup-props-reactivity-loss": "off", "vue/no-sparse-arrays": "error", "vue/no-unused-refs": "error", "vue/no-useless-v-bind": "error", "vue/no-v-for-template-key-on-child": "off", "vue/no-v-html": "off", "vue/object-shorthand": [ "error", "always", { avoidQuotes: true, ignoreConstructors: false } ], "vue/prefer-separate-static-class": "error", "vue/prefer-template": "error", "vue/prop-name-casing": ["error", "camelCase"], "vue/require-default-prop": "off", "vue/require-prop-types": "off", "vue/script-setup-uses-vars": "error", "vue/space-infix-ops": "error", "vue/space-unary-ops": ["error", { nonwords: false, words: true }], //styllistic "vue/array-bracket-spacing": ["error", "never"], "vue/arrow-spacing": ["error", { after: true, before: true }], "vue/block-spacing": ["error", "always"], "vue/block-tag-newline": [ "error", { multiline: "always", singleline: "always" } ], "vue/brace-style": ["error", "stroustrup", { allowSingleLine: true }], "vue/comma-dangle": ["error", "always-multiline"], "vue/comma-spacing": ["error", { after: true, before: false }], "vue/comma-style": ["error", "last"], "vue/html-comment-content-spacing": [ "error", "always", { exceptions: ["-"] } ], "vue/key-spacing": ["error", { afterColon: true, beforeColon: false }], "vue/keyword-spacing": ["error", { after: true, before: true }], "vue/object-curly-newline": "off", "vue/object-curly-spacing": ["error", "always"], "vue/object-property-newline": ["error", { allowMultiplePropertiesPerLine: true }], "vue/operator-linebreak": ["error", "before"], "vue/padding-line-between-blocks": ["error", "always"], "vue/quote-props": ["error", "consistent-as-needed"], "vue/space-in-parens": ["error", "never"], "vue/template-curly-spacing": "error", ...overrides } } ]; } // src/options.ts var import_promises = require("fs/promises"); var import_node_path = __toESM(require("path"), 1); var import_node_process2 = __toESM(require("process"), 1); var DEFAULT_PRETTIER_RULES = { printWidth: 120, tabWidth: 2, useTabs: false, semi: false, vueIndentScriptAndStyle: true, singleQuote: true, quoteProps: "as-needed", bracketSpacing: true, trailingComma: "none", jsxSingleQuote: true, arrowParens: "always", proseWrap: "never", htmlWhitespaceSensitivity: "strict", endOfLine: "lf", rangeStart: 0 }; var DEFAULT_PRETTIER_FORMATTERS = { html: true, css: true, json: true, markdown: true }; var VuePackages = ["vue", "nuxt", "vitepress", "@slidev/cli"]; async function loadPrettierConfig(cwd) { let prettierConfig = {}; try { const prettierrc = await (0, import_promises.readFile)(import_node_path.default.join(cwd, ".prettierrc"), "utf-8"); prettierConfig = JSON.parse(prettierrc); } catch { } return prettierConfig; } async function createOptions(options = {}) { const opts = { cwd: import_node_process2.default.cwd(), ignores: [], prettier: { rules: DEFAULT_PRETTIER_RULES, formatters: DEFAULT_PRETTIER_FORMATTERS }, flatignore: [".gitignore", ".eslintignore"], javascript: {}, typescript: {}, vue: {}, react: {}, unocss: { attributify: true, strict: false }, markdown: {}, jsonc: {} }; const { cwd, ignores, flatignore, prettier, javascript, typescript = (0, import_node_pkg.isPackageExists)("typescript"), unocss = false, vue = VuePackages.some((i) => (0, import_node_pkg.isPackageExists)(i)), react = false, markdown = true, jsonc = true } = options; if (cwd) { opts.cwd = cwd; } if (ignores?.length) { opts.ignores = [...opts.ignores, ...ignores]; } if (typeof flatignore === "object") { opts.flatignore = [.../* @__PURE__ */ new Set([...opts.flatignore, ...flatignore])]; } if (typeof prettier === "object") { opts.prettier = { rules: { ...DEFAULT_PRETTIER_RULES, ...prettier.rules }, formatters: { ...DEFAULT_PRETTIER_FORMATTERS, ...prettier.formatters } }; } else if (prettier === false) { opts.prettier = prettier; } if (typeof opts.prettier === "object") { const prettierConfig = await loadPrettierConfig(opts.cwd); Object.assign(opts.prettier.rules, prettierConfig); } if (typeof javascript === "object") { opts.javascript = javascript; } if (typeof typescript === "object") { Object.assign(opts.typescript, typescript); } else if (typescript === false) { opts.typescript = typescript; } if (typeof unocss === "object") { Object.assign(opts.unocss, unocss); } else if (unocss === false) { opts.unocss = unocss; } if (typeof vue === "object") { Object.assign(opts.vue, vue); } else if (vue === false) { opts.vue = vue; } if (typeof react === "object") { Object.assign(opts.react, react); } else if (react === false) { opts.react = react; } if (typeof markdown === "object") { Object.assign(opts.markdown, markdown); } else if (markdown === false) { opts.markdown = markdown; } if (typeof jsonc === "object") { Object.assign(opts.jsonc, jsonc); } else if (jsonc === false) { opts.jsonc = jsonc; } return opts; } // src/index.ts async function defineConfig(options = {}, ...userConfigs) { const opts = await createOptions(options); const tsOverride = opts.typescript ? opts.typescript.overrides : {}; const comments = await createCommentsConfig(); const formatter = await createFormatterConfig(opts.prettier); const ignores = await createIgnoresConfig(opts.ignores, opts.flatignore); const imports = await createImportsConfig(); const javascript = await createJavascriptConfig(opts.javascript); const jsdoc = await createJsDocConfig(); const json = await createJSONConfig(opts.jsonc); const node = await createNodeConfig(); const markdown = await createMarkdownConfig(opts.markdown); const perfectionist = await createPerfectionistConfig(); const typescript = await createTypescriptConfig(opts.typescript); const unicorn = await createUnicornConfig(); const unocss = await createUnocssConfig(opts.unocss); const vue = await createVueConfig(opts.vue, tsOverride); const react = await createReactConfig(opts.react, tsOverride); const userResolved = await Promise.all(userConfigs); const configs = [ //basic ...ignores, ...javascript, ...comments, ...node, ...jsdoc, ...imports, ...unicorn, ...perfectionist, //optional ...typescript, ...unocss, ...vue, ...react, ...json, ...markdown, //userdefined ...userResolved, //formatter ...formatter ]; return (0, import_eslint_flat_config_utils.composer)(configs).renamePlugins(defaultPluginRenaming); }