Copyright | (c) Fuzz Leonard 2025 |
---|---|
License | MIT |
Maintainer | cyborg@bionicfuzz.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Clod.IgnorePatterns
Description
This module provides functionality for parsing and matching .gitignore and .clodignore patterns to determine which files should be excluded from processing.
The module supports common gitignore patterns including:
- Simple file patterns:
README.md
,LICENSE
- Directory patterns:
node_modules/
,dist/
- Extension patterns:
*.js
,*.svg
- Path patterns:
srccomponents
- Patterns with wildcards:
**/node_modules
,src/**/*.js
- Negation patterns:
!important.txt
(to exclude a file from a broader pattern) - Character classes:
[abc]file.txt
,file[0-9].txt
Default Patterns
This module provides default .clodignore patterns that are embedded directly into the executable at compile time using Template Haskell.
Pattern Matching Rules
- File extension patterns (
*.ext
) match any file with that extension - Directory patterns match at any level in the directory tree
- Patterns with leading slash (
/dist
) are anchored to the repository root - Patterns with trailing slash are treated as directories
- Patterns with wildcards use simplified glob matching
- Negation patterns (
!pattern
) re-include a previously excluded file - Later patterns take precedence over earlier ones
Usage
-- Read patterns from a .clodignore file patterns <- readClodIgnore "pathto/repo" -- Check if a file matches any pattern if matchesIgnorePattern patterns "srccomponentsButton.jsx" then -- Skip the file else -- Process the file
Synopsis
- readClodIgnore :: FilePath -> ClodM [IgnorePattern]
- readGitIgnore :: FilePath -> ClodM [IgnorePattern]
- readNestedGitIgnores :: FilePath -> ClodM [IgnorePattern]
- createDefaultClodIgnore :: FilePath -> String -> ClodM ()
- matchesIgnorePattern :: [IgnorePattern] -> FilePath -> Bool
- simpleGlobMatch :: String -> FilePath -> Bool
- makePatternMatcher :: String -> FilePath -> Bool
- data PatternType
- categorizePatterns :: [IgnorePattern] -> ([IgnorePattern], [IgnorePattern])
- defaultClodIgnoreContent :: Text
- defaultClodIgnoreContentStr :: String
Pattern reading functions
readClodIgnore :: FilePath -> ClodM [IgnorePattern] Source #
Read and parse .clodignore file
This function reads patterns from a .clodignore file in the specified directory.
If the file doesn't exist, a default one is created using the template in resources/default_clodignore.dhall
which is a proper Dhall configuration file that is parsed and converted to a plain text .clodignore file.
Comments (lines starting with #
) and empty lines are ignored.
Uses the CLODIGNORE environment variable or defaults to ".clodignore".
patterns <- readClodIgnore "pathto/repo"
readGitIgnore :: FilePath -> ClodM [IgnorePattern] Source #
Read and parse .gitignore file
This function reads patterns from a .gitignore file in the specified directory.
If the file doesn't exist, an empty list is returned.
Comments (lines starting with #
) and empty lines are ignored.
Negation patterns (lines starting with !
) are properly processed.
patterns <- readGitIgnore "pathto/repo"
readNestedGitIgnores :: FilePath -> ClodM [IgnorePattern] Source #
Find and read all .gitignore files in a directory tree
This function recursively searches for all .gitignore files in a directory and its subdirectories, and combines their patterns. Patterns in deeper directories take precedence over ones in higher directories.
This matches Git's behavior where each directory can have its own .gitignore that applies to files within it.
patterns <- readNestedGitIgnores "pathto/repo"
createDefaultClodIgnore :: FilePath -> String -> ClodM () Source #
Create a default .clodignore file using the embedded template
This function creates a new .clodignore file in the specified directory using the default patterns embedded in the executable at compile time.
createDefaultClodIgnore "pathto/repo" ".clodignore"
Pattern matching functions
matchesIgnorePattern :: [IgnorePattern] -> FilePath -> Bool Source #
Check if a file matches any ignore pattern, respecting negations
This function checks if a given file path matches any of the provided ignore patterns, while properly handling negation patterns. Patterns are processed in order, with later patterns taking precedence over earlier ones.
A file is ignored if it matches any inclusion pattern and doesn't match any subsequent negation pattern.
Examples
-- Check if a file should be ignored matchesIgnorePattern [IgnorePattern "*.js", IgnorePattern "!important.js"] "app.js" -- Returns True (matches *.js) matchesIgnorePattern [IgnorePattern "*.js", IgnorePattern "!important.js"] "important.js" -- Returns False (negated) matchesIgnorePattern [IgnorePattern "src*.svg"] "srclogo.svg" -- Returns True matchesIgnorePattern [IgnorePattern "node_modules"] "srcnode_modulesfile.js" -- Returns True
makePatternMatcher :: String -> FilePath -> Bool Source #
Convert a pattern string into a function that matches paths against that pattern
Pattern types and utilities
data PatternType Source #
Types of ignore patterns
Constructors
Inclusion | Normal inclusion pattern (e.g., "*.js") |
Negation | Negation pattern to re-include files (e.g., "!important.js") |
Instances
Show PatternType Source # | |
Defined in Clod.IgnorePatterns Methods showsPrec :: Int -> PatternType -> ShowS # show :: PatternType -> String # showList :: [PatternType] -> ShowS # | |
Eq PatternType Source # | |
Defined in Clod.IgnorePatterns |
categorizePatterns :: [IgnorePattern] -> ([IgnorePattern], [IgnorePattern]) Source #
Categorize patterns by type (inclusion or negation)
Embedded content
defaultClodIgnoreContent :: Text Source #
Default clodignore pattern content embedded at compile time (Dhall format)
defaultClodIgnoreContentStr :: String Source #
Default clodignore pattern content as a string (for testing)