Skip to content

Commit 754bb11

Browse files
committed
refactor: extract foreign-region helpers to satisfy funlen
Fold the config validation calls into validateConfigSemantics and the runner's foreign-region check into checkWithForeignRegions so loadFromBytes and lintFile stay under the funlen budget. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EwKxDxhjkTQPPkBrNhsrNG
1 parent f913d78 commit 754bb11

3 files changed

Lines changed: 26 additions & 13 deletions

File tree

internal/config/foreignregion.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ func EffectiveForeignRegions(cfg *Config, filePath string) []ForeignRegion {
2828
return out
2929
}
3030

31+
// validateConfigSemantics runs the post-parse structural checks that
32+
// depend on the fully-decoded config: kind graph validity and
33+
// foreign-region marker-pair well-formedness. Kept together so
34+
// loadFromBytes carries one call site rather than one per check.
35+
func validateConfigSemantics(cfg *Config) error {
36+
if err := ValidateKinds(cfg); err != nil {
37+
return err
38+
}
39+
return validateForeignRegions(cfg)
40+
}
41+
3142
// validateForeignRegions rejects malformed marker-pair declarations:
3243
// a blank start or end marker, or a pair whose start equals its end
3344
// (the scanner could never tell which line opens and which closes a

internal/config/load.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ func loadFromBytes(data []byte, sourcePath string, mergeKinds bool) (*Config, er
101101
return nil, err
102102
}
103103

104-
if err := ValidateKinds(&cfg); err != nil {
105-
return nil, fmt.Errorf("validating config: %w", err)
106-
}
107-
108-
if err := validateForeignRegions(&cfg); err != nil {
104+
if err := validateConfigSemantics(&cfg); err != nil {
109105
return nil, fmt.Errorf("validating config: %w", err)
110106
}
111107

internal/engine/runner.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,18 +486,11 @@ func (r *Runner) lintFile(path string, intraFileCap int, cache *lint.RunCache, r
486486
// directives, so it has no generated sections — leave the ranges nil.
487487
populateGeneratedRanges(f)
488488

489-
// Foreign-region ranges extend the same exclusion set from a plain
490-
// line scan (no AST needed), so style rules skip diagnostics inside a
491-
// marker pair another generator owns. Malformed pairs surface as
492-
// MDS073 diagnostics appended after the rule check.
493-
foreignDiags := foreignregion.Apply(f, r.Config, path)
494-
495489
// Configure the enabled rules once per config signature (cached on the
496490
// worker's confCache) and reuse the result across every file that shares
497491
// that config, instead of re-cloning every Configurable rule per file.
498492
configured, cfgErrs := rr.configured(sigKey, effective)
499-
diags := checker.CheckConfiguredRules(f, configured, r.SkipSourceContext, intraFileCap)
500-
diags = append(diags, foreignDiags...)
493+
diags := r.checkWithForeignRegions(f, configured, path, intraFileCap)
501494
if r.Explain {
502495
explain.Attach(diags, r.Config, path, fmKinds, fmFields)
503496
}
@@ -508,6 +501,19 @@ func (r *Runner) lintFile(path string, intraFileCap int, cache *lint.RunCache, r
508501
return fileOutcome{diags: diags, errs: cfgErrs}
509502
}
510503

504+
// checkWithForeignRegions extends f.GeneratedRanges with the foreign-
505+
// region spans that apply to path (a plain line scan, no AST needed) so
506+
// style rules skip diagnostics inside a marker pair another generator
507+
// owns, runs the configured rules, and appends the malformed-region
508+
// (MDS073) diagnostics for any unmatched or duplicated marker.
509+
func (r *Runner) checkWithForeignRegions(
510+
f *lint.File, configured []rule.Rule, path string, intraFileCap int,
511+
) []lint.Diagnostic {
512+
foreignDiags := foreignregion.Apply(f, r.Config, path)
513+
diags := checker.CheckConfiguredRules(f, configured, r.SkipSourceContext, intraFileCap)
514+
return append(diags, foreignDiags...)
515+
}
516+
511517
// populateGeneratedRanges fills f.GeneratedRanges from the include/catalog
512518
// markers in its AST. The flat Layer-0 and Layer 0 parse-skip paths leave
513519
// f.AST nil (and only take that path for files with no such directive, so

0 commit comments

Comments
 (0)