← back to jeduden__mdsmith

Function bodies 497 total

All specs Real LLM only Function bodies
catalog.fromGensectionColumns function · go · L31-L43 (13 LOC)
internal/rules/catalog/parse.go
func fromGensectionColumns(cols map[string]gensection.ColumnConfig) map[string]columnConfig {
	if cols == nil {
		return nil
	}
	result := make(map[string]columnConfig, len(cols))
	for k, v := range cols {
		result[k] = columnConfig{
			maxWidth: v.MaxWidth,
			wrap:     v.Wrap,
		}
	}
	return result
}
catalog.Rule.getEngine method · go · L44-L49 (6 LOC)
internal/rules/catalog/rule.go
func (r *Rule) getEngine() *gensection.Engine {
	if r.engine == nil {
		r.engine = gensection.NewEngine(r)
	}
	return r.engine
}
catalog.Rule.Check method · go · L52-L57 (6 LOC)
internal/rules/catalog/rule.go
func (r *Rule) Check(f *lint.File) []lint.Diagnostic {
	if f.FS == nil {
		return nil
	}
	return r.getEngine().Check(f)
}
catalog.Rule.Fix method · go · L60-L65 (6 LOC)
internal/rules/catalog/rule.go
func (r *Rule) Fix(f *lint.File) []byte {
	if f.FS == nil {
		return f.Source
	}
	return r.getEngine().Fix(f)
}
catalog.Rule.Generate method · go · L75-L92 (18 LOC)
internal/rules/catalog/rule.go
func (r *Rule) Generate(f *lint.File, filePath string, line int,
	params map[string]string, columns map[string]gensection.ColumnConfig,
) (string, []lint.Diagnostic) {
	cols := fromGensectionColumns(columns)
	entries := buildCatalogEntries(f, params)

	_, hasRow := params["row"]
	content, err := renderCatalogContent(params, entries, cols, hasRow)
	if err != nil {
		return "", []lint.Diagnostic{makeDiag(filePath, line,
			fmt.Sprintf("generated section template execution failed: %v", err))}
	}

	// Format tables to comply with MDS025 (table-format) settings.
	content = tableformat.FormatString(content, tableFormatPad())

	return content, nil
}
catalog.tableFormatPad function · go · L96-L106 (11 LOC)
internal/rules/catalog/rule.go
func tableFormatPad() int {
	r := rule.ByID("MDS025")
	if r == nil {
		return 1
	}
	type padder interface{ GetPad() int }
	if p, ok := r.(padder); ok {
		return p.GetPad()
	}
	return 1
}
catalog.validateCatalogDirective function · go · L109-L142 (34 LOC)
internal/rules/catalog/rule.go
func validateCatalogDirective(
	filePath string, line int,
	params map[string]string,
	columns map[string]gensection.ColumnConfig,
) []lint.Diagnostic {
	_, hasRow := params["row"]
	_, hasHeader := params["header"]
	_, hasFooter := params["footer"]

	if (hasHeader || hasFooter) && !hasRow {
		return []lint.Diagnostic{makeDiag(filePath, line,
			`generated section template missing required "row" key`)}
	}
	if hasRow && strings.TrimSpace(params["row"]) == "" {
		return []lint.Diagnostic{makeDiag(filePath, line,
			`generated section directive has empty "row" value`)}
	}

	if diags := validateGlob(filePath, line, params); len(diags) > 0 {
		return diags
	}

	var diags []lint.Diagnostic
	if sortVal, hasSort := params["sort"]; hasSort {
		diags = append(diags, validateSort(filePath, line, sortVal)...)
	}
	if hasRow {
		if _, err := parseRowTemplate(params["row"]); err != nil {
			diags = append(diags, makeDiag(filePath, line,
				fmt.Sprintf("generated section has invalid template: %v", err
If a scraper extracted this row, it came from Repobility (https://repobility.com)
catalog.validateGlob function · go · L145-L168 (24 LOC)
internal/rules/catalog/rule.go
func validateGlob(filePath string, line int, params map[string]string) []lint.Diagnostic {
	glob, hasGlob := params["glob"]
	if !hasGlob {
		return []lint.Diagnostic{makeDiag(filePath, line,
			`generated section directive missing required "glob" parameter`)}
	}
	if glob == "" {
		return []lint.Diagnostic{makeDiag(filePath, line,
			`generated section directive has empty "glob" parameter`)}
	}
	if filepath.IsAbs(glob) {
		return []lint.Diagnostic{makeDiag(filePath, line,
			"generated section directive has absolute glob path")}
	}
	if containsDotDot(glob) {
		return []lint.Diagnostic{makeDiag(filePath, line,
			`generated section directive has glob pattern with ".." path traversal`)}
	}
	if !doublestar.ValidatePattern(glob) {
		return []lint.Diagnostic{makeDiag(filePath, line,
			fmt.Sprintf("generated section directive has invalid glob pattern: %s", glob))}
	}
	return nil
}
catalog.validateSort function · go · L171-L182 (12 LOC)
internal/rules/catalog/rule.go
func validateSort(filePath string, line int, sortVal string) []lint.Diagnostic {
	if sortVal == "" {
		return []lint.Diagnostic{makeDiag(filePath, line,
			`generated section directive has empty "sort" value`)}
	}
	key := strings.TrimPrefix(sortVal, "-")
	if key == "" || strings.ContainsAny(key, " \t") {
		return []lint.Diagnostic{makeDiag(filePath, line,
			fmt.Sprintf("generated section directive has invalid sort value %q", sortVal))}
	}
	return nil
}
catalog.buildCatalogEntries function · go · L186-L218 (33 LOC)
internal/rules/catalog/rule.go
func buildCatalogEntries(f *lint.File, params map[string]string) []fileEntry {
	matches, err := doublestar.Glob(f.FS, params["glob"])
	if err != nil {
		return nil
	}

	var files []string
	for _, m := range matches {
		info, err := fs.Stat(f.FS, m)
		if err != nil || info.IsDir() {
			continue
		}
		files = append(files, m)
	}

	sortKey, descending := parseSort(params)
	_, hasRow := params["row"]
	needFM := hasRow || (sortKey != "path" && sortKey != "filename")

	entries := make([]fileEntry, 0, len(files))
	for _, path := range files {
		fields := map[string]string{"filename": path}
		if needFM {
			for k, v := range readFrontMatter(f.FS, path) {
				fields[k] = v
			}
		}
		entries = append(entries, fileEntry{fields: fields})
	}

	sortEntries(entries, sortKey, descending)
	return entries
}
catalog.renderCatalogContent function · go · L221-L232 (12 LOC)
internal/rules/catalog/rule.go
func renderCatalogContent(
	params map[string]string, entries []fileEntry,
	cols map[string]columnConfig, hasRow bool,
) (string, error) {
	if len(entries) == 0 {
		return renderEmpty(params), nil
	}
	if !hasRow {
		return renderMinimal(entries), nil
	}
	return renderTemplate(params, entries, cols)
}
catalog.parseSort function · go · L235-L245 (11 LOC)
internal/rules/catalog/rule.go
func parseSort(params map[string]string) (key string, descending bool) {
	sortVal, ok := params["sort"]
	if !ok || sortVal == "" {
		return "path", false
	}

	if strings.HasPrefix(sortVal, "-") {
		return sortVal[1:], true
	}
	return sortVal, false
}
catalog.sortEntries function · go · L248-L266 (19 LOC)
internal/rules/catalog/rule.go
func sortEntries(entries []fileEntry, key string, descending bool) {
	sort.SliceStable(entries, func(i, j int) bool {
		vi := sortValue(entries[i], key)
		vj := sortValue(entries[j], key)

		cmp := strings.Compare(strings.ToLower(vi), strings.ToLower(vj))
		if cmp == 0 {
			// Tiebreaker: path ascending, case-insensitive.
			pi := strings.ToLower(entries[i].fields["filename"])
			pj := strings.ToLower(entries[j].fields["filename"])
			return pi < pj
		}

		if descending {
			return cmp > 0
		}
		return cmp < 0
	})
}
catalog.sortValue function · go · L269-L278 (10 LOC)
internal/rules/catalog/rule.go
func sortValue(entry fileEntry, key string) string {
	switch key {
	case "path":
		return entry.fields["filename"]
	case "filename":
		return filepath.Base(entry.fields["filename"])
	default:
		return entry.fields[key]
	}
}
catalog.readFrontMatter function · go · L283-L317 (35 LOC)
internal/rules/catalog/rule.go
func readFrontMatter(fsys fs.FS, path string) map[string]string {
	data, err := fs.ReadFile(fsys, path)
	if err != nil {
		return nil
	}

	prefix, _ := lint.StripFrontMatter(data)
	if prefix == nil {
		return nil
	}

	// Extract the YAML between --- delimiters.
	s := string(prefix)
	s = strings.TrimPrefix(s, "---\n")
	idx := strings.Index(s, "---\n")
	if idx < 0 {
		return nil
	}
	yamlStr := s[:idx]

	var raw map[string]any
	if err := yaml.Unmarshal([]byte(yamlStr), &raw); err != nil {
		return nil
	}

	result := make(map[string]string, len(raw))
	for k, v := range raw {
		if s, ok := v.(string); ok {
			result[k] = s
		} else {
			result[k] = fmt.Sprintf("%v", v)
		}
	}
	return result
}
Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
catalog.containsDotDot function · go · L320-L328 (9 LOC)
internal/rules/catalog/rule.go
func containsDotDot(pattern string) bool {
	parts := strings.Split(pattern, "/")
	for _, p := range parts {
		if p == ".." {
			return true
		}
	}
	return false
}
catalog.truncateCell function · go · L16-L44 (29 LOC)
internal/rules/catalog/wrap.go
func truncateCell(text string, maxWidth int) string {
	if maxWidth <= 0 {
		return ""
	}
	if len(text) <= maxWidth {
		return text
	}

	spans := parseMarkdownSpans(text)

	if maxWidth < 3 {
		// Not enough room for full ellipsis, return dots up to maxWidth
		return "..."[:maxWidth]
	}

	// Find a good truncation point that respects markdown spans.
	// We need room for "..." (3 chars).
	targetWidth := maxWidth - 3

	// Find the best break point that doesn't split a markdown span.
	breakPos := findBreakPoint(text, spans, targetWidth)

	if breakPos <= 0 {
		// Can't fit anything meaningful, hard truncate
		return text[:targetWidth] + "..."
	}

	return strings.TrimRight(text[:breakPos], " ") + "..."
}
catalog.wrapCellBr function · go · L49-L81 (33 LOC)
internal/rules/catalog/wrap.go
func wrapCellBr(text string, maxWidth int) string {
	if maxWidth <= 0 {
		return ""
	}
	if len(text) <= maxWidth {
		return text
	}

	spans := parseMarkdownSpans(text)
	var lines []string
	remaining := text

	for len(remaining) > maxWidth {
		breakPos := findBreakPoint(remaining, spansInRange(spans, len(text)-len(remaining), len(remaining)), maxWidth)

		if breakPos <= 0 {
			// Hard break at maxWidth
			breakPos = maxWidth
		}

		line := strings.TrimRight(remaining[:breakPos], " ")
		lines = append(lines, line)
		remaining = strings.TrimLeft(remaining[breakPos:], " ")

		// Recalculate spans relative to new remaining position
	}

	if remaining != "" {
		lines = append(lines, remaining)
	}

	return strings.Join(lines, "<br>")
}
catalog.parseMarkdownSpans function · go · L91-L126 (36 LOC)
internal/rules/catalog/wrap.go
func parseMarkdownSpans(text string) []markdownSpan {
	var spans []markdownSpan

	i := 0
	for i < len(text) {
		// Check for inline code: `...`
		if text[i] == '`' {
			end := strings.IndexByte(text[i+1:], '`')
			if end >= 0 {
				spanEnd := i + 1 + end + 1
				spans = append(spans, markdownSpan{start: i, end: spanEnd})
				i = spanEnd
				continue
			}
		}

		// Check for markdown link: [text](url)
		if text[i] == '[' {
			// Find closing ]
			closeBracket := findClosingBracket(text, i)
			if closeBracket > i && closeBracket+1 < len(text) && text[closeBracket+1] == '(' {
				// Find closing )
				closeParen := findClosingParen(text, closeBracket+1)
				if closeParen > closeBracket+1 {
					spans = append(spans, markdownSpan{start: i, end: closeParen + 1})
					i = closeParen + 1
					continue
				}
			}
		}

		i++
	}

	return spans
}
catalog.findClosingBracket function · go · L129-L143 (15 LOC)
internal/rules/catalog/wrap.go
func findClosingBracket(text string, pos int) int {
	depth := 0
	for i := pos; i < len(text); i++ {
		switch text[i] {
		case '[':
			depth++
		case ']':
			depth--
			if depth == 0 {
				return i
			}
		}
	}
	return -1
}
catalog.findClosingParen function · go · L146-L160 (15 LOC)
internal/rules/catalog/wrap.go
func findClosingParen(text string, pos int) int {
	depth := 0
	for i := pos; i < len(text); i++ {
		switch text[i] {
		case '(':
			depth++
		case ')':
			depth--
			if depth == 0 {
				return i
			}
		}
	}
	return -1
}
catalog.findBreakPoint function · go · L165-L195 (31 LOC)
internal/rules/catalog/wrap.go
func findBreakPoint(text string, spans []markdownSpan, targetWidth int) int {
	if targetWidth >= len(text) {
		return len(text)
	}

	// Check if targetWidth falls inside a markdown span
	for _, s := range spans {
		if targetWidth > s.start && targetWidth < s.end {
			// We're inside a span. Try to break before the span.
			if s.start > 0 {
				// Find a word boundary before this span
				breakBefore := lastSpaceBefore(text, s.start)
				if breakBefore > 0 {
					return breakBefore
				}
				return s.start
			}
			// Span starts at 0 and is too long -- hard break at targetWidth
			return targetWidth
		}
	}

	// Not inside a span. Find the last word boundary at or before targetWidth.
	breakPos := lastSpaceBefore(text, targetWidth+1)
	if breakPos > 0 {
		return breakPos
	}

	// No word boundary found, use targetWidth as hard break
	return targetWidth
}
catalog.lastSpaceBefore function · go · L199-L209 (11 LOC)
internal/rules/catalog/wrap.go
func lastSpaceBefore(text string, pos int) int {
	if pos > len(text) {
		pos = len(text)
	}
	for i := pos - 1; i >= 0; i-- {
		if text[i] == ' ' {
			return i
		}
	}
	return -1
}
Repobility · open methodology · https://repobility.com/research/
catalog.spansInRange function · go · L212-L228 (17 LOC)
internal/rules/catalog/wrap.go
func spansInRange(spans []markdownSpan, offset, end int) []markdownSpan {
	var result []markdownSpan
	for _, s := range spans {
		if s.end <= offset || s.start >= end {
			continue
		}
		adjusted := markdownSpan{
			start: s.start - offset,
			end:   s.end - offset,
		}
		if adjusted.start < 0 {
			adjusted.start = 0
		}
		result = append(result, adjusted)
	}
	return result
}
catalog.applyColumnConstraints function · go · L233-L276 (44 LOC)
internal/rules/catalog/wrap.go
func applyColumnConstraints(row string, cols map[string]columnConfig, colMap map[int]string) string {
	if len(cols) == 0 || len(colMap) == 0 {
		return row
	}

	// Must be a table row (starts with |)
	if !strings.HasPrefix(strings.TrimSpace(row), "|") {
		return row
	}

	cells := splitTableRow(row)
	if len(cells) == 0 {
		return row
	}

	modified := false
	for idx, colName := range colMap {
		cc, ok := cols[colName]
		if !ok || cc.maxWidth <= 0 || idx >= len(cells) {
			continue
		}

		cellContent := strings.TrimSpace(cells[idx])
		if len(cellContent) <= cc.maxWidth {
			continue
		}

		var newContent string
		if cc.wrap == "br" {
			newContent = wrapCellBr(cellContent, cc.maxWidth)
		} else {
			newContent = truncateCell(cellContent, cc.maxWidth)
		}

		cells[idx] = " " + newContent + " "
		modified = true
	}

	if !modified {
		return row
	}

	return "|" + strings.Join(cells, "|") + "|"
}
catalog.splitTableRow function · go · L281-L289 (9 LOC)
internal/rules/catalog/wrap.go
func splitTableRow(row string) []string {
	trimmed := strings.TrimSpace(row)
	if !strings.HasPrefix(trimmed, "|") || !strings.HasSuffix(trimmed, "|") {
		return nil
	}
	// Remove leading and trailing |
	inner := trimmed[1 : len(trimmed)-1]
	return strings.Split(inner, "|")
}
catalog.buildColumnMap function · go · L294-L314 (21 LOC)
internal/rules/catalog/wrap.go
func buildColumnMap(rowTemplate string) map[int]string {
	// The row template should be a table row like:
	// "| {{.title}} | {{.description}} |"
	cells := splitTableRow(rowTemplate)
	if len(cells) == 0 {
		return nil
	}

	result := make(map[int]string)
	for i, cell := range cells {
		cell = strings.TrimSpace(cell)
		// Extract field names from {{.fieldname}} patterns
		// We look for the primary field in the cell
		field := extractPrimaryField(cell)
		if field != "" {
			result[i] = field
		}
	}

	return result
}
catalog.extractPrimaryField function · go · L320-L333 (14 LOC)
internal/rules/catalog/wrap.go
func extractPrimaryField(cell string) string {
	idx := strings.Index(cell, "{{.")
	if idx < 0 {
		return ""
	}

	rest := cell[idx+3:]
	end := strings.Index(rest, "}}")
	if end < 0 {
		return ""
	}

	return rest[:end]
}
concisenessscoring.init function · go · L44-L49 (6 LOC)
internal/rules/concisenessscoring/rule.go
func init() {
	rule.Register(&Rule{
		MinScore: defaultMinScore,
		MinWords: defaultMinWords,
	})
}
concisenessscoring.Rule.Check method · go · L74-L130 (57 LOC)
internal/rules/concisenessscoring/rule.go
func (r *Rule) Check(f *lint.File) []lint.Diagnostic {
	var diags []lint.Diagnostic

	heur := r.heuristics()
	minScore := r.MinScore
	minWords := r.MinWords

	_ = ast.Walk(
		f.AST,
		func(n ast.Node, entering bool) (ast.WalkStatus, error) {
			if !entering {
				return ast.WalkContinue, nil
			}

			para, ok := n.(*ast.Paragraph)
			if !ok {
				return ast.WalkContinue, nil
			}
			if isTable(para, f) {
				return ast.WalkContinue, nil
			}

			text := mdtext.ExtractPlainText(para, f.Source)
			result := scoreParagraph(text, heur)
			if result.WordCount < minWords || result.Score >= minScore {
				return ast.WalkContinue, nil
			}

			line := paragraphLine(para, f)
			message := fmt.Sprintf(
				"conciseness score too low (%.2f < %.2f); target >= %.2f",
				result.Score, minScore, minScore,
			)
			examples := formatExamples(result.Examples)
			if examples != "" {
				message += fmt.Sprintf(
					"; reduce filler or hedge cues (e.g., %s)",
					examples,
				)
			}

			diags = append(
concisenessscoring.formatExamples function · go · L132-L145 (14 LOC)
internal/rules/concisenessscoring/rule.go
func formatExamples(examples []string) string {
	if len(examples) == 0 {
		return ""
	}
	limit := 2
	if len(examples) < limit {
		limit = len(examples)
	}
	values := make([]string, 0, limit)
	for i := 0; i < limit; i++ {
		values = append(values, fmt.Sprintf("%q", examples[i]))
	}
	return strings.Join(values, ", ")
}
Repobility — the code-quality scanner for AI-generated software · https://repobility.com
concisenessscoring.paragraphLine function · go · L147-L153 (7 LOC)
internal/rules/concisenessscoring/rule.go
func paragraphLine(para *ast.Paragraph, f *lint.File) int {
	lines := para.Lines()
	if lines.Len() > 0 {
		return f.LineOfOffset(lines.At(0).Start)
	}
	return 1
}
concisenessscoring.Rule.ApplySettings method · go · L156-L163 (8 LOC)
internal/rules/concisenessscoring/rule.go
func (r *Rule) ApplySettings(settings map[string]any) error {
	for k, v := range settings {
		if err := r.applySetting(k, v); err != nil {
			return err
		}
	}
	return nil
}
concisenessscoring.Rule.applySetting method · go · L165-L186 (22 LOC)
internal/rules/concisenessscoring/rule.go
func (r *Rule) applySetting(k string, v any) error {
	switch k {
	case "min-score":
		return r.setMinScore(v)
	case "min-words":
		return r.setMinWords(v)
	case "filler-words":
		return r.setWordList("filler-words", v, func(values []string) {
			r.FillerWords = values
		})
	case "hedge-phrases":
		return r.setWordList("hedge-phrases", v, func(values []string) {
			r.HedgePhrases = values
		})
	case "verbose-phrases":
		return r.setWordList("verbose-phrases", v, func(values []string) {
			r.VerbosePhrases = values
		})
	default:
		return fmt.Errorf("conciseness-scoring: unknown setting %q", k)
	}
}
concisenessscoring.Rule.setMinScore method · go · L188-L204 (17 LOC)
internal/rules/concisenessscoring/rule.go
func (r *Rule) setMinScore(v any) error {
	n, ok := toFloat(v)
	if !ok {
		return fmt.Errorf(
			"conciseness-scoring: min-score must be a number, got %T",
			v,
		)
	}
	if n <= 0 || n > 1 {
		return fmt.Errorf(
			"conciseness-scoring: min-score must be > 0 and <= 1, got %.2f",
			n,
		)
	}
	r.MinScore = n
	return nil
}
concisenessscoring.Rule.setMinWords method · go · L206-L222 (17 LOC)
internal/rules/concisenessscoring/rule.go
func (r *Rule) setMinWords(v any) error {
	n, ok := toInt(v)
	if !ok {
		return fmt.Errorf(
			"conciseness-scoring: min-words must be an integer, got %T",
			v,
		)
	}
	if n <= 0 {
		return fmt.Errorf(
			"conciseness-scoring: min-words must be > 0, got %d",
			n,
		)
	}
	r.MinWords = n
	return nil
}
concisenessscoring.Rule.setWordList method · go · L224-L236 (13 LOC)
internal/rules/concisenessscoring/rule.go
func (r *Rule) setWordList(
	name string, v any, set func(values []string),
) error {
	values, ok := toStringSlice(v)
	if !ok {
		return fmt.Errorf(
			"conciseness-scoring: %s must be a list of strings, got %T",
			name, v,
		)
	}
	set(values)
	return nil
}
concisenessscoring.Rule.DefaultSettings method · go · L239-L244 (6 LOC)
internal/rules/concisenessscoring/rule.go
func (r *Rule) DefaultSettings() map[string]any {
	return map[string]any{
		"min-score": defaultMinScore,
		"min-words": defaultMinWords,
	}
}
concisenessscoring.toFloat function · go · L246-L256 (11 LOC)
internal/rules/concisenessscoring/rule.go
func toFloat(v any) (float64, bool) {
	switch n := v.(type) {
	case float64:
		return n, true
	case int:
		return float64(n), true
	case int64:
		return float64(n), true
	}
	return 0, false
}
If a scraper extracted this row, it came from Repobility (https://repobility.com)
concisenessscoring.toInt function · go · L258-L268 (11 LOC)
internal/rules/concisenessscoring/rule.go
func toInt(v any) (int, bool) {
	switch n := v.(type) {
	case int:
		return n, true
	case float64:
		return int(n), true
	case int64:
		return int(n), true
	}
	return 0, false
}
concisenessscoring.toStringSlice function · go · L270-L287 (18 LOC)
internal/rules/concisenessscoring/rule.go
func toStringSlice(v any) ([]string, bool) {
	switch values := v.(type) {
	case []string:
		return values, true
	case []any:
		out := make([]string, 0, len(values))
		for _, item := range values {
			s, ok := item.(string)
			if !ok {
				return nil, false
			}
			out = append(out, s)
		}
		return out, true
	default:
		return nil, false
	}
}
concisenessscoring.isTable function · go · L292-L302 (11 LOC)
internal/rules/concisenessscoring/rule.go
func isTable(para *ast.Paragraph, f *lint.File) bool {
	lines := para.Lines()
	if lines.Len() == 0 {
		return false
	}
	seg := lines.At(0)
	return bytes.HasPrefix(
		bytes.TrimSpace(f.Source[seg.Start:seg.Stop]),
		[]byte("|"),
	)
}
concisenessscoring.Rule.heuristics method · go · L304-L321 (18 LOC)
internal/rules/concisenessscoring/rule.go
func (r *Rule) heuristics() heuristics {
	filler := r.FillerWords
	if filler == nil {
		filler = defaultFillerWords
	}

	hedge := r.HedgePhrases
	if hedge == nil {
		hedge = defaultHedgePhrases
	}

	verbose := r.VerbosePhrases
	if verbose == nil {
		verbose = defaultVerbosePhrases
	}

	return newHeuristics(filler, hedge, verbose)
}
concisenessscoring.newHeuristics function · go · L39-L47 (9 LOC)
internal/rules/concisenessscoring/scoring.go
func newHeuristics(
	fillerWords []string, hedgePhrases []string, verbosePhrases []string,
) heuristics {
	return heuristics{
		fillerSet:      toWordSet(fillerWords),
		hedgePhrases:   normalizePhrases(hedgePhrases),
		verbosePhrases: normalizePhrases(verbosePhrases),
	}
}
concisenessscoring.scoreParagraph function · go · L49-L98 (50 LOC)
internal/rules/concisenessscoring/scoring.go
func scoreParagraph(text string, heur heuristics) scoreResult {
	tokens := tokenizeWords(text)
	if len(tokens) == 0 {
		return scoreResult{Score: 1.0}
	}

	joined := " " + strings.Join(tokens, " ") + " "
	total := len(tokens)

	contentWords := 0
	fillerHits := 0
	examples := make([]string, 0, 2)
	seenExamples := make(map[string]struct{})

	for _, token := range tokens {
		if _, ok := heur.fillerSet[token]; ok {
			fillerHits++
			addExample(&examples, seenExamples, token)
		}
		if len(token) >= 4 {
			if _, isStopWord := stopWords[token]; !isStopWord {
				contentWords++
			}
		}
	}

	hedgeHits := countPhraseHits(
		joined, heur.hedgePhrases, &examples, seenExamples,
	)
	verboseHits := countPhraseHits(
		joined, heur.verbosePhrases, &examples, seenExamples,
	)

	contentRatio := float64(contentWords) / float64(total)
	fillerRatio := float64(fillerHits) / float64(total)
	hedgeRatio := float64(hedgeHits) / float64(total)
	verboseRatio := float64(verboseHits) / float64(total)

	score := co
concisenessscoring.normalizePhrases function · go · L116-L126 (11 LOC)
internal/rules/concisenessscoring/scoring.go
func normalizePhrases(phrases []string) []string {
	out := make([]string, 0, len(phrases))
	for _, phrase := range phrases {
		tokens := tokenizeWords(phrase)
		if len(tokens) == 0 {
			continue
		}
		out = append(out, strings.Join(tokens, " "))
	}
	return out
}
concisenessscoring.countPhraseHits function · go · L128-L142 (15 LOC)
internal/rules/concisenessscoring/scoring.go
func countPhraseHits(
	text string, phrases []string, examples *[]string, seen map[string]struct{},
) int {
	hits := 0
	for _, phrase := range phrases {
		marker := " " + phrase + " "
		n := strings.Count(text, marker)
		if n == 0 {
			continue
		}
		hits += n
		addExample(examples, seen, phrase)
	}
	return hits
}
Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
concisenessscoring.addExample function · go · L144-L155 (12 LOC)
internal/rules/concisenessscoring/scoring.go
func addExample(
	examples *[]string, seen map[string]struct{}, value string,
) {
	if len(*examples) >= 3 {
		return
	}
	if _, ok := seen[value]; ok {
		return
	}
	seen[value] = struct{}{}
	*examples = append(*examples, value)
}
crossfilereferenceintegrity.Rule.Check method · go · L40-L82 (43 LOC)
internal/rules/crossfilereferenceintegrity/rule.go
func (r *Rule) Check(f *lint.File) []lint.Diagnostic {
	// Stdin/source-only checks have no stable filesystem context.
	if f.FS == nil {
		return nil
	}

	includeMatchers, err := compileMatchers(r.Include)
	if err != nil {
		return []lint.Diagnostic{configDiag(f.Path, r, err)}
	}
	excludeMatchers, err := compileMatchers(r.Exclude)
	if err != nil {
		return []lint.Diagnostic{configDiag(f.Path, r, err)}
	}

	selfAnchors := collectHeadingAnchors(f)
	anchorCache := map[string]map[string]bool{"self": selfAnchors}

	var diags []lint.Diagnostic
	_ = ast.Walk(f.AST, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
		if !entering {
			return ast.WalkContinue, nil
		}

		linkNode, ok := n.(*ast.Link)
		if !ok {
			return ast.WalkContinue, nil
		}

		diags = append(diags, r.checkLink(
			f,
			linkNode,
			includeMatchers,
			excludeMatchers,
			selfAnchors,
			anchorCache,
		)...)

		return ast.WalkContinue, nil
	})

	return diags
}
crossfilereferenceintegrity.Rule.checkLink method · go · L84-L139 (56 LOC)
internal/rules/crossfilereferenceintegrity/rule.go
func (r *Rule) checkLink(
	f *lint.File,
	linkNode *ast.Link,
	includeMatchers []glob.Glob,
	excludeMatchers []glob.Glob,
	selfAnchors map[string]bool,
	anchorCache map[string]map[string]bool,
) []lint.Diagnostic {
	target, ok := parseTarget(string(linkNode.Destination))
	if !ok {
		return nil
	}

	line, col := linkPosition(f, linkNode)

	if target.LocalAnchor {
		if target.Anchor == "" {
			return nil
		}
		if selfAnchors[normalizeAnchor(target.Anchor)] {
			return nil
		}
		return []lint.Diagnostic{brokenHeadingDiag(f.Path, line, col, r, target.Raw)}
	}

	linkPath := normalizeLinkPath(target.Path)
	if linkPath == "" || filepath.IsAbs(linkPath) {
		return nil
	}

	if !r.Strict && !isMarkdownPath(linkPath) {
		return nil
	}

	if !matchesPathFilters(linkPath, includeMatchers, excludeMatchers) {
		return nil
	}

	targetFile, ok := resolveTargetFile(f, linkPath)
	if !ok {
		return []lint.Diagnostic{brokenFileDiag(f.Path, line, col, r, target.Raw)}
	}

	if target.Anchor == "" || !isMarkdow
‹ prevpage 5 / 10next ›