jfmengels/elm-review/2.16.0

NOTE: the latest version is 2.16.6

Review.FilePattern

A module for selecting multiple files from the file system using [glob] patterns and negated patterns.

import Review.FilePattern as FilePattern exposing (FilePattern)


filePatterns : List FilePattern
filePatterns =
    [ FilePattern.include "**/*.css"
    , FilePattern.exclude "**/*-test.css"
    , FilePattern.excludeDirectory "ignore-folder/"
    ]

Some elm-review APIs require a List FilePattern as an argument to figure out a list of files to match or not match.

This list works similarly to [.gitignore] files: any matching file excluded by a previous pattern will become included again. Files that are in excluded directories are ignored entirely.

A file pattern is always relative to the project's elm.json file, is case-sensitive, and should be written in the Unix style (src/Some/File.elm, not src\Some\File.elm).

A pattern to include or exclude files from a selection.

include : String -> FilePattern

Create a FilePattern that includes files that match a Glob-like pattern.

[ FilePattern.include "CHANGELOG.md"
, FilePattern.include "src/**/*.elm"
, FilePattern.include "*.css"
]
exclude : String -> FilePattern

Create a FilePattern that excludes files that match a Glob-like pattern.

[ FilePattern.include "**/*.css"
, FilePattern.exclude "exception.css"
]

Files that get excluded this way can be re-included through FilePattern.include.

[ FilePattern.include "**/*.css"
, FilePattern.exclude "exception-*.css"
, FilePattern.include "exception-among-exceptions.css"
]

Create a FilePattern that excludes a whole directory. Files that get excluded this way can't be re-included.

[ FilePattern.include "**/*.css"
, FilePattern.excludeDirectory "build/"
]

Supported patterns

The supported patterns are the following:

  • ? matches an unknown single character (except /). "a?c" would match "abc" or "a5c", but not "ac".
  • * matches any number of unknown characters (except /). "some-*.txt" would match "some-file.txt" and "some-other-file.txt", but not "other-file.txt" or "some-folder/file.txt".
  • ** matches any number of sub-directories. "projects/**/README.md" would match "projects/README.md", "projects/a/README.md" and "projects/a/b/README.md". If you desire to include all files in a folder, then you need to end the pattern with /**/* (eg "projects/**/*" or "projects/**/*.md").
  • [characters] matches one of the specified characters. a[bc]d would match "abc" and "acd", but not "axd".
  • [^characters] matches anything that is not one of the specified characters. a[^bc]d would match "axc", but not "abd" or "acd".
  • [character1-character2] matches a range of characters. a[a-z]d would match "aac" and "ayd", but not "a5d".
  • {string1|string2} matches one of the provided strings. file.{js|ts} would match "file.js" and "file.ts" but not "file.md".

Using FilePattern

type Summary

Compiled version of a list of FilePatterns.

Equivalent to using compact [], but without the Result.

compact : List FilePattern -> Result (List String) Summary

Compile a list of FilePatterns.

match : { includeByDefault : Bool } -> Summary -> String -> Bool

Check if a file path matches file patterns.

-> { files :
List
{ pattern : String
, included : Bool
}
, excludedDirectories : List String
}

Stringify the file patterns in a way that is easily understandable by a JavaScript Glob-like API.