Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jshint

Package Overview
Dependencies
Maintainers
2
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jshint - npm Package Compare versions

Comparing version 0.5.9 to 0.6.0

84

lib/cli.js

@@ -27,24 +27,44 @@ var fs = require('fs'),

function _loadAndParseConfig(filePath) {
return existsSync(filePath) ?
return filePath && existsSync(filePath) ?
JSON.parse(_removeJsComments(fs.readFileSync(filePath, "utf-8"))) : {};
}
function _mergeConfigs(homerc, cwdrc) {
var homeConfig = _loadAndParseConfig(homerc),
cwdConfig = _loadAndParseConfig(cwdrc),
prop;
/**
* This function searches for a file with a specified name, it starts
* with the dir passed, and traverses up the filesystem until it either
* finds the file, or hits the root
*
* @param {String} name Filename to search for (.jshintrc, .jshintignore)
* @param {String} dir Defaults to process.cwd()
*/
function _searchFile(name, dir) {
dir = dir || process.cwd();
for (prop in cwdConfig) {
if (typeof prop === 'string') {
if (prop === 'predef') {
homeConfig.predef = (homeConfig.predef || []).concat(cwdConfig.predef);
} else {
homeConfig[prop] = cwdConfig[prop];
}
}
var filename = path.normalize(path.join(dir, name));
if (existsSync(filename)) {
return filename;
}
return homeConfig;
return dir === "/" ?
null : _searchFile(name, path.normalize(path.join(dir, "..")));
}
function _findConfig(target) {
var name = ".jshintrc",
projectConfig = _searchFile(name),
homeConfig = path.normalize(path.join(process.env.HOME, name));
if (projectConfig) {
return projectConfig;
}
// if no project config, check $HOME
if (existsSync(homeConfig)) {
return homeConfig;
}
return false;
}
function _print(results) {

@@ -70,11 +90,9 @@ function exit() {

interpret: function (args) {
var config, reporter, ignore,
var config, reporter,
options = argsparser.parse(args),
pathsToIgnore = path.join(process.cwd(), '.jshintignore'),
defaultConfig = path.join(process.env.HOME, '.jshintrc'),
projectConfig = path.join(process.cwd(), '.jshintrc'),
customConfig = options["--config"],
customReporter = options["--reporter"] ? path.resolve(process.cwd(), options["--reporter"]) : null,
targets = options.node;
targets = options.node,
ignoreFile, ignores;
//could be on Windows which we are looking for an attribute ending in 'node.exe'

@@ -96,3 +114,2 @@ if (targets === undefined) {

if (options["--version"]) {

@@ -116,7 +133,3 @@ _version();

if (customConfig) {
config = _loadAndParseConfig(customConfig);
} else {
config = _mergeConfigs(defaultConfig, projectConfig);
}
config = _loadAndParseConfig(customConfig ? customConfig : _findConfig());

@@ -133,13 +146,16 @@ if (customReporter) {

if (existsSync(pathsToIgnore)) {
ignore = fs.readFileSync(pathsToIgnore, "utf-8").split("\n").map(function (line) {
return line.trim();
}).filter(function (line) {
return !!line;
});
ignoreFile = _searchFile(".jshintignore");
if (ignoreFile) {
ignores = fs.readFileSync(ignoreFile, "utf8").split("\n")
.filter(function (line) {
return !!line.trim();
})
.map(function (line) {
return path.resolve(path.dirname(ignoreFile), line.trim());
});
}
_print(hint.hint(targets, config, reporter, ignore));
_print(hint.hint(targets, config, reporter, ignores));
}
};

@@ -61,6 +61,7 @@ var fs = require('fs'),

var fnmatch = minimatch(somePath, p, {nocase: true}),
absmatch = path.resolve(somePath) === p,
lsmatch = isDirectory(p) && p.match(/^[^\/]*\/?$/) &&
somePath.match(new RegExp("^" + p + ".*"));
return !!(fnmatch || lsmatch);
return !!(fnmatch || lsmatch || absmatch);
}

@@ -67,0 +68,0 @@

{
"name": "jshint",
"version": "0.5.9",
"version": "0.6.0",
"description": "A CLI for JSHint",

@@ -27,9 +27,9 @@ "homepage": "http://github.com/jshint/node-jshint",

"dependencies": {
"argsparser": ">=0.0.3",
"minimatch": ">=0.0.4"
"argsparser": "0.0.x",
"minimatch": "0.0.x"
},
"devDependencies": {
"jasmine-node": "1.0.7"
"jasmine-node": "1.0.x"
},
"preferGlobal" : true
}

@@ -43,23 +43,27 @@ # node-jshint

## Custom Options
## Configuration Options
Specify custom lint options (see [example/config.json](https://github.com/jshint/node-jshint/blob/master/example/config.json)).
**Note:** This behavior described below is very different from versions prior to `0.6`.
--config path/to/config.json
The CLI uses the default options that come with JSHint. To have your own configuration apply, there are several methods you can use:
Note: This bypasses any .jshintrc files.
### Specify Manually
## Default Options
Setting the `--config=/path/to/your/config` command line option to specify your own configuration file outside of the directory tree for your project.
The CLI uses the default options that come with JSHint. However, if it locates a .jshintrc file in your home directory (~/) it will use those options first.
### Within your Project's Directory Tree
## Per Directory Options
When the CLI is called, and a configuration file isn't specified already, `node-jshint` will attempt to locate one for you starting in `pwd`. (or "present working directory") If this does not yield a `.jshintrc` file, it will move one level up (`..`) the directory tree all the way up to the filesystem root. If a file is found, it stops immediately and uses that set of configuration.
If there is a .jshintrc file in the current working directory, any of those options will take precedence over (or be merged with) any options found in the ~/.jshintrc file (if it exists).
This setup allows you to set up **one** configuration file for your entire project. (place it in the root folder) As long as you run `jshint` from anywhere within your project directory tree, the same configuration file will be used.
### Home Directory
If all the methods above do not yield a `.jshintrc` to use, the last place that will be checked is your user's `$HOME` directory.
## 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 your project's directory tree, (also provided you run `jshint` from within your project's directory true) then any directories or files specified will be skipped over. (behaves just like a `.gitignore` file)
Note: Pattern matching uses minimatch, with the nocase [option](https://github.com/isaacs/minimatch). When there is no match, it performs a left side match (when no forward slashes present and path is a directory).
**Note:** Pattern matching uses minimatch, with the nocase [option](https://github.com/isaacs/minimatch). When there is no match, it performs a left side match (when no forward slashes present and path is a directory).

@@ -73,1 +77,6 @@ ## Installing dependencies for development

jake -T
## Project Guidelines
* All tests are passing.
* No (new) JSHint errors are introduced.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc