Function bodies 497 total
gensection.Engine.checkPair method · go · L61-L90 (30 LOC)internal/archetype/gensection/engine.go
func (e *Engine) checkPair(f *lint.File, mp MarkerPair) []lint.Diagnostic {
dir, diags := ParseDirective(
f.Path, mp,
e.directive.RuleID(), e.directive.RuleName(),
)
if dir == nil || len(diags) > 0 {
return diags
}
valDiags := e.directive.Validate(f.Path, mp.StartLine, dir.Params, dir.Columns)
if len(valDiags) > 0 {
return valDiags
}
expected, genDiags := e.directive.Generate(f, f.Path, mp.StartLine, dir.Params, dir.Columns)
if len(genDiags) > 0 {
return genDiags
}
actual := ExtractContent(f, mp)
if actual != expected {
return []lint.Diagnostic{
MakeDiag(e.directive.RuleID(), e.directive.RuleName(),
f.Path, mp.StartLine,
"generated section is out of date"),
}
}
return nil
}gensection.Engine.generateContent method · go · L95-L114 (20 LOC)internal/archetype/gensection/engine.go
func (e *Engine) generateContent(f *lint.File, mp MarkerPair) (string, bool) {
dir, diags := ParseDirective(
f.Path, mp,
e.directive.RuleID(), e.directive.RuleName(),
)
if dir == nil || len(diags) > 0 {
return "", false
}
moreDiags := e.directive.Validate(f.Path, mp.StartLine, dir.Params, dir.Columns)
if len(moreDiags) > 0 {
return "", false
}
content, genDiags := e.directive.Generate(f, f.Path, mp.StartLine, dir.Params, dir.Columns)
if len(genDiags) > 0 {
return "", false
}
return content, true
}gensection.ExtractContent function · go · L117-L129 (13 LOC)internal/archetype/gensection/engine.go
func ExtractContent(f *lint.File, mp MarkerPair) string {
if mp.ContentFrom > mp.ContentTo {
return ""
}
var lines []string
for i := mp.ContentFrom - 1; i <= mp.ContentTo-1 && i < len(f.Lines); i++ {
lines = append(lines, string(f.Lines[i]))
}
if len(lines) == 0 {
return ""
}
return strings.Join(lines, "\n") + "\n"
}gensection.ReplaceContent function · go · L132-L153 (22 LOC)internal/archetype/gensection/engine.go
func ReplaceContent(f *lint.File, mp MarkerPair, content string) []byte {
var result []byte
// Lines before content.
for i := 0; i < mp.ContentFrom-1 && i < len(f.Lines); i++ {
result = append(result, f.Lines[i]...)
result = append(result, '\n')
}
// New content.
result = append(result, []byte(content)...)
// Lines from end marker onward.
for i := mp.EndLine - 1; i < len(f.Lines); i++ {
result = append(result, f.Lines[i]...)
if i < len(f.Lines)-1 {
result = append(result, '\n')
}
}
return result
}gensection.SplitLines function · go · L156-L167 (12 LOC)internal/archetype/gensection/engine.go
func SplitLines(source []byte) [][]byte {
var lines [][]byte
start := 0
for i, b := range source {
if b == '\n' {
lines = append(lines, source[start:i])
start = i + 1
}
}
lines = append(lines, source[start:])
return lines
}gensection.EnsureTrailingNewline function · go · L170-L175 (6 LOC)internal/archetype/gensection/engine.go
func EnsureTrailingNewline(s string) string {
if strings.HasSuffix(s, "\n") {
return s
}
return s + "\n"
}gensection.MakeDiag function · go · L39-L49 (11 LOC)internal/archetype/gensection/parse.go
func MakeDiag(ruleID, ruleName, filePath string, line int, message string) lint.Diagnostic {
return lint.Diagnostic{
File: filePath,
Line: line,
Column: 1,
RuleID: ruleID,
RuleName: ruleName,
Severity: lint.Error,
Message: message,
}
}Repobility — same analyzer, your code, free for public repos · /scan/
gensection.FindMarkerPairs function · go · L54-L80 (27 LOC)internal/archetype/gensection/parse.go
func FindMarkerPairs(
f *lint.File,
startPrefix, endMarker, ruleID, ruleName string,
) ([]MarkerPair, []lint.Diagnostic) {
ignored := CollectIgnoredLines(f, startPrefix, endMarker)
state := &markerScanState{}
for i, line := range f.Lines {
lineNum := i + 1
if ignored[lineNum] {
continue
}
trimmed := strings.TrimSpace(string(line))
processMarkerLine(
f, state, lineNum, string(line), trimmed,
startPrefix, endMarker, ruleID, ruleName,
)
}
if state.current != nil {
state.diags = append(state.diags,
MakeDiag(ruleID, ruleName, f.Path, state.current.StartLine,
"generated section has no closing marker"))
}
return state.pairs, state.diags
}gensection.processMarkerLine function · go · L83-L103 (21 LOC)internal/archetype/gensection/parse.go
func processMarkerLine(
f *lint.File, s *markerScanState, lineNum int, line, trimmed string,
startPrefix, endMarker, ruleID, ruleName string,
) {
if s.current != nil && s.inYAMLBody {
if trimmed == "-->" {
s.current.ContentFrom = lineNum + 1
s.inYAMLBody = false
return
}
s.current.YAMLBody += line + "\n"
return
}
if s.current != nil {
processLineInsidePair(f, s, lineNum, trimmed, startPrefix, endMarker, ruleID, ruleName)
return
}
processLineOutsidePair(f, s, lineNum, trimmed, startPrefix, endMarker, ruleID, ruleName)
}gensection.processLineInsidePair function · go · L107-L123 (17 LOC)internal/archetype/gensection/parse.go
func processLineInsidePair(
f *lint.File, s *markerScanState, lineNum int, trimmed string,
startPrefix, endMarker, ruleID, ruleName string,
) {
if strings.HasPrefix(trimmed, startPrefix) {
s.diags = append(s.diags,
MakeDiag(ruleID, ruleName, f.Path, lineNum,
"nested generated section markers are not allowed"))
return
}
if trimmed == endMarker {
s.current.EndLine = lineNum
s.current.ContentTo = lineNum - 1
s.pairs = append(s.pairs, *s.current)
s.current = nil
}
}gensection.processLineOutsidePair function · go · L126-L149 (24 LOC)internal/archetype/gensection/parse.go
func processLineOutsidePair(
f *lint.File, s *markerScanState, lineNum int, trimmed string,
startPrefix, endMarker, ruleID, ruleName string,
) {
if trimmed == endMarker {
s.diags = append(s.diags,
MakeDiag(ruleID, ruleName, f.Path, lineNum,
"unexpected generated section end marker"))
return
}
if strings.HasPrefix(trimmed, startPrefix) {
mp := MarkerPair{StartLine: lineNum, FirstLine: trimmed}
rest := trimmed[len(startPrefix):]
if strings.HasSuffix(rest, "-->") {
rest = strings.TrimSuffix(rest, "-->")
mp.FirstLine = startPrefix + rest
mp.ContentFrom = lineNum + 1
} else {
s.inYAMLBody = true
}
s.current = &mp
}
}gensection.ParseDirective function · go · L152-L171 (20 LOC)internal/archetype/gensection/parse.go
func ParseDirective(
filePath string, mp MarkerPair, ruleID, ruleName string,
) (*ParsedDirective, []lint.Diagnostic) {
rawMap, diags := ParseYAMLBody(filePath, mp, ruleID, ruleName)
if len(diags) > 0 {
return nil, diags
}
columnsRaw := ExtractColumnsRaw(rawMap)
params, diags := ValidateStringParams(filePath, mp.StartLine, rawMap, ruleID, ruleName)
if len(diags) > 0 {
return nil, diags
}
return &ParsedDirective{
Params: params,
Columns: ParseColumnConfig(columnsRaw),
}, nil
}gensection.ParseYAMLBody function · go · L174-L190 (17 LOC)internal/archetype/gensection/parse.go
func ParseYAMLBody(
filePath string, mp MarkerPair, ruleID, ruleName string,
) (map[string]any, []lint.Diagnostic) {
var rawMap map[string]any
if mp.YAMLBody != "" {
if err := yaml.Unmarshal([]byte(mp.YAMLBody), &rawMap); err != nil {
return nil, []lint.Diagnostic{
MakeDiag(ruleID, ruleName, filePath, mp.StartLine,
fmt.Sprintf("generated section has invalid YAML: %v", err)),
}
}
}
if rawMap == nil {
rawMap = map[string]any{}
}
return rawMap, nil
}gensection.ExtractColumnsRaw function · go · L193-L203 (11 LOC)internal/archetype/gensection/parse.go
func ExtractColumnsRaw(rawMap map[string]any) map[string]any {
v, ok := rawMap["columns"]
if !ok {
return nil
}
delete(rawMap, "columns")
if m, ok := v.(map[string]any); ok {
return m
}
return nil
}gensection.ValidateStringParams function · go · L206-L225 (20 LOC)internal/archetype/gensection/parse.go
func ValidateStringParams(
filePath string, line int, rawMap map[string]any, ruleID, ruleName string,
) (map[string]string, []lint.Diagnostic) {
var diags []lint.Diagnostic
params := make(map[string]string)
for k, v := range rawMap {
s, ok := v.(string)
if !ok {
diags = append(diags,
MakeDiag(ruleID, ruleName, filePath, line,
fmt.Sprintf("generated section has non-string value for key %q", k)))
} else {
params[k] = s
}
}
if len(diags) > 0 {
return nil, diags
}
return params, nil
}Open data scored by Repobility · https://repobility.com
gensection.ParseColumnConfig function · go · L228-L263 (36 LOC)internal/archetype/gensection/parse.go
func ParseColumnConfig(raw map[string]any) map[string]ColumnConfig {
if raw == nil {
return nil
}
result := make(map[string]ColumnConfig, len(raw))
for name, v := range raw {
colMap, ok := v.(map[string]any)
if !ok {
continue
}
cc := ColumnConfig{
Wrap: "truncate",
}
if mw, ok := colMap["max-width"]; ok {
switch val := mw.(type) {
case int:
cc.MaxWidth = val
case float64:
cc.MaxWidth = int(val)
}
}
if w, ok := colMap["wrap"]; ok {
if ws, ok := w.(string); ok {
cc.Wrap = ws
}
}
result[name] = cc
}
return result
}gensection.CollectIgnoredLines function · go · L267-L288 (22 LOC)internal/archetype/gensection/parse.go
func CollectIgnoredLines(f *lint.File, startPrefix, endMarker string) map[int]bool {
lines := map[int]bool{}
_ = ast.Walk(f.AST, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
if !entering {
return ast.WalkContinue, nil
}
switch cb := n.(type) {
case *ast.FencedCodeBlock:
addBlockLineRange(f, cb, lines)
case *ast.CodeBlock:
addBlockLineRange(f, cb, lines)
case *ast.HTMLBlock:
addHTMLBlockLines(f, cb, lines, startPrefix, endMarker)
}
return ast.WalkContinue, nil
})
return lines
}gensection.addBlockLineRange function · go · L291-L312 (22 LOC)internal/archetype/gensection/parse.go
func addBlockLineRange(f *lint.File, n ast.Node, set map[int]bool) {
if n.Lines().Len() == 0 {
return
}
firstSeg := n.Lines().At(0)
lastSeg := n.Lines().At(n.Lines().Len() - 1)
startLine := f.LineOfOffset(firstSeg.Start)
endLine := f.LineOfOffset(lastSeg.Start)
if _, ok := n.(*ast.FencedCodeBlock); ok {
if startLine > 1 {
startLine--
}
endLine++
}
for ln := startLine; ln <= endLine && ln <= len(f.Lines); ln++ {
set[ln] = true
}
}gensection.addHTMLBlockLines function · go · L317-L343 (27 LOC)internal/archetype/gensection/parse.go
func addHTMLBlockLines(f *lint.File, n *ast.HTMLBlock, set map[int]bool, startPrefix, endMarker string) {
if n.Lines().Len() == 0 {
return
}
firstSeg := n.Lines().At(0)
firstLineText := strings.TrimSpace(string(firstSeg.Value(f.Source)))
if strings.HasPrefix(firstLineText, startPrefix) || firstLineText == endMarker {
return
}
lastSeg := n.Lines().At(n.Lines().Len() - 1)
startLine := f.LineOfOffset(firstSeg.Start)
endLine := f.LineOfOffset(lastSeg.Start)
if n.HasClosure() {
closureLine := f.LineOfOffset(n.ClosureLine.Start)
if closureLine > endLine {
endLine = closureLine
}
}
for ln := startLine; ln <= endLine && ln <= len(f.Lines); ln++ {
set[ln] = true
}
}config.RuleCfg.UnmarshalYAML method · go · L67-L90 (24 LOC)internal/config/config.go
func (r *RuleCfg) UnmarshalYAML(value *yaml.Node) error {
// Try bool first
if value.Kind == yaml.ScalarNode {
var b bool
if err := value.Decode(&b); err == nil {
r.Enabled = b
r.Settings = nil
return nil
}
}
// Try map
if value.Kind == yaml.MappingNode {
var m map[string]any
if err := value.Decode(&m); err != nil {
return fmt.Errorf("invalid rule config: %w", err)
}
r.Enabled = true
r.Settings = m
return nil
}
return fmt.Errorf("rule config must be a bool or a mapping, got %v", value.Kind)
}config.RuleCfg.MarshalYAML method · go · L96-L104 (9 LOC)internal/config/config.go
func (r RuleCfg) MarshalYAML() (any, error) {
if !r.Enabled && r.Settings == nil {
return false, nil
}
if r.Enabled && len(r.Settings) > 0 {
return r.Settings, nil
}
return true, nil
}config.IsIgnored function · go · L12-L25 (14 LOC)internal/config/ignore.go
func IsIgnored(patterns []string, path string) bool {
cleanPath := filepath.Clean(path)
for _, pattern := range patterns {
g, err := glob.Compile(pattern)
if err != nil {
continue
}
if g.Match(path) || g.Match(cleanPath) || g.Match(filepath.Base(path)) {
return true
}
}
return false
}config.Load function · go · L15-L30 (16 LOC)internal/config/load.go
func Load(path string) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("reading config file: %w", err)
}
var cfg Config
if err := yaml.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("parsing config file: %w", err)
}
// Detect whether the "files" key was explicitly present in the YAML.
cfg.FilesExplicit = yamlHasKey(data, "files")
return &cfg, nil
}Repobility · open methodology · https://repobility.com/research/
config.yamlHasKey function · go · L33-L51 (19 LOC)internal/config/load.go
func yamlHasKey(data []byte, key string) bool {
var node yaml.Node
if err := yaml.Unmarshal(data, &node); err != nil {
return false
}
if node.Kind != yaml.DocumentNode || len(node.Content) == 0 {
return false
}
mapping := node.Content[0]
if mapping.Kind != yaml.MappingNode {
return false
}
for i := 0; i < len(mapping.Content)-1; i += 2 {
if mapping.Content[i].Value == key {
return true
}
}
return false
}config.Discover function · go · L57-L83 (27 LOC)internal/config/load.go
func Discover(startDir string) (string, error) {
dir, err := filepath.Abs(startDir)
if err != nil {
return "", fmt.Errorf("resolving absolute path: %w", err)
}
for {
candidate := filepath.Join(dir, configFileName)
if _, err := os.Stat(candidate); err == nil {
return candidate, nil
}
// Check for .git boundary — if .git exists in this dir,
// this is the repo root and we should not search further up.
gitDir := filepath.Join(dir, ".git")
if info, err := os.Stat(gitDir); err == nil && info.IsDir() {
return "", nil
}
parent := filepath.Dir(dir)
if parent == dir {
// Reached filesystem root
return "", nil
}
dir = parent
}
}config.Defaults function · go · L87-L97 (11 LOC)internal/config/load.go
func Defaults() *Config {
all := rule.All()
rules := make(map[string]RuleCfg, len(all))
for _, r := range all {
rules[r.Name()] = RuleCfg{Enabled: enabledByDefault(r)}
}
return &Config{
Rules: rules,
Files: DefaultFiles,
}
}config.DumpDefaults function · go · L104-L128 (25 LOC)internal/config/load.go
func DumpDefaults() *Config {
all := rule.All()
rules := make(map[string]RuleCfg, len(all))
for _, r := range all {
enabled := enabledByDefault(r)
rc := RuleCfg{Enabled: enabled}
if enabled {
if c, ok := r.(rule.Configurable); ok {
rc.Settings = c.DefaultSettings()
}
}
rules[r.Name()] = rc
}
categories := make(map[string]bool, len(ValidCategories))
for _, cat := range ValidCategories {
categories[cat] = true
}
return &Config{
Rules: rules,
Categories: categories,
Files: DefaultFiles,
}
}config.enabledByDefault function · go · L130-L135 (6 LOC)internal/config/load.go
func enabledByDefault(r rule.Rule) bool {
if d, ok := r.(rule.Defaultable); ok {
return d.EnabledByDefault()
}
return true
}config.Merge function · go · L12-L74 (63 LOC)internal/config/merge.go
func Merge(defaults, loaded *Config) *Config {
if loaded == nil {
// No user config: return a copy of defaults.
rules := make(map[string]RuleCfg, len(defaults.Rules))
for k, v := range defaults.Rules {
rules[k] = v
}
cats := copyCategories(defaults.Categories)
files := copyStrings(defaults.Files)
noFollow := copyStrings(defaults.NoFollowSymlinks)
return &Config{
Rules: rules,
FrontMatter: defaults.FrontMatter,
Categories: cats,
Files: files,
NoFollowSymlinks: noFollow,
}
}
rules := make(map[string]RuleCfg, len(defaults.Rules))
for k, v := range defaults.Rules {
rules[k] = v
}
// Apply loaded rules on top.
for k, v := range loaded.Rules {
rules[k] = v
}
fm := defaults.FrontMatter
if loaded.FrontMatter != nil {
fm = loaded.FrontMatter
}
// Merge categories: start with defaults, apply loaded on top.
cats := mergeCategories(defaults.Categories, loaded.Categories)
// Merge files: loaded overrides dconfig.copyStrings function · go · L77-L84 (8 LOC)internal/config/merge.go
func copyStrings(s []string) []string {
if s == nil {
return nil
}
result := make([]string, len(s))
copy(result, s)
return result
}config.copyCategories function · go · L88-L97 (10 LOC)internal/config/merge.go
func copyCategories(cats map[string]bool) map[string]bool {
if cats == nil {
return nil
}
result := make(map[string]bool, len(cats))
for k, v := range cats {
result[k] = v
}
return result
}Repobility · severity-and-effort ranking · https://repobility.com
config.mergeCategories function · go · L102-L114 (13 LOC)internal/config/merge.go
func mergeCategories(base, override map[string]bool) map[string]bool {
if base == nil && override == nil {
return nil
}
result := make(map[string]bool, len(ValidCategories))
for k, v := range base {
result[k] = v
}
for k, v := range override {
result[k] = v
}
return result
}config.Effective function · go · L119-L134 (16 LOC)internal/config/merge.go
func Effective(cfg *Config, filePath string) map[string]RuleCfg {
result := make(map[string]RuleCfg, len(cfg.Rules))
for k, v := range cfg.Rules {
result[k] = v
}
for _, o := range cfg.Overrides {
if matchesAny(o.Files, filePath) {
for k, v := range o.Rules {
result[k] = v
}
}
}
return result
}config.EffectiveExplicitRules function · go · L139-L154 (16 LOC)internal/config/merge.go
func EffectiveExplicitRules(cfg *Config, filePath string) map[string]bool {
result := make(map[string]bool, len(cfg.ExplicitRules))
for k := range cfg.ExplicitRules {
result[k] = true
}
for _, o := range cfg.Overrides {
if matchesAny(o.Files, filePath) {
for k := range o.Rules {
result[k] = true
}
}
}
return result
}config.EffectiveCategories function · go · L160-L182 (23 LOC)internal/config/merge.go
func EffectiveCategories(cfg *Config, filePath string) map[string]bool {
// Start with all categories enabled.
result := make(map[string]bool, len(ValidCategories))
for _, cat := range ValidCategories {
result[cat] = true
}
// Apply top-level category settings.
for k, v := range cfg.Categories {
result[k] = v
}
// Apply matching overrides in order.
for _, o := range cfg.Overrides {
if matchesAny(o.Files, filePath) {
for k, v := range o.Categories {
result[k] = v
}
}
}
return result
}config.ApplyCategories function · go · L189-L207 (19 LOC)internal/config/merge.go
func ApplyCategories(
rules map[string]RuleCfg,
categories map[string]bool,
ruleCategory func(ruleName string) string,
explicit map[string]bool,
) map[string]RuleCfg {
result := make(map[string]RuleCfg, len(rules))
for name, cfg := range rules {
cat := ruleCategory(name)
enabled, catSet := categories[cat]
if catSet && !enabled && !explicit[name] {
// Category is disabled and rule is not explicitly configured.
result[name] = RuleCfg{Enabled: false, Settings: cfg.Settings}
} else {
result[name] = cfg
}
}
return result
}config.matchesAny function · go · L210-L222 (13 LOC)internal/config/merge.go
func matchesAny(patterns []string, filePath string) bool {
for _, pattern := range patterns {
g, err := glob.Compile(pattern)
if err != nil {
// Skip invalid patterns silently.
continue
}
if g.Match(filePath) {
return true
}
}
return false
}discovery.Discover function · go · L32-L71 (40 LOC)internal/discovery/discovery.go
func Discover(opts Options) ([]string, error) {
if len(opts.Patterns) == 0 {
return nil, nil
}
baseDir := opts.BaseDir
if baseDir == "" {
baseDir = "."
}
absBase, err := filepath.Abs(baseDir)
if err != nil {
return nil, err
}
validPatterns := validatePatterns(opts.Patterns)
if len(validPatterns) == 0 {
return nil, nil
}
var gitMatcher *lint.GitignoreMatcher
if opts.UseGitignore {
gitMatcher = lint.NewGitignoreMatcher(baseDir)
}
w := &walker{
absBase: absBase,
patterns: validPatterns,
git: gitMatcher,
noFollow: opts.NoFollowSymlinks,
seen: make(map[string]bool),
}
if err := filepath.Walk(absBase, w.visit); err != nil {
return nil, err
}
sort.Strings(w.result)
return w.result, nil
}discovery.validatePatterns function · go · L74-L82 (9 LOC)internal/discovery/discovery.go
func validatePatterns(patterns []string) []string {
valid := make([]string, 0, len(patterns))
for _, p := range patterns {
if doublestar.ValidatePattern(p) {
valid = append(valid, p)
}
}
return valid
}Repobility — same analyzer, your code, free for public repos · /scan/
discovery.walker.visit method · go · L95-L128 (34 LOC)internal/discovery/discovery.go
func (w *walker) visit(path string, info os.FileInfo, walkErr error) error {
if walkErr != nil {
return walkErr
}
rel, err := filepath.Rel(w.absBase, path)
if err != nil || rel == "." {
return nil
}
rel = filepath.ToSlash(rel)
if w.isNoFollow(path, info) {
if info.IsDir() {
return filepath.SkipDir
}
return nil
}
if w.isGitignored(path, info) {
if info.IsDir() {
return filepath.SkipDir
}
return nil
}
if info.IsDir() {
return nil
}
if w.matchesAny(rel) {
w.addFile(path)
}
return nil
}discovery.walker.isNoFollow method · go · L131-L139 (9 LOC)internal/discovery/discovery.go
func (w *walker) isNoFollow(path string, info os.FileInfo) bool {
if len(w.noFollow) == 0 {
return false
}
if info.Mode()&os.ModeSymlink == 0 {
return false
}
return matchesPath(w.noFollow, path)
}discovery.walker.isGitignored method · go · L142-L151 (10 LOC)internal/discovery/discovery.go
func (w *walker) isGitignored(path string, info os.FileInfo) bool {
if w.git == nil {
return false
}
absPath, err := filepath.Abs(path)
if err != nil {
return false
}
return w.git.IsIgnored(absPath, info.IsDir())
}discovery.walker.matchesAny method · go · L154-L162 (9 LOC)internal/discovery/discovery.go
func (w *walker) matchesAny(rel string) bool {
for _, p := range w.patterns {
matched, err := doublestar.Match(p, rel)
if err == nil && matched {
return true
}
}
return false
}discovery.walker.addFile method · go · L165-L174 (10 LOC)internal/discovery/discovery.go
func (w *walker) addFile(path string) {
absPath, err := filepath.Abs(path)
if err != nil {
absPath = path
}
if !w.seen[absPath] {
w.seen[absPath] = true
w.result = append(w.result, path)
}
}discovery.matchesPath function · go · L176-L188 (13 LOC)internal/discovery/discovery.go
func matchesPath(patterns []string, path string) bool {
cleanPath := filepath.Clean(path)
for _, pattern := range patterns {
g, err := glob.Compile(pattern)
if err != nil {
continue
}
if g.Match(path) || g.Match(cleanPath) || g.Match(filepath.Base(path)) {
return true
}
}
return false
}engine.ConfigureRule function · go · L15-L29 (15 LOC)internal/engine/check.go
func ConfigureRule(rl rule.Rule, cfg config.RuleCfg) (rule.Rule, error) {
if cfg.Settings == nil {
return rl, nil
}
if _, ok := rl.(rule.Configurable); !ok {
return rl, nil
}
clone := rule.CloneRule(rl)
if c, ok := clone.(rule.Configurable); ok {
if err := c.ApplySettings(cfg.Settings); err != nil {
return nil, fmt.Errorf("applying settings for %s: %w", rl.Name(), err)
}
}
return clone, nil
}engine.CheckRules function · go · L35-L57 (23 LOC)internal/engine/check.go
func CheckRules(f *lint.File, rules []rule.Rule, effective map[string]config.RuleCfg) ([]lint.Diagnostic, []error) {
var diags []lint.Diagnostic
var errs []error
for _, rl := range rules {
cfg, ok := effective[rl.Name()]
if !ok || !cfg.Enabled {
continue
}
checkRule, err := ConfigureRule(rl, cfg)
if err != nil {
errs = append(errs, err)
continue
}
d := checkRule.Check(f)
diags = append(diags, d...)
}
f.AdjustDiagnostics(diags)
return diags, errs
}Open data scored by Repobility · https://repobility.com
engine.Runner.Run method · go · L35-L70 (36 LOC)internal/engine/runner.go
func (r *Runner) Run(paths []string) *Result {
res := &Result{}
for _, path := range paths {
if config.IsIgnored(r.Config.Ignore, path) {
continue
}
res.FilesChecked++
r.log().Printf("file: %s", path)
source, err := os.ReadFile(path)
if err != nil {
res.Errors = append(res.Errors, fmt.Errorf("reading %q: %w", path, err))
continue
}
f, err := lint.NewFileFromSource(path, source, r.StripFrontMatter)
if err != nil {
res.Errors = append(res.Errors, fmt.Errorf("parsing %q: %w", path, err))
continue
}
f.FS = os.DirFS(filepath.Dir(path))
effective := r.effectiveWithCategories(path)
r.logRules(effective)
diags, errs := CheckRules(f, r.Rules, effective)
res.Diagnostics = append(res.Diagnostics, diags...)
res.Errors = append(res.Errors, errs...)
}
sortDiagnostics(res.Diagnostics)
return res
}engine.Runner.RunSource method · go · L79-L100 (22 LOC)internal/engine/runner.go
func (r *Runner) RunSource(path string, source []byte) *Result {
res := &Result{FilesChecked: 1}
r.log().Printf("file: %s", path)
f, err := lint.NewFileFromSource(path, source, r.StripFrontMatter)
if err != nil {
res.Errors = append(res.Errors, fmt.Errorf("parsing %q: %w", path, err))
return res
}
effective := r.effectiveWithCategories(path)
r.logRules(effective)
diags, errs := CheckRules(f, r.Rules, effective)
res.Diagnostics = append(res.Diagnostics, diags...)
res.Errors = append(res.Errors, errs...)
sortDiagnostics(res.Diagnostics)
return res
}engine.Runner.effectiveWithCategories method · go · L104-L113 (10 LOC)internal/engine/runner.go
func (r *Runner) effectiveWithCategories(path string) map[string]config.RuleCfg {
effective := config.Effective(r.Config, path)
categories := config.EffectiveCategories(r.Config, path)
explicit := config.EffectiveExplicitRules(r.Config, path)
// Build rule-name-to-category lookup from the runner's rule list.
catLookup := ruleCategoryLookup(r.Rules)
return config.ApplyCategories(effective, categories, catLookup, explicit)
}