UNPKG

@yunarch/config-web

Version:

Shared configurations for web projects.

1 lines 14 kB
import{FlatConfigComposer as e}from"eslint-flat-config-utils";import t from"@eslint/js";import n from"eslint-plugin-unused-imports";import r from"globals";import i from"eslint-config-prettier";import a from"eslint-plugin-oxlint";import{createTypeScriptImportResolver as o}from"eslint-import-resolver-typescript";import{createNodeResolver as s,importX as c}from"eslint-plugin-import-x";import l,{jsdoc as u}from"eslint-plugin-jsdoc";import d from"eslint-plugin-perfectionist";import f from"@vitest/eslint-plugin";import p from"typescript-eslint";import m from"eslint-plugin-unicorn";const h=`**/node_modules/,**/dist/,**/out/,**/output,**/.output,**/build/,**/*.min.*,**/package-lock.json,**/yarn.lock,**/.yarn/,**/.yarnrc.yml,**/.pnp.*,**/.pnp,**/.pnp.js,**/.pnp.cjs,**/bun.lock,**/bun.lockb,**/pnpm-lock.yaml,**/.vite-inspect,**/.vitepress/cache,**/vite.config.*.timestamp-*,**/*.log,**/npm-debug.log*,**/yarn-debug.log*,**/yarn-error.log*,**/coverage/,**/.nyc_output/,**/__snapshots__,**/.vscode/,**/.idea/,**/.cache,**/.nuxt,**/.next,**/.svelte-kit,**/.vercel,**/.changeset,**/.turbo/,**/.DS_Store,**/Thumbs.db,**/temp,**/.temp,**/tmp,**/.tmp,**/.history,**/mockServiceWorker.js,**/CHANGELOG*,**/LICENSE*`.split(`,`);function g(e={},i,a){let o=e.linterOptions??{};return[{name:`yunarch/base/ignores`,ignores:[...h,...i??[]]},{name:`yunarch/base/setup`,languageOptions:{ecmaVersion:2022,globals:{...r.browser,...r.es2021,...r.node,document:`readonly`,navigator:`readonly`,window:`readonly`},parserOptions:{ecmaFeatures:{jsx:!0},ecmaVersion:2022,sourceType:`module`},sourceType:`module`},linterOptions:{...o,reportUnusedDisableDirectives:a?!1:o.reportUnusedDisableDirectives??!0}},{name:`yunarch/base/rules`,plugins:{"unused-imports":n},rules:{...t.configs.recommended.rules,"array-callback-return":[`error`,{allowImplicit:!0}],"block-scoped-var":`error`,camelcase:[`error`,{allow:[`^UNSAFE_`],ignoreDestructuring:!1,properties:`never`}],curly:[`error`,`multi-line`,`consistent`],"default-case-last":`error`,eqeqeq:`error`,"func-names":[`error`,`as-needed`],"grouped-accessor-pairs":`error`,"max-lines":[`warn`,300],"max-params":[`warn`,4],"new-cap":[`error`,{capIsNew:!1}],"no-alert":`error`,"no-array-constructor":`error`,"no-bitwise":`error`,"no-caller":`error`,"no-console":`error`,"no-constant-binary-expression":`error`,"no-constructor-return":`error`,"no-else-return":`warn`,"no-eval":`error`,"no-extend-native":`error`,"no-extra-bind":`error`,"no-extra-label":`error`,"no-implicit-coercion":[`error`,{allow:[`!!`,`+`]}],"no-implied-eval":`error`,"no-iterator":`error`,"no-label-var":`error`,"no-labels":`error`,"no-lone-blocks":`error`,"no-lonely-if":`warn`,"no-multi-assign":`error`,"no-nested-ternary":`error`,"no-new":`error`,"no-new-func":`error`,"no-new-wrappers":`error`,"no-octal-escape":`error`,"no-param-reassign":`error`,"no-promise-executor-return":`error`,"no-proto":`error`,"no-return-assign":`error`,"no-script-url":`error`,"no-self-compare":`error`,"no-sequences":`error`,"no-template-curly-in-string":`error`,"no-undef-init":`warn`,"no-unneeded-ternary":`error`,"no-unreachable-loop":`error`,"no-unused-expressions":`error`,"no-unused-vars":[`error`,{args:`none`,caughtErrors:`none`,ignoreRestSiblings:!0,vars:`all`}],"no-useless-call":`error`,"no-useless-computed-key":`warn`,"no-useless-concat":`error`,"no-useless-rename":`warn`,"no-useless-return":`warn`,"no-var":`error`,"no-void":[`error`,{allowAsStatement:!0}],"object-shorthand":`warn`,"prefer-const":`warn`,"prefer-named-capture-group":`error`,"prefer-numeric-literals":`error`,"prefer-object-has-own":`error`,"prefer-object-spread":`warn`,"prefer-promise-reject-errors":[`error`,{allowEmptyReject:!0}],"prefer-regex-literals":`error`,"prefer-rest-params":`error`,"prefer-spread":`error`,"prefer-template":`warn`,"symbol-description":`error`,"unused-imports/no-unused-imports":`error`,"unused-imports/no-unused-vars":[`error`,{args:`after-used`,argsIgnorePattern:`^_`,ignoreRestSiblings:!0,vars:`all`,varsIgnorePattern:`^_`}],yoda:`warn`}}]}const _=`**/*.{js,jsx,cjs,cjsx,mjs,mjsx,ts,tsx,cts,ctsx,mts,mtjsx}`,v=`{js,jsx,cjs,cjsx,mjs,mjsx,ts,tsx,cts,ctsx,mts,mtjsx}`,y=`**/*.{ts,cts,mts}`,b=`**/*.{tsx,ctsx,mtsx}`,x=`**/*.astro/*.ts`,S=`**/*.md`,C=[`**/__tests__/**/*.${v}`,`**/*.spec.${v}`,`**/*.test.${v}`,`**/*.bench.${v}`,`**/*.benchmark.${v}`];function w(e){let{typeAware:t,oxlint:n}=e;return[{name:`yunarch/disables/cli`,files:[`**/scripts/${_}`,`**/tasks/${_}`,`**/bin/${_}`,`**/bin.${v}`,`**/*.bin.${v}`,`**/cli/${_}`,`**/cli.${v}`,`**/*.cli.${v}`],rules:{"@typescript-eslint/no-floating-promises":`off`,"no-console":`off`,"unicorn/no-process-exit":`off`}},{name:`yunarch/disables/dts`,files:[`**/*.d.{ts,cts,mts}`],rules:{"@typescript-eslint/consistent-indexed-object-style":`off`,"import/no-duplicates":`off`,"no-restricted-syntax":`off`,"unused-imports/no-unused-vars":`off`}},{name:`yunarch/disables/config-files`,files:[`**/*.config.${v}`,`**/*.config.*.${v}`],rules:{"no-console":`off`,"@typescript-eslint/explicit-function-return-type":`off`}},{name:`yunarch/disables/prettier`,rules:{...i.rules}},...n?.oxlintConfigPath?a.buildFromOxlintConfigFile(n.oxlintConfigPath,{typeAware:t}):[]]}function T(){return[{name:`yunarch/import/rules`,plugins:{import:c},rules:{...c.flatConfigs.recommended.rules,"import/first":`error`,"import/newline-after-import":[`error`,{count:1}],"import/no-absolute-path":`error`,"import/no-amd":`error`,"import/no-cycle":[`error`,{ignoreExternal:!1,maxDepth:3}],"import/no-duplicates":[`error`,{"prefer-inline":!0}],"import/no-dynamic-require":`error`,"import/no-mutable-exports":`error`,"import/no-relative-packages":`error`,"import/no-self-import":`error`,"import/no-useless-path-segments":`error`},settings:{"import-x/resolver-next":[s()]}},{name:`yunarch/import/typescript/rules`,files:[y,b],rules:{...c.flatConfigs.typescript.rules},settings:{"import-x/resolver-next":[o()]}}]}function E(){return[u({name:`yunarch/jsdoc/rules`,config:`flat/recommended-error`,rules:{"jsdoc/check-param-names":[`error`,{checkDestructured:!1}],"jsdoc/lines-before-block":[`error`,{lines:0}],"jsdoc/require-hyphen-before-param-description":[`error`,`always`],"jsdoc/require-param":[`error`,{checkDestructured:!1,enableRestElementFixer:!1}],"jsdoc/require-throws":`error`,"jsdoc/tag-lines":[`error`,`any`,{startLines:1}]}}),u({name:`yunarch/jsdoc/typescript/rules`,files:[y,b],config:`flat/recommended-typescript-error`,rules:{...l.configs[`flat/contents-typescript-error`].rules,...l.configs[`flat/logical-typescript-error`].rules,...l.configs[`flat/stylistic-typescript-error`].rules,"jsdoc/require-hyphen-before-param-description":[`error`,`always`],"jsdoc/require-param":[`error`,{checkDestructured:!1,enableRestElementFixer:!1}],"jsdoc/require-throws":`error`}})]}function D(){return[{name:`yunarch/perfectionist/rules`,plugins:{perfectionist:d},rules:{"perfectionist/sort-exports":[`error`,{order:`asc`,type:`natural`}],"perfectionist/sort-imports":[`error`,{groups:[`builtin`,`external`,`internal`,[`parent`,`sibling`,`index`],`side-effect`,`unknown`],newlinesBetween:0,order:`asc`,type:`natural`}],"perfectionist/sort-named-exports":[`error`,{order:`asc`,type:`natural`}],"perfectionist/sort-named-imports":[`error`,{groups:[`value-import`,`type-import`],order:`asc`,type:`natural`}],"import/order":`off`,"sort-imports":`off`}}]}async function O(e){let t=await e;return typeof t==`object`&&t&&`default`in t?t.default:t}async function k(e,t){let n=t.typescriptEnabled,r=n&&t.typeAware,i=e===!0||e.enableStrictRules,[a,o]=await Promise.all([O(import(`@eslint-react/eslint-plugin`)),O(import(`eslint-plugin-react-refresh`))]);return[{name:`yunarch/react/setup`,plugins:{react:a.configs.all.plugins[`@eslint-react`],"react-refresh":o}},{name:`yunarch/react/rules`,files:[_],languageOptions:{parserOptions:{ecmaFeatures:{jsx:!0}},sourceType:`module`},rules:{...a.configs.recommended.rules,...i?a.configs.strict.rules:{},...o.configs.recommended.rules,"react/use-state":[`warn`,{enforceAssignment:!1}],...a.configs[`disable-experimental`].rules}},...n?[{name:`yunarch/react/typescript/rules`,files:[y,b],ignores:[`${S}/**`,x],languageOptions:{parserOptions:{projectService:!0}},rules:{...a.configs[`recommended-typescript`].rules,...i?a.configs[`strict-typescript`].rules:{},...r?{...a.configs[`recommended-type-checked`].rules,...i?a.configs[`strict-type-checked`].rules:{}}:{},...a.configs[`disable-experimental`].rules}}]:[]]}async function A(e,t){let n=t.typescriptEnabled,r=e===!0||e.enableQuery,i=e===!0||e.enableRouter,a=[];if(r){let e=await O(import(`@tanstack/eslint-plugin-query`));a.push({name:`yunarch/tanstack/query/rules`,plugins:{"@tanstack/query":e},rules:{...e.configs[`flat/recommended`].at(0)?.rules}})}if(i){let e=await O(import(`@tanstack/eslint-plugin-router`));a.push({name:`yunarch/tanstack/router/rules`,plugins:{"@tanstack/router":e},rules:{...e.configs[`flat/recommended`].at(0)?.rules}},...n?[{name:`yunarch/tanstack/router/typescript/rules`,files:[y,b],ignores:[`${S}/**`,x],rules:{"@typescript-eslint/only-throw-error":[`error`,{allow:[`Redirect`,`NotFoundError`]}]}}]:[])}return a}function j(e){let t=e===!0||e.enableTypeTesting;return[{name:`yunarch/test/setup`,plugins:{vitest:f},...t?{settings:{vitest:{typecheck:!0}},languageOptions:{globals:{...f.environments.env.globals}}}:{}},{name:`yunarch/test/rules`,files:[...C],rules:{...f.configs.recommended.rules,"vitest/consistent-test-it":[`error`,{fn:`it`,withinDescribe:`it`}],"vitest/prefer-hooks-in-order":`error`,"vitest/prefer-lowercase-title":`error`}}]}function M(e,t,n){return{name:e,files:t,...n.ignores?{ignores:n.ignores}:{},languageOptions:{parser:p.parser,parserOptions:{extraFileExtensions:n.extraFileExtensions?.map(e=>`.${e}`),sourceType:`module`,...n.tsconfigPath?{projectService:{allowDefaultProject:[`./*.js`],defaultProject:n.tsconfigPath},tsconfigRootDir:process.cwd()}:{},...n.parserOptions}}}}function N(e,t=[]){let n=[y,b],r=e.filesTypeAware??[`**/*.{ts,cts,mts}`,`**/*.{tsx,ctsx,mtsx}`],i=e.ignoresTypeAware??[`**/*.md/**`,`**/*.astro/*.ts`];return[{name:`yunarch/typescript/setup`,plugins:{"@typescript-eslint":p.plugin}},M(`yunarch/typescript/parser`,n,{ignores:void 0,extraFileExtensions:t,parserOptions:e.parserOptions}),...e.tsconfigPath?[M(`yunarch/typescript/parser/type-aware`,r,{ignores:i,extraFileExtensions:t,parserOptions:e.parserOptions,tsconfigPath:e.tsconfigPath})]:[],{name:`yunarch/typescript/rules`,files:n,rules:{...p.configs.eslintRecommended.rules,...p.configs.strict.at(-1)?.rules,...p.configs.stylistic.at(-1)?.rules,"@typescript-eslint/ban-ts-comment":[`error`,{"ts-expect-error":`allow-with-description`}],"@typescript-eslint/consistent-type-definitions":`off`,"@typescript-eslint/consistent-type-imports":[`error`,{disallowTypeAnnotations:!1,fixStyle:`inline-type-imports`,prefer:`type-imports`}],"@typescript-eslint/default-param-last":`error`,"@typescript-eslint/explicit-function-return-type":`off`,"@typescript-eslint/method-signature-style":[`error`,`property`],"@typescript-eslint/naming-convention":[`error`,{format:[`PascalCase`],selector:[`typeLike`]},{format:[`UPPER_CASE`],selector:[`enumMember`]},{custom:{match:!1,regex:`^I[A-Z]|^(Interface|Props|State)$`},format:[`PascalCase`],selector:`interface`}],"@typescript-eslint/no-dupe-class-members":`error`,"@typescript-eslint/no-empty-object-type":[`error`,{allowInterfaces:`always`}],"@typescript-eslint/no-import-type-side-effects":`error`,"@typescript-eslint/no-loop-func":`error`,"@typescript-eslint/no-redeclare":[`error`,{builtinGlobals:!1}],"@typescript-eslint/no-shadow":`error`,"@typescript-eslint/no-unused-vars":`off`,"@typescript-eslint/no-use-before-define":[`error`,{classes:!1,functions:!1,variables:!0}],"@typescript-eslint/no-useless-empty-export":`warn`,"@typescript-eslint/restrict-template-expressions":[`error`,{allowNumber:!0,allowBoolean:!0}],"@typescript-eslint/unified-signatures":[`error`,{ignoreDifferentlyNamedParameters:!0,ignoreOverloadsWithDifferentJSDoc:!0}]}},...e.tsconfigPath&&!e.disableTypeAware?[{name:`yunarch/typescript/rules/type-aware`,files:r,ignores:i,rules:{...p.configs.strictTypeCheckedOnly.at(-1)?.rules,...p.configs.stylisticTypeCheckedOnly.at(-1)?.rules,"@typescript-eslint/no-misused-promises":[`error`,{checksVoidReturn:{attributes:!1}}],"@typescript-eslint/require-array-sort-compare":[`error`,{ignoreStringArrays:!0}],"@typescript-eslint/restrict-template-expressions":[`error`,{allowNumber:!0,allowBoolean:!0}],"@typescript-eslint/switch-exhaustiveness-check":`warn`}}]:[]]}function P(){return[{name:`yunarch/unicorn/rules`,plugins:{unicorn:m},rules:{...m.configs.recommended.rules,"unicorn/filename-case":[`error`,{cases:{camelCase:!0,kebabCase:!0,pascalCase:!0}}],"unicorn/no-array-reduce":`off`,"unicorn/no-null":`off`,"unicorn/prefer-number-properties":[`error`,{checkInfinity:!0,checkNaN:!0}],"unicorn/prefer-top-level-await":`warn`,"unicorn/prevent-abbreviations":`off`,"unicorn/no-useless-undefined":[`error`,{checkArguments:!1}]}}]}function F(t={},...n){let{gitignore:r=!0,ignores:i,extraFileExtensions:a,import:o=!0,jsdoc:s=!0,unicorn:c=!0,oxlint:l}=t,u=!!l,d=t.typescript===!0||typeof t.typescript==`object`&&!!t.typescript.tsconfigPath,f=t.typescript===!0||typeof t.typescript==`object`&&!!t.typescript.tsconfigPath&&!t.typescript.disableTypeAware,p=[];r&&(typeof r==`boolean`?p.push(O(import(`eslint-config-flat-gitignore`)).then(e=>[e({name:`yunarch/gitignore`,strict:!1})])):p.push(O(import(`eslint-config-flat-gitignore`)).then(e=>[e({name:`yunarch/gitignore`,...r})]))),p.push(g(t.base,i,u)),t.typescript&&p.push(N(t.typescript===!0?{}:t.typescript,a)),o&&p.push(T()),s&&p.push(E()),c&&p.push(P()),t.test&&p.push(j(t.test)),t.tanstack&&p.push(A(t.tanstack,{typescriptEnabled:d})),t.react&&p.push(k(t.react,{typescriptEnabled:d,typeAware:f})),p.push(D(),w({typeAware:f,oxlint:l}));let m=new e;return m=m.append(...p,...n),m=m.renamePlugins({"import-x":`import`,"@eslint-react":`react`}),m}export{F as config};