Skip to content

Latest commit

 

History

History
149 lines (110 loc) · 3.67 KB

README.md

File metadata and controls

149 lines (110 loc) · 3.67 KB

Build Maven Central Scala.js

GitIgnore

This is a nano-library for Scala

"com.github.arturopala" %% "gitignore" % "@VERSION@"

//> using "com.github.arturopala::gitignore:@VERSION@"

Cross-compiles to Scala versions @SUPPORTED_SCALA_VERSIONS@, and ScalaJS version @SCALA_JS_VERSION@, and ScalaNative version @SCALA_NATIVE_VERSION@.

Motivation

The .gitignore has became de-facto standard filter format for project's files and folders.

This nano-library provides Scala implementation of the .gitignore compliant filter, ready to embed in different tools without having to run git command.

Scaladoc

https://arturopala.github.io/gitignore/latest/api/com/github/arturopala/gitignore/GitIgnore.html

Try online in Scastie!

https://scastie.scala-lang.org/arturopala/D8GzZ1LwTIuNr4wBOzcMUg/11

Usage

Option 1 - parse existing .gitignore file content

import com.github.arturopala.gitignore._

val gitignore = GitIgnore
    .parse(""" 
        |#*.json
        |*.txt
        |*.pdf
        |!ok.*
        |bar.json 
        |target  
        |""".stripMargin)
 
gitignore.isIgnored("foo.txt")
gitignore.isIgnored("bar.txt")
gitignore.isIgnored("ok.txt")
gitignore.isIgnored("foo.pdf")
gitignore.isIgnored("bar.pdf")
gitignore.isIgnored("ok.pdf")
gitignore.isIgnored("foo.json")
gitignore.isIgnored("bar.json")
gitignore.isIgnored("ok.json")
gitignore.isIgnored("target/")
gitignore.isIgnored("target.json")

gitignore.isAllowed("foo.txt")
gitignore.isAllowed("bar.txt")
gitignore.isAllowed("ok.txt")
gitignore.isAllowed("foo.pdf")
gitignore.isAllowed("bar.pdf")
gitignore.isAllowed("ok.pdf")
gitignore.isAllowed("foo.json")
gitignore.isAllowed("bar.json")
gitignore.isAllowed("ok.json")
gitignore.isAllowed("target/")
gitignore.isAllowed("target.json")

Option 2 - pass list of rules to the constructor

import com.github.arturopala.gitignore._

val gitignore = GitIgnore(Seq(
    "*.txt",
    "*.pdf",
    "!ok.*",
    "bar.json ",
    "target"))
 
gitignore.isIgnored("foo.txt")
gitignore.isIgnored("bar.txt")
gitignore.isIgnored("ok.txt")
gitignore.isIgnored("foo.pdf")
gitignore.isIgnored("bar.pdf")
gitignore.isIgnored("ok.pdf")
gitignore.isIgnored("foo.json")
gitignore.isIgnored("bar.json")
gitignore.isIgnored("ok.json")
gitignore.isIgnored("target/")
gitignore.isIgnored("target.json")

gitignore.isAllowed("foo.txt")
gitignore.isAllowed("bar.txt")
gitignore.isAllowed("ok.txt")
gitignore.isAllowed("foo.pdf")
gitignore.isAllowed("bar.pdf")
gitignore.isAllowed("ok.pdf")
gitignore.isAllowed("foo.json")
gitignore.isAllowed("bar.json")
gitignore.isAllowed("ok.json")
gitignore.isAllowed("target/")
gitignore.isAllowed("target.json")

Development

Compile

sbt compile

Compile for all Scala versions

sbt +compile

Test

sbt rootJVM/test
sbt rootJS/test
sbt rootNative/test

Test with all Scala versions

sbt +test
sbt +rootJVM/test

Generate README and docs

sbt docs/mdoc

Apply scalafixes

sbt rootJMV/scalafixAll    

Github Actions