@icebreakers/eslint-config 2.0.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -56,12 +56,13 @@ export default icebreaker({
56
56
  a11y: true,
57
57
  nestjs: true,
58
58
  ionic: true,
59
- weapp: true,
59
+ miniProgram: true,
60
60
  formatters: true,
61
61
  })
62
62
  ```
63
63
 
64
- - `vue` – enables Vue + optionally version specific overrides (Vue 2/3) and ionic/weapp adjustments.
64
+ - `miniProgram` – injects Mini Program globals, ignores common outputs/config files, and enables Vue-side Mini Program compatibility tweaks when `vue` is on.
65
+ - `vue` – enables Vue + optionally version specific overrides (Vue 2/3) and ionic/miniProgram adjustments.
65
66
  - `react` – defers to the upstream React preset and unlocks accessibility helpers when `a11y` is enabled.
66
67
  - `query` – toggles the TanStack Query plugin (`@tanstack/eslint-plugin-query`) and its recommended lint rules.
67
68
  - `tailwindcss` – pass `true` to use the built-in Tailwind flat config or provide `{ entryPoint, tailwindConfig }` for Tailwind v4/v3 projects.
@@ -71,6 +72,55 @@ export default icebreaker({
71
72
  - `nestjs` – enables NestJS-centric TypeScript tweaks (empty decorated constructors, declaration merging, DI parameter properties, etc.).
72
73
  - `formatters` – keeps the built-in formatting rules enabled by default.
73
74
  - `test` – relaxes certain Vitest/Jest style rules (`test/prefer-lowercase-title`).
75
+ - `weapp` – legacy alias for `miniProgram`; kept for backward compatibility.
76
+
77
+ ### Mini Program Preset
78
+
79
+ `miniProgram: true` is the recommended API for `weapp-vite`, `wevu`, and native
80
+ Mini Program templates. It enables the following defaults:
81
+
82
+ - injects readonly globals for `wx`, `Page`, `App`, `Component`, `getApp`, `getCurrentPages`, `requirePlugin`, and `WechatMiniprogram`
83
+ - ignores `dist/**`, `.weapp-vite/**`, `miniprogram_npm/**`, `node_modules/**`, `project.config.json`, and `project.private.config.json`
84
+ - when `vue: true` is also enabled, relaxes Vue template checks for Mini Program inline tags such as `<text>`
85
+
86
+ #### Native Mini Program Minimal Config
87
+
88
+ ```ts
89
+ import { icebreaker } from '@icebreakers/eslint-config'
90
+
91
+ export default icebreaker({
92
+ miniProgram: true,
93
+ })
94
+ ```
95
+
96
+ #### weapp-vite + wevu Minimal Config
97
+
98
+ ```ts
99
+ import { icebreaker } from '@icebreakers/eslint-config'
100
+
101
+ export default icebreaker({
102
+ miniProgram: true,
103
+ vue: true,
104
+ })
105
+ ```
106
+
107
+ #### Combining With Existing Options
108
+
109
+ ```ts
110
+ import { icebreaker } from '@icebreakers/eslint-config'
111
+
112
+ export default icebreaker({
113
+ miniProgram: true,
114
+ vue: true,
115
+ tailwindcss: true,
116
+ ignores: [
117
+ 'coverage/**',
118
+ ],
119
+ })
120
+ ```
121
+
122
+ `miniProgram` only adds the platform defaults. User supplied `ignores`,
123
+ `extends`, `rules`, and downstream flat config items still compose normally.
74
124
 
75
125
  ### Stylelint Bridge
76
126
 
package/README.zh.md CHANGED
@@ -54,12 +54,13 @@ export default icebreaker({
54
54
  a11y: true,
55
55
  nestjs: true,
56
56
  ionic: true,
57
- weapp: true,
57
+ miniProgram: true,
58
58
  formatters: true,
59
59
  })
60
60
  ```
61
61
 
62
- - `vue`:启用 Vue 规则,可根据 Vue 2/3 自动切换,并在 `ionic`、`weapp` 选项开启时追加对应覆盖。
62
+ - `miniProgram`:启用小程序预设,注入全局变量、忽略常见产物/配置文件,并在 `vue: true` 时补充小程序模板兼容调整。
63
+ - `vue`:启用 Vue 规则,可根据 Vue 2/3 自动切换,并在 `ionic`、`miniProgram` 选项开启时追加对应覆盖。
63
64
  - `react`:复用上游 React 预设,配合 `a11y` 注入无障碍插件。
64
65
  - `query`:按需启用 TanStack Query 插件(`@tanstack/eslint-plugin-query`)及其推荐规则。
65
66
  - `tailwindcss`:传入 `true` 使用内置 Tailwind flat 配置,或通过对象指定 Tailwind v4 的入口文件 / v3 的配置文件路径。
@@ -69,6 +70,55 @@ export default icebreaker({
69
70
  - `nestjs`:针对 NestJS 场景做 TypeScript 调整(允许带装饰器的空构造函数、依赖注入参数属性、声明合并等)。
70
71
  - `formatters`:默认启用格式化辅助规则。
71
72
  - `test`:放宽 Vitest / Jest 常见规则,例如关闭 `test/prefer-lowercase-title`。
73
+ - `weapp`:`miniProgram` 的兼容别名,保留但不再推荐作为主入口。
74
+
75
+ ### 小程序预设
76
+
77
+ 推荐在 `weapp-vite`、`wevu`、原生小程序模板里统一使用 `miniProgram: true`。
78
+ 它会默认完成:
79
+
80
+ - 注入 `wx`、`Page`、`App`、`Component`、`getApp`、`getCurrentPages`、`requirePlugin`、`WechatMiniprogram` 全局变量
81
+ - 忽略 `dist/**`、`.weapp-vite/**`、`miniprogram_npm/**`、`node_modules/**`、`project.config.json`、`project.private.config.json`
82
+ - 当同时开启 `vue: true` 时,降低 `<text>` 等小程序内联标签的误报
83
+
84
+ #### 原生小程序最小配置
85
+
86
+ ```ts
87
+ import { icebreaker } from '@icebreakers/eslint-config'
88
+
89
+ export default icebreaker({
90
+ miniProgram: true,
91
+ })
92
+ ```
93
+
94
+ #### weapp-vite + wevu 最小配置
95
+
96
+ ```ts
97
+ import { icebreaker } from '@icebreakers/eslint-config'
98
+
99
+ export default icebreaker({
100
+ miniProgram: true,
101
+ vue: true,
102
+ })
103
+ ```
104
+
105
+ #### 与现有选项组合
106
+
107
+ ```ts
108
+ import { icebreaker } from '@icebreakers/eslint-config'
109
+
110
+ export default icebreaker({
111
+ miniProgram: true,
112
+ vue: true,
113
+ tailwindcss: true,
114
+ ignores: [
115
+ 'coverage/**',
116
+ ],
117
+ })
118
+ ```
119
+
120
+ `miniProgram` 只负责追加平台默认项;你自己的 `ignores`、`extends`、`rules`
121
+ 以及额外 flat config 仍按原有方式继续组合。
72
122
 
73
123
  ### Stylelint 桥接
74
124
 
package/dist/index.cjs CHANGED
@@ -104,6 +104,9 @@ const nestjsTypeScriptRules = {
104
104
  types: { Function: false }
105
105
  }]
106
106
  };
107
+ function isMiniProgramEnabled(opts) {
108
+ return opts?.miniProgram === true || opts?.weapp === true;
109
+ }
107
110
  function getDefaultVueOptions(opts) {
108
111
  const overrides = {
109
112
  "vue/attribute-hyphenation": "off",
@@ -117,7 +120,7 @@ function getDefaultVueOptions(opts) {
117
120
  "vue/no-unused-refs": "warn"
118
121
  };
119
122
  if (opts?.ionic) overrides["vue/no-deprecated-slot-attribute"] = "off";
120
- if (opts?.weapp) overrides["vue/singleline-html-element-content-newline"] = ["warn", {
123
+ if (isMiniProgramEnabled(opts)) overrides["vue/singleline-html-element-content-newline"] = ["warn", {
121
124
  ignoreWhenNoAttributes: true,
122
125
  ignoreWhenEmpty: true,
123
126
  ignores: ["text", ...INLINE_ELEMENTS],
@@ -450,6 +453,10 @@ function resolveFormattersOption(input, cwd = node_process.default.cwd()) {
450
453
  }
451
454
  function resolveUserOptions(options) {
452
455
  const resolved = defu({}, options ?? {}, BASE_DEFAULTS);
456
+ if (isMiniProgramEnabled(options)) {
457
+ resolved.miniProgram = true;
458
+ delete resolved.weapp;
459
+ }
453
460
  const resolvedVue = mergeOptionWithDefaults(resolved.vue, getDefaultVueOptions(options), { postProcess: applyVueVersionSpecificRules });
454
461
  if (resolvedVue === void 0) delete resolved.vue;
455
462
  else resolved.vue = resolvedVue;
@@ -468,12 +475,37 @@ function createBaseRuleSet(isLegacy) {
468
475
  }
469
476
  //#endregion
470
477
  //#region src/preset.ts
478
+ const MINI_PROGRAM_IGNORES = [
479
+ "dist/**",
480
+ ".weapp-vite/**",
481
+ "miniprogram_npm/**",
482
+ "node_modules/**",
483
+ "project.config.json",
484
+ "project.private.config.json"
485
+ ];
486
+ const MINI_PROGRAM_GLOBALS = {
487
+ wx: "readonly",
488
+ Page: "readonly",
489
+ App: "readonly",
490
+ Component: "readonly",
491
+ getApp: "readonly",
492
+ getCurrentPages: "readonly",
493
+ requirePlugin: "readonly",
494
+ WechatMiniprogram: "readonly"
495
+ };
471
496
  function getPresets(options, mode) {
472
497
  const resolved = resolveUserOptions(options);
473
- const presets = [{ rules: createBaseRuleSet(mode === "legacy") }, {
474
- files: ["**/*.{css,scss,sass,less,pcss,postcss,json,jsonc,json5}"],
475
- rules: { "style/eol-last": "off" }
476
- }];
498
+ const presets = [
499
+ ...resolved.miniProgram ? [{ ignores: [...MINI_PROGRAM_IGNORES] }, {
500
+ files: ["**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,vue}"],
501
+ languageOptions: { globals: MINI_PROGRAM_GLOBALS }
502
+ }] : [],
503
+ { rules: createBaseRuleSet(mode === "legacy") },
504
+ {
505
+ files: ["**/*.{css,scss,sass,less,pcss,postcss,json,jsonc,json5}"],
506
+ rules: { "style/eol-last": "off" }
507
+ }
508
+ ];
477
509
  presets.push(...resolveStylelintBridgePresets(resolved.stylelint), ...resolveTailwindPresets(resolved.tailwindcss), ...resolveMdxPresets(resolved.mdx), ...resolveNestPresets(resolved.nestjs), ...resolveQueryPresets(resolved.query), ...resolveAccessibilityPresets(resolved.a11y, resolved.vue, resolved.react));
478
510
  return [resolved, ...presets];
479
511
  }
package/dist/index.d.cts CHANGED
@@ -2961,6 +2961,11 @@ interface StylelintBridgeOption {
2961
2961
  }
2962
2962
  type StylelintBridgeConfig = boolean | StylelintBridgeOption;
2963
2963
  type UserDefinedOptions = OptionsConfig & TypedFlatConfigItem$1 & {
2964
+ /**
2965
+ * Enable Mini Program support.
2966
+ * @default false
2967
+ */
2968
+ miniProgram?: boolean;
2964
2969
  /**
2965
2970
  * Enable TailwindCSS support
2966
2971
  * @default false
@@ -2998,6 +3003,7 @@ type UserDefinedOptions = OptionsConfig & TypedFlatConfigItem$1 & {
2998
3003
  ionic?: boolean;
2999
3004
  /**
3000
3005
  * Enable Weapp support
3006
+ * @deprecated Use `miniProgram` instead.
3001
3007
  * @default false
3002
3008
  */
3003
3009
  weapp?: boolean;
package/dist/index.d.ts CHANGED
@@ -2961,6 +2961,11 @@ interface StylelintBridgeOption {
2961
2961
  }
2962
2962
  type StylelintBridgeConfig = boolean | StylelintBridgeOption;
2963
2963
  type UserDefinedOptions = OptionsConfig & TypedFlatConfigItem$1 & {
2964
+ /**
2965
+ * Enable Mini Program support.
2966
+ * @default false
2967
+ */
2968
+ miniProgram?: boolean;
2964
2969
  /**
2965
2970
  * Enable TailwindCSS support
2966
2971
  * @default false
@@ -2998,6 +3003,7 @@ type UserDefinedOptions = OptionsConfig & TypedFlatConfigItem$1 & {
2998
3003
  ionic?: boolean;
2999
3004
  /**
3000
3005
  * Enable Weapp support
3006
+ * @deprecated Use `miniProgram` instead.
3001
3007
  * @default false
3002
3008
  */
3003
3009
  weapp?: boolean;
package/dist/index.js CHANGED
@@ -95,6 +95,9 @@ const nestjsTypeScriptRules = {
95
95
  types: { Function: false }
96
96
  }]
97
97
  };
98
+ function isMiniProgramEnabled(opts) {
99
+ return opts?.miniProgram === true || opts?.weapp === true;
100
+ }
98
101
  function getDefaultVueOptions(opts) {
99
102
  const overrides = {
100
103
  "vue/attribute-hyphenation": "off",
@@ -108,7 +111,7 @@ function getDefaultVueOptions(opts) {
108
111
  "vue/no-unused-refs": "warn"
109
112
  };
110
113
  if (opts?.ionic) overrides["vue/no-deprecated-slot-attribute"] = "off";
111
- if (opts?.weapp) overrides["vue/singleline-html-element-content-newline"] = ["warn", {
114
+ if (isMiniProgramEnabled(opts)) overrides["vue/singleline-html-element-content-newline"] = ["warn", {
112
115
  ignoreWhenNoAttributes: true,
113
116
  ignoreWhenEmpty: true,
114
117
  ignores: ["text", ...INLINE_ELEMENTS],
@@ -441,6 +444,10 @@ function resolveFormattersOption(input, cwd = process.cwd()) {
441
444
  }
442
445
  function resolveUserOptions(options) {
443
446
  const resolved = defu({}, options ?? {}, BASE_DEFAULTS);
447
+ if (isMiniProgramEnabled(options)) {
448
+ resolved.miniProgram = true;
449
+ delete resolved.weapp;
450
+ }
444
451
  const resolvedVue = mergeOptionWithDefaults(resolved.vue, getDefaultVueOptions(options), { postProcess: applyVueVersionSpecificRules });
445
452
  if (resolvedVue === void 0) delete resolved.vue;
446
453
  else resolved.vue = resolvedVue;
@@ -459,12 +466,37 @@ function createBaseRuleSet(isLegacy) {
459
466
  }
460
467
  //#endregion
461
468
  //#region src/preset.ts
469
+ const MINI_PROGRAM_IGNORES = [
470
+ "dist/**",
471
+ ".weapp-vite/**",
472
+ "miniprogram_npm/**",
473
+ "node_modules/**",
474
+ "project.config.json",
475
+ "project.private.config.json"
476
+ ];
477
+ const MINI_PROGRAM_GLOBALS = {
478
+ wx: "readonly",
479
+ Page: "readonly",
480
+ App: "readonly",
481
+ Component: "readonly",
482
+ getApp: "readonly",
483
+ getCurrentPages: "readonly",
484
+ requirePlugin: "readonly",
485
+ WechatMiniprogram: "readonly"
486
+ };
462
487
  function getPresets(options, mode) {
463
488
  const resolved = resolveUserOptions(options);
464
- const presets = [{ rules: createBaseRuleSet(mode === "legacy") }, {
465
- files: ["**/*.{css,scss,sass,less,pcss,postcss,json,jsonc,json5}"],
466
- rules: { "style/eol-last": "off" }
467
- }];
489
+ const presets = [
490
+ ...resolved.miniProgram ? [{ ignores: [...MINI_PROGRAM_IGNORES] }, {
491
+ files: ["**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,vue}"],
492
+ languageOptions: { globals: MINI_PROGRAM_GLOBALS }
493
+ }] : [],
494
+ { rules: createBaseRuleSet(mode === "legacy") },
495
+ {
496
+ files: ["**/*.{css,scss,sass,less,pcss,postcss,json,jsonc,json5}"],
497
+ rules: { "style/eol-last": "off" }
498
+ }
499
+ ];
468
500
  presets.push(...resolveStylelintBridgePresets(resolved.stylelint), ...resolveTailwindPresets(resolved.tailwindcss), ...resolveMdxPresets(resolved.mdx), ...resolveNestPresets(resolved.nestjs), ...resolveQueryPresets(resolved.query), ...resolveAccessibilityPresets(resolved.a11y, resolved.vue, resolved.react));
469
501
  return [resolved, ...presets];
470
502
  }
package/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export interface StylelintBridgeOption {
19
19
  export type StylelintBridgeConfig = boolean | StylelintBridgeOption
20
20
 
21
21
  export type UserDefinedOptions = OptionsConfig & TypedFlatConfigItem & {
22
+ miniProgram?: boolean
22
23
  tailwindcss?: TailwindcssConfig
23
24
  stylelint?: StylelintBridgeConfig
24
25
  mdx?: boolean
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@icebreakers/eslint-config",
3
3
  "type": "module",
4
- "version": "2.0.3",
4
+ "version": "2.1.0",
5
5
  "description": "ESLint preset from Icebreaker's dev-configs",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -58,7 +58,7 @@
58
58
  "eslint-plugin-react-refresh": "^0.5.2",
59
59
  "eslint-plugin-tailwindcss": "3.18.2",
60
60
  "eslint-plugin-vuejs-accessibility": "^2.5.0",
61
- "@icebreakers/stylelint-config": "2.1.2",
61
+ "@icebreakers/stylelint-config": "2.2.0",
62
62
  "eslint-plugin-better-stylelint": "0.1.1"
63
63
  },
64
64
  "optionalDependencies": {