skip

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: GPL-2.0, GPL-2.0-only Imports: 7 Imported by: 0

Documentation

Overview

Package skip provides utilities for determining which files and directories should be excluded from scanning.

Index

Constants

This section is empty.

Variables

View Source
var DefaultSkippedDirs = []string{
	"nbproject",
	"nbbuild",
	"nbdist",
	"__pycache__",
	"venv",
	"_yardoc",
	"eggs",
	"wheels",
	"htmlcov",
	"__pypackages__",
	"example",
	"examples",
	"docs",
	"doc",
	"node_modules",
	"dist",
	"build",
	"target",
	"vendor",
}

DefaultSkippedDirs contains commonly excluded directories across projects.

View Source
var DefaultSkippedTestPatterns = []string{
	"test/",
	"tests/",
	"src/test/",
	"src/tests/",
	"__tests__/",
	"**/*Test.java",
	"**/*Tests.java",
	"**/*_test.go",
	"**/test_*.py",
}

DefaultSkippedTestPatterns contains gitignore-style patterns for excluding test sources.

Functions

func OnlyDefaultTestPatterns added in v0.4.0

func OnlyDefaultTestPatterns(patterns []string) []string

OnlyDefaultTestPatterns keeps only the built-in test skip patterns from the provided list.

func WithDefaultTestPatterns added in v0.4.0

func WithDefaultTestPatterns(patterns []string) []string

WithDefaultTestPatterns appends the built-in test skip patterns and deduplicates the result.

Types

type DefaultsSource

type DefaultsSource struct{}

DefaultsSource provides the built-in default skip patterns. These patterns represent commonly excluded directories across projects.

func NewDefaultsSource

func NewDefaultsSource() *DefaultsSource

NewDefaultsSource creates a new source that returns the built-in default patterns.

Returns:

  • *DefaultsSource: Source providing default skip patterns

func (*DefaultsSource) Load

func (d *DefaultsSource) Load() ([]string, error)

Load returns the default excluded directory patterns. This source never fails - it always returns the built-in defaults.

Returns:

  • []string: Default skip patterns
  • error: Always nil (included for interface compatibility)

func (*DefaultsSource) Name

func (d *DefaultsSource) Name() string

Name returns a descriptive name for this pattern source.

type GitIgnoreMatcher

type GitIgnoreMatcher struct {
	// contains filtered or unexported fields
}

GitIgnoreMatcher determines whether files or directories match a given gitignore-style pattern.

func NewGitIgnoreMatcher

func NewGitIgnoreMatcher(patterns []string) *GitIgnoreMatcher

NewGitIgnoreMatcher creates a new GitIgnoreMatcher with the provided patterns. Patterns follow gitignore syntax and are deduplicated automatically.

Patterns can be:

  • Directory names (e.g., "node_modules", "vendor")
  • Glob patterns (e.g., "*.min.js", "build/")
  • Path segments (e.g., "test/", ".git/")
  • Negation patterns (e.g., "!important.js")
  • ** recursive wildcards (e.g., "**/test/**")

Parameters:

  • patterns: List of gitignore-style skip patterns

Returns:

  • *SkipMatcher: Configured matcher

func (*GitIgnoreMatcher) ShouldSkip

func (m *GitIgnoreMatcher) ShouldSkip(path string, isDir bool) bool

ShouldSkip checks if a file or directory path should be skipped. It uses gitignore-style pattern matching and also automatically skips hidden directories.

Parameters:

  • path: Full or relative path to check
  • isDir: Whether the path is a directory

Returns:

  • bool: true if the path should be skipped

type MultiSource

type MultiSource struct {
	// contains filtered or unexported fields
}

MultiSource aggregates patterns from multiple sources. It loads patterns from all sources and merges them, removing duplicates.

func NewMultiSource

func NewMultiSource(sources ...PatternSource) *MultiSource

NewMultiSource creates a new MultiSource that aggregates patterns from multiple sources. Sources are loaded in the order provided. Patterns are deduplicated automatically.

Parameters:

  • sources: Variable number of PatternSource implementations

Returns:

  • *MultiSource: Aggregator for multiple pattern sources

func (*MultiSource) Load

func (m *MultiSource) Load() ([]string, error)

Load retrieves and merges patterns from all configured sources. If any source fails to load, the error is returned immediately. Empty patterns from sources are filtered out automatically.

Returns:

  • []string: Deduplicated merged patterns from all sources
  • error: First error encountered while loading sources, if any

func (*MultiSource) Name

func (m *MultiSource) Name() string

Name returns a descriptive name for this multi-source.

type PatternSource

type PatternSource interface {
	// Load retrieves skip patterns from the source.
	// Returns an empty slice if the source has no patterns (not an error).
	// Returns an error only if the source exists but cannot be read/parsed.
	Load() ([]string, error)

	// Name returns a human-readable identifier for this source.
	// Used for logging and debugging purposes.
	Name() string
}

PatternSource defines an interface for loading skip patterns from various sources. Implementations can load patterns from files, remote URLs, databases, environment variables, etc.

type ScanossConfigSource

type ScanossConfigSource struct {
	// contains filtered or unexported fields
}

ScanossConfigSource loads skip patterns from a scanoss.json configuration file. This source implements the settings.skip.patterns.scanning field.

func NewScanossConfigSourceFromDir

func NewScanossConfigSourceFromDir(dir string) *ScanossConfigSource

NewScanossConfigSourceFromDir creates a new source that loads from scanoss.json in a directory. This is a convenience constructor that builds the path to scanoss.json.

Parameters:

  • dir: Directory containing scanoss.json

Returns:

  • *ScanossConfigSource: Source configured to load from dir/scanoss.json

func (*ScanossConfigSource) Load

func (s *ScanossConfigSource) Load() ([]string, error)

Load retrieves skip patterns from the scanoss.json file. Returns an empty slice if the file doesn't exist (not an error). Returns an error if the file exists but cannot be read or parsed.

Returns:

  • []string: Skip patterns from settings.skip.patterns.scanning
  • error: Error if file exists but cannot be read/parsed

func (*ScanossConfigSource) Name

func (s *ScanossConfigSource) Name() string

Name returns a descriptive name for this pattern source.

type SkipMatcher

type SkipMatcher interface {
	// ShouldSkip returns true if the given path should be skipped.
	ShouldSkip(path string, isDir bool) bool
}

SkipMatcher is an interface that defines a matcher for skipping files and directories.

type UserExcludeSource added in v0.6.0

type UserExcludeSource struct {
	// contains filtered or unexported fields
}

UserExcludeSource provides skip patterns supplied directly via the CLI (--exclude <pattern> flag, repeatable). Patterns are taken verbatim and only trimmed; empty entries (e.g. from accidental --exclude "") are dropped to avoid emitting meaningless arguments to downstream scanners.

Deduplication is intentionally NOT performed here — MultiSource.Load() deduplicates across all sources, keeping the single-responsibility principle: sources provide raw data, MultiSource normalises it.

func NewUserExcludeSource added in v0.6.0

func NewUserExcludeSource(patterns []string) *UserExcludeSource

NewUserExcludeSource creates a source wrapping CLI --exclude patterns.

Parameters:

  • patterns: Raw pattern strings as received from the cobra flag.

Returns:

  • *UserExcludeSource: Source ready to be added to a MultiSource.

func (*UserExcludeSource) Load added in v0.6.0

func (u *UserExcludeSource) Load() ([]string, error)

Load returns the user-supplied patterns with whitespace trimmed and empty entries removed. This source never fails — it does no I/O.

Returns:

  • []string: Trimmed, non-empty patterns
  • error: Always nil (included for interface compatibility)

func (*UserExcludeSource) Name added in v0.6.0

func (u *UserExcludeSource) Name() string

Name returns a descriptive name for this pattern source. The flag name "--exclude" is embedded so that log messages like "Using N skip patterns from cli-flags(--exclude)" are immediately actionable — users can search their invocation for "--exclude".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL