Permalink
Browse files

switched matching to use fnmatch

  • Loading branch information...
1 parent 936475f commit e65b2f99b171c2328a0a94f3ba689e79f6a81811 @brentlintner brentlintner committed Jul 14, 2011
Showing with 15 additions and 14 deletions.
  1. +3 −3 .jshintignore
  2. +3 −1 README.md
  3. +5 −6 lib/hint.js
  4. +2 −1 package.json
  5. +2 −3 test/hint.js
View
@@ -1,3 +1,3 @@
-node_modules
-packages
-.git/
+node_modules/*
+packages/*
+.git/*
View
@@ -52,7 +52,9 @@ If there is a .jshintrc file in the current working directory, any of those opti
## Ignoring Files and Directories
-If there is a .jshintignore file in the current working directory, then any directories or files will be skipped over.
+If there is a .jshintignore file in the current working directory, then any directories or files will be skipped over (see root directory for example).
+
+Note: Pattern matching is similar to a .gitignore file (uses FNM_PATHNAME flag)
## Installing dependencies for development
View
@@ -1,5 +1,6 @@
var fs = require('fs'),
sys = require('sys'),
+ glob = require('glob'),
path = require('path'),
jshint = require('./../packages/jshint/jshint.js'),
_reporter = require('./reporters/default').reporter;
@@ -31,16 +32,14 @@ function _lint(file, results, config, data) {
}
}
-function _shouldIgnore(path, toIgnore) {
- var endOfPath = new RegExp(path + "\\s?$");
- return !toIgnore || path === "." ? false : toIgnore.some(function (ignore) {
- var startOfPath = new RegExp(("^" + ignore));
- return ignore.match(endOfPath) || path.match(startOfPath);
+function _shouldIgnore(somePath, ignore) {
+ return ignore.some(function (ignorePath) {
+ return glob.fnmatch(ignorePath, somePath, glob.FNM_PATHNAME);
});
}
function _collect(filePath, files, ignore) {
- if (_shouldIgnore(filePath, ignore)) {
+ if (ignore && _shouldIgnore(filePath, ignore)) {
return;
}
View
@@ -24,7 +24,8 @@
"lib"
],
"dependencies": {
- "argsparser": ">=0.0.3"
+ "argsparser": ">=0.0.3",
+ "glob": ">=2.0.7"
},
"preferGlobal" : true
}
View
@@ -152,8 +152,8 @@ describe("hint", function () {
});
it("ignores directories", function () {
- var targets = [".", "dir/file.js", "dir2/foo/file.js", "file0.js"],
- ignore = ["dir2"];
+ var targets = ["dir/file.js", "dir2/foo/file.js", "file0.js"],
+ ignore = ["dir2/*"];
spyOn(fs, "readFileSync").andReturn("data");
@@ -166,7 +166,6 @@ describe("hint", function () {
expect(fs.readFileSync.callCount).toBe(2);
expect(fs.readFileSync.argsForCall[1][0]).toBe("file0.js");
expect(fs.readFileSync.argsForCall[0][0]).toBe("dir/file.js");
- expect(fs.statSync).not.toHaveBeenCalledWith(targets[0]);
});
// TODO: support more robust ignore paths (ex foo/**/*.js)

0 comments on commit e65b2f9

Please sign in to comment.