@@ -12,11 +12,9 @@ let readmeContent = fs.readFileSync(readmePath, 'utf8');
1212function getRuleMetadata ( ruleRegistry ) {
1313 const rules = [ ] ;
1414 const allRuleIds = ruleRegistry . getAllRuleIds ( true ) ; // Include beta rules
15-
1615 for ( const ruleId of allRuleIds ) {
1716 const entry = ruleRegistry . get ( ruleId ) ;
1817 const instance = ruleRegistry . createInstance ( ruleId ) ;
19-
2018 rules . push ( {
2119 ruleId : instance . ruleId ,
2220 className : entry . legacyName ,
@@ -27,27 +25,22 @@ function getRuleMetadata(ruleRegistry) {
2725 isBeta : entry . isBeta
2826 } ) ;
2927 }
30-
3128 return rules ;
3229}
3330
3431// 2. Sort rules by category, then severity, then alphabetically
3532function sortRules ( rules ) {
3633 const categoryOrder = { 'problem' : 1 , 'suggestion' : 2 , 'layout' : 3 } ;
3734 const severityOrder = { 'error' : 1 , 'warning' : 2 , 'note' : 3 } ;
38-
3935 return rules . sort ( ( a , b ) => {
40- // Sort by category first
4136 const catA = categoryOrder [ a . category ] || 999 ;
4237 const catB = categoryOrder [ b . category ] || 999 ;
4338 if ( catA !== catB ) return catA - catB ;
4439
45- // Then by severity
4640 const sevA = severityOrder [ a . severity ?. toLowerCase ( ) ] || 999 ;
4741 const sevB = severityOrder [ b . severity ?. toLowerCase ( ) ] || 999 ;
4842 if ( sevA !== sevB ) return sevA - sevB ;
4943
50- // Finally alphabetically by title
5144 return a . title . localeCompare ( b . title ) ;
5245 } ) ;
5346}
@@ -62,51 +55,60 @@ function formatSeverity(severity) {
6255 return severityMap [ severity ?. toLowerCase ( ) ] || '🟡 *Warning*' ;
6356}
6457
65- // 4. Format each rule as markdown
58+ // 4. Format each rule as markdown (now using ####)
6659function formatRule ( rule ) {
6760 const betaBadge = rule . isBeta
6861 ? ' '
6962 : '' ;
70-
71- return `### ${ rule . title } ${ betaBadge }
63+ return `#### ${ rule . title } ${ betaBadge }
7264${ rule . description }
73-
7465**Rule ID:** \`${ rule . ruleId } \`
7566**Class Name:** _[${ rule . className } ](packages/core/src/main/rules/${ rule . className } .ts)_
7667**Severity:** ${ formatSeverity ( rule . severity ) } ` ;
7768}
7869
79- // 5. Build rules content with category headers
70+ // 5. Build rules content with category headers + formal introductions
8071function buildRulesContent ( rules ) {
81- const categoryLabels = {
82- 'problem' : '### Problems' ,
83- 'suggestion' : '### Suggestions' ,
84- 'layout' : '### Layout'
72+ const categoryInfo = {
73+ 'problem' : {
74+ header : '### Problems' ,
75+ intro : 'Rules that detect issues highly likely to cause runtime errors, security risks, governor limit exceptions, or deployment failures.'
76+ } ,
77+ 'suggestion' : {
78+ header : '### Suggestions' ,
79+ intro : 'Rules in this category recommend better patterns and optimizations related to performance, bulkification, trigger behavior, and overall design. Following them improves efficiency and long-term maintainability without affecting correctness.'
80+ } ,
81+ 'layout' : {
82+ header : '### Layout' ,
83+ intro : 'Rules in this category enforce consistency in naming, documentation, element organization, and visual layout. They help ensure Flows remain readable, well-documented, and structured as automations scale.'
84+ }
8585 } ;
8686
8787 let content = '' ;
8888 let currentCategory = null ;
8989
9090 for ( const rule of rules ) {
91- // Add category header if we've moved to a new category
9291 if ( rule . category !== currentCategory ) {
93- if ( content ) content += '\n\n' ; // Add spacing before new category (except first)
94- content += categoryLabels [ rule . category ] || '## Other' ;
95- content += '\n\n' ;
92+ // Add spacing before new category (except the very first one)
93+ if ( content ) content += '\n' ;
94+
95+ const info = categoryInfo [ rule . category ] || { header : '### Other' , intro : '' } ;
96+ content += info . header + '\n\n' ;
97+ content += info . intro + '\n\n' ;
98+
9699 currentCategory = rule . category ;
97100 }
98101
99102 content += formatRule ( rule ) + '\n\n' ;
100103 }
101104
102- return content . trimEnd ( ) ; // Remove trailing newlines
105+ return content . trimEnd ( ) ;
103106}
104107
105108// 6. Replace content between markers
106109function updateReadmeWithRules ( readmeContent , rulesContent ) {
107110 const startMarker = '<!-- START GENERATED_RULES -->' ;
108111 const endMarker = '<!-- END GENERATED_RULES -->' ;
109-
110112 const startIndex = readmeContent . indexOf ( startMarker ) ;
111113 const endIndex = readmeContent . indexOf ( endMarker ) ;
112114
@@ -117,34 +119,29 @@ function updateReadmeWithRules(readmeContent, rulesContent) {
117119 const before = readmeContent . substring ( 0 , startIndex + startMarker . length ) ;
118120 const after = readmeContent . substring ( endIndex ) ;
119121
120- return before + '\n' + rulesContent + '\n' + after ;
122+ return before + '\n\n ' + rulesContent + '\n' + after ;
121123}
122124
123125// Main execution
124126try {
125127 console . log ( '📖 Generating README from rule source code...\n' ) ;
126128
127- // Step 1: Extract metadata from rules
128129 console . log ( '1️⃣ Extracting rule metadata from RuleRegistry...' ) ;
129130 const rules = getRuleMetadata ( ruleRegistry ) ;
130131 console . log ( ` ✅ Found ${ rules . length } rules (${ rules . filter ( r => r . isBeta ) . length } beta)\n` ) ;
131132
132- // Step 2: Sort rules
133133 console . log ( '2️⃣ Sorting rules by category, severity, and alphabetically...' ) ;
134134 const sortedRules = sortRules ( rules ) ;
135135 console . log ( ` ✅ Rules sorted\n` ) ;
136136
137- // Step 3: Build rules content
138- console . log ( '3️⃣ Building rules content...' ) ;
137+ console . log ( '3️⃣ Building rules content with category introductions...' ) ;
139138 const rulesContent = buildRulesContent ( sortedRules ) ;
140139 console . log ( ` ✅ Rules content built\n` ) ;
141140
142- // Step 4: Update README between markers
143141 console . log ( '4️⃣ Updating README.md...' ) ;
144142 const updatedReadme = updateReadmeWithRules ( readmeContent , rulesContent ) ;
145143 console . log ( ` ✅ README updated\n` ) ;
146144
147- // Step 5: Write to file
148145 console . log ( '5️⃣ Writing to README.md...' ) ;
149146 fs . writeFileSync ( readmePath , updatedReadme , 'utf8' ) ;
150147 console . log ( ` ✅ Written to ${ readmePath } \n` ) ;
@@ -155,9 +152,8 @@ try {
155152 const betaLabel = rule . isBeta ? ' [BETA]' : '' ;
156153 console . log ( ` - ${ rule . title } ${ betaLabel } ` ) ;
157154 } ) ;
158-
159155} catch ( error ) {
160156 console . error ( '❌ Error generating README:' , error . message ) ;
161157 console . error ( error . stack ) ;
162158 process . exit ( 1 ) ;
163- }
159+ }
0 commit comments