@@ -18,16 +18,26 @@ type MessageIds = "issue:var" | "fix:let" | "fix:const";
1818
1919/**
2020 * The extra options that the rule can accept.
21- * These options are merged with the shared settings.
21+ * These options get merged with the shared settings.
2222 * The typing is not used by `eslint-doc-generator` which uses the `schema` property in the rule's metadata.
2323 * Yet, it is useful for the IDE to provide autocompletion and type checking.
2424 */
25- export type RuleOptions = {
25+ type RuleOptions = {
2626 someBool : boolean ;
2727 someEnum : string ;
28- } & PluginSettings ;
28+ } ;
2929
30- type Options = [ RuleOptions ] ;
30+ export type MergedOptions = RuleOptions & PluginSettings ;
31+
32+ const RULE_DEFAULT : RuleOptions = {
33+ someBool : false ,
34+ someEnum : "always" ,
35+ } ;
36+
37+ // TODO which one ?
38+ // - type Options = [RuleOptions];
39+ // - type Options = [MergedOptions];
40+ type Options = [ MergedOptions ] ;
3141
3242// The Rule creator returns a function that is used to create a well-typed ESLint rule
3343// The parameter passed into RuleCreator is a URL generator function.
@@ -54,13 +64,13 @@ export const myRule = createRule<Options, MessageIds>({
5464 someBool : {
5565 description : "someBool description." ,
5666 type : "boolean" ,
57- default : true ,
67+ default : RULE_DEFAULT . someBool ,
5868 } ,
5969 someEnum : {
6070 description : "someEnum description." ,
6171 type : "string" ,
6272 enum : [ "always" , "never" ] ,
63- default : "always" ,
73+ default : RULE_DEFAULT . someEnum ,
6474 } ,
6575 } ,
6676 additionalProperties : false ,
@@ -83,27 +93,29 @@ export const myRule = createRule<Options, MessageIds>({
8393 } ,
8494 ] ,
8595 create : ( context , options ) => {
96+ // Reading inline configuration
97+ console . log ( "\n" , new Date ( ) , "\n" , "Options (rule):" , "\n" , options [ 0 ] ) ;
98+
99+ // Shared settings
100+ const sharedSettings = ( context . settings ?. tailwindcss ||
101+ DEFAULTS ) as PluginSharedSettings ;
102+ console . log ( "\n" , "sharedSettings (rule):" , "\n" , sharedSettings ) ;
103+
104+ // Merged settings
105+ // const merged = parsePluginSettings(options[0]) as RuleOptions;
106+ const merged = parsePluginSettings < RuleOptions > ( {
107+ tailwindcss : options [ 0 ] ,
108+ } ) as RuleOptions ;
109+ console . log ( "\n" , "merged (rule):" , "\n" , merged ) ;
110+
86111 return {
87112 VariableDeclaration : ( node ) => {
113+ console . log ( "\n" , "merged.someBool:" , "\n" , merged . someBool ) ;
114+ if ( merged . someBool === true ) {
115+ console . log ( "someBool is true, processing VariableDeclaration" ) ;
116+ return ;
117+ }
88118 if ( node . kind === "var" ) {
89- // Reading inline configuration
90- console . log (
91- "\n" ,
92- new Date ( ) ,
93- "\n" ,
94- "Options (rule):" ,
95- "\n" ,
96- options [ 0 ]
97- ) ;
98- // Shared settings
99- const sharedSettings = ( context . settings ?. tailwindcss || {
100- stylesheet : "" ,
101- functions : [ ] ,
102- } ) as PluginSharedSettings ;
103- console . log ( "\n" , "sharedSettings (rule):" , "\n" , sharedSettings ) ;
104-
105- const merged : PluginSettings = parsePluginSettings ( context . settings ) ;
106- console . log ( "\n" , "merged (rule):" , "\n" , merged ) ;
107119 const rangeStart = node . range [ 0 ] ;
108120 const range : readonly [ number , number ] = [
109121 rangeStart ,
0 commit comments