Git Product home page Git Product logo

dotignore's Introduction

dotignore

ignored $IGNOREFILE

Check the ignorefile against the current directory. Print out if a file should be ignored by prefixing with a -. If the file should not be ignored prefix it with a +.

API

exports.createMatcher(str)

Return a Matcher that fully matches the str argument.

str should conform to the .gitignore specification.

Matcher.shouldIgnore(name)

Test that all the rules provided to create the matcher match the name given. / is expected as the path delimiter. Returns true if the name should be ignored.

LICENSE

MIT

dotignore's People

Contributors

bmeck avatar ljharb avatar nexdrew avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dotignore's Issues

"Shell glob" handling differs from git

This code snippet is not behaving how I would expect.

var dotignore = require('dotignore')
var matcher = dotignore.createMatcher('tmp/\n')
console.log(matcher.shouldIgnore('tmp/myfile.js')) // incorrectly returns `false`

This differs from how git handles the same string. If you put tmp/ in a line of a .gitignore file, you'll see that everything inside the tmp folder is ignored.

I believe this line (

rooted[rooted.length] = rootedLine || isShellGlob;
) is the culprit, because tmp/ is being considered a "shell glob" because it ends with a /. What is a "shell glob"?

Can we fix the behavior to match what git does?

Unexpected behavior for comment lines in .gitignore file

I ran into an unexpected issue using standard-version, which relies on this package, where a line comment in the .gitignore file caused an unexpected behavior.

File System
package.json

.gitignore (auto-generated for my projects with something akin to the following

## TODO: If the tool you use a package structure, uncomment the next line
# !package

From my initial investigation, dotignore will modify the second line from # !package to !package in the code block below.

var commentLine = line[0] === '#'; // true
var negatedLine == line[0] === '!'; // false since the comment character is still in the initial position
if (negatedLine || commentLine || rootedLine) {
      line = line.substring(1);
}

Although it passes the commentLine boolean via the options object to the minimatch RegularExpression creator, that value is never used inside the minimatch method. Instead, the minimatch.make method repeats a similar check pattern.charAt(0) to suppress including comment lines from the regular expression set. There's some interesting interplay between the # character already having been removed and negatedLine not correctly evaluating to true--the character isn't at the zero index position in this example. At the end, the ignore pattern looks like package, which doesn't seem like the desired behavior for a commented line.

I have a local test case that confirms a potential solution, i.e., removing commentLine from the list of conditions that will substring the source string.

security vulnerability in minimatch

I'd love to use this library in standard-version to parse the .gitignore, but it looks like minimatch has a security vulnerability.

 deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue

If you don't get to it first, I'll submit a patch ASAP.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.