|
1 | | -import type { BaseRuleListener, RuleModule } from "../types"; |
| 1 | +import type { BaseRuleListener, PartialRuleModule, RuleModule } from "../types"; |
2 | 2 | import { createRule } from "../utils"; |
3 | 3 | import { getAutoConfig } from "../utils/get-auto-jsonc-rules-config"; |
4 | 4 |
|
@@ -30,7 +30,7 @@ export default createRule("auto", { |
30 | 30 | ).default; |
31 | 31 | const subContext: any = { |
32 | 32 | __proto__: context, |
33 | | - options: getRuleOptions(autoConfig[ruleId]), |
| 33 | + options: getRuleOptions(autoConfig[ruleId], rule.jsoncDefineRule), |
34 | 34 | report(options: any) { |
35 | 35 | if (options.messageId) { |
36 | 36 | options.message = `[${ruleId}] ${ |
@@ -72,9 +72,17 @@ export default createRule("auto", { |
72 | 72 | /** |
73 | 73 | * Build the options to create the rule. |
74 | 74 | */ |
75 | | -function getRuleOptions(options: number | string | any[]): any[] { |
76 | | - if (!Array.isArray(options)) { |
77 | | - return []; |
| 75 | +function getRuleOptions( |
| 76 | + options: number | string | any[], |
| 77 | + rule: PartialRuleModule, |
| 78 | +): any[] { |
| 79 | + const jsonOptions = Array.isArray(options) ? options.slice(1) : []; |
| 80 | + if (rule.meta.defaultOptions) { |
| 81 | + rule.meta.defaultOptions.forEach((option, index) => { |
| 82 | + if (jsonOptions[index] === undefined) { |
| 83 | + jsonOptions[index] = option; |
| 84 | + } |
| 85 | + }); |
78 | 86 | } |
79 | | - return options.slice(1); |
| 87 | + return jsonOptions; |
80 | 88 | } |
0 commit comments