88
99 "github.com/jeduden/mdsmith/internal/lint"
1010 "github.com/jeduden/mdsmith/internal/rule"
11+ "github.com/jeduden/mdsmith/internal/rules/settings"
1112 "github.com/yuin/goldmark/ast"
1213)
1314
@@ -55,8 +56,8 @@ func (r *Rule) isExcluded(category string) bool {
5556}
5657
5758// ApplySettings implements rule.Configurable.
58- func (r * Rule ) ApplySettings (settings map [string ]any ) error {
59- for k , v := range settings {
59+ func (r * Rule ) ApplySettings (s map [string ]any ) error {
60+ for k , v := range s {
6061 if err := r .applySetting (k , v ); err != nil {
6162 return err
6263 }
@@ -84,7 +85,7 @@ func (r *Rule) applySetting(k string, v any) error {
8485}
8586
8687func (r * Rule ) applyMax (v any ) error {
87- n , ok := toInt (v )
88+ n , ok := settings . ToInt (v )
8889 if ! ok {
8990 return fmt .Errorf ("line-length: max must be an integer, got %T" , v )
9091 }
@@ -93,7 +94,7 @@ func (r *Rule) applyMax(v any) error {
9394}
9495
9596func (r * Rule ) applyPositiveIntPtr (v any , name string , target * * int ) error {
96- n , ok := toInt (v )
97+ n , ok := settings . ToInt (v )
9798 if ! ok {
9899 return fmt .Errorf ("line-length: %s must be an integer, got %T" , name , v )
99100 }
@@ -114,7 +115,7 @@ func (r *Rule) applyStern(v any) error {
114115}
115116
116117func (r * Rule ) applyExclude (v any ) error {
117- list , ok := toStringSlice (v )
118+ list , ok := settings . ToStringSlice (v )
118119 if ! ok {
119120 return fmt .Errorf ("line-length: exclude must be a list of strings, got %T" , v )
120121 }
@@ -315,40 +316,6 @@ func headingLineNum(h *ast.Heading, f *lint.File) int {
315316 return 0
316317}
317318
318- // toInt converts a value to int. Supports int and float64 (YAML decodes
319- // numbers as int or float64 depending on context).
320- func toInt (v any ) (int , bool ) {
321- switch n := v .(type ) {
322- case int :
323- return n , true
324- case float64 :
325- return int (n ), true
326- case int64 :
327- return int (n ), true
328- }
329- return 0 , false
330- }
331-
332- // toStringSlice converts a value to []string. YAML decodes sequences as
333- // []any with string elements.
334- func toStringSlice (v any ) ([]string , bool ) {
335- switch s := v .(type ) {
336- case []string :
337- return s , true
338- case []any :
339- result := make ([]string , 0 , len (s ))
340- for _ , item := range s {
341- str , ok := item .(string )
342- if ! ok {
343- return nil , false
344- }
345- result = append (result , str )
346- }
347- return result , true
348- }
349- return nil , false
350- }
351-
352319func isValidExclude (s string ) bool {
353320 return s == "code-blocks" || s == "tables" || s == "urls"
354321}
0 commit comments