Socket
Socket
Sign inDemoInstall

eslint

Package Overview
Dependencies
33
Maintainers
1
Versions
357
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.4 to 0.0.5

lib/options.js

2

config/eslint.json
{
"rules": {
"no-alert": 1,
"no-arg": 1,
"no-bitwise": 0,
"no-console": 1,

@@ -6,0 +8,0 @@ "no-debugger": 1,

51

lib/cli.js

@@ -12,3 +12,3 @@ /**

var optimist = require("optimist"),
var options = require("./options"),
fs = require("fs"),

@@ -76,2 +76,6 @@ path = require("path"),

/**
*
* @returns {int} The total number of errors.
*/
function processFile(filename, config) {

@@ -86,4 +90,16 @@

console.log(reporter(eslint, messages, filename, config));
return messages.reduce(function(previous, message) {
if (message.fatal || config.rules[message.ruleId] === 2) {
return previous + 1;
} else {
return previous;
}
}, 0);
}
/**
*
* @returns {int} The total number of errors.
*/
function processFiles(files, config) {

@@ -101,5 +117,5 @@

fullFileList.forEach(function(file) {
processFile(file, config);
});
return fullFileList.reduce(function(previous, file) {
return previous + processFile(file, config);
}, 0);
}

@@ -126,24 +142,25 @@

var options = optimist.parse(argv),
files = options._,
config;
var currentOptions = options.parse(argv),
files = currentOptions._,
config,
result;
if (options.h || options.help) {
if (currentOptions.h || !files.length) {
options.help();
} else {
config = readConfig(options);
config = readConfig(currentOptions);
// TODO: Figure out correct option vs. config for this
// load rules
if (options.rules) {
rules.load(options.rules);
if (currentOptions.rulesdir) {
rules.load(currentOptions.rulesdir);
}
if (files.length) {
processFiles(files, config);
} else {
console.log("No files!");
result = processFiles(files, config);
// result is the number of errors (not warnings)
if (result > 0) {
process.exit(1);
}
}

@@ -150,0 +167,0 @@

@@ -12,5 +12,5 @@ /**

var astw = require("astw"),
util = require("util"),
var util = require("util"),
esprima = require("esprima"),
estraverse = require("estraverse"),
rules = require("./rules"),

@@ -55,3 +55,5 @@ RuleContext = require("./rule-context"),

// enable appropriate rules
Object.keys(config.rules).forEach(function(key) {
Object.keys(config.rules).filter(function(key) {
return config.rules[key] > 0; // ignore rules that are turned off
}).forEach(function(key) {

@@ -82,9 +84,32 @@ var ruleCreator = rules.get(key),

*/
var ast = esprima.parse(text, { loc: true, range: true }),
walk = astw(ast);
try {
var ast = esprima.parse(text, { loc: true, range: true });
estraverse.traverse(ast, {
enter: function(node) {
api.emit(node.type, node);
},
leave: function(node) {
api.emit(node.type + ":after", node);
}
});
walk(function(node) {
api.emit(node.type, node);
});
} catch (ex) {
messages.push({
fatal: true,
// messages come as "Line X: Unexpected token foo", so strip off leading part
message: ex.message.substring(ex.message.indexOf(":") + 1).trim(),
// fake AST node to make life easier for reporters
node: {
loc: {
start: {
line: ex.lineNumber,
column: ex.column
}
}
}
});
}
return messages;

@@ -101,2 +126,3 @@ };

api.report = function(ruleId, node, message) {
messages.push({

@@ -103,0 +129,0 @@ ruleId: ruleId,

@@ -14,6 +14,6 @@ /**

if (config.rules[message.ruleId] < 2) {
if (message.fatal || config.rules[message.ruleId] === 2) {
return "Error";
} else {
return "Warning";
} else {
return "Error";
}

@@ -35,5 +35,10 @@

output += filename + ": line " + message.node.loc.start.line + ", col " +
message.node.loc.start.column + ", " + getMessageType(message, config) +
" - " + message.message + "\n";
output += filename + ": ";
if (message.node) {
output += "line " + message.node.loc.start.line + ", col " +
message.node.loc.start.column + ", " + getMessageType(message, config);
}
output += " - " + message.message + "\n";
});

@@ -40,0 +45,0 @@

@@ -17,2 +17,8 @@ /**

//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------
var JS_EXT = ".js";
//------------------------------------------------------------------------------
// Privates

@@ -30,8 +36,8 @@ //------------------------------------------------------------------------------

try {
var fullPath = path.join(__dirname, directory),
var fullPath = path.resolve(process.cwd(), directory),
files = fs.readdirSync(fullPath);
files.forEach(function(file) {
if (path.extname(file) === ".js") {
var ruleId = file.replace(".js", "");
if (path.extname(file) === JS_EXT) {
var ruleId = file.replace(JS_EXT, "");
rules[ruleId] = require(path.join(fullPath, ruleId));

@@ -55,2 +61,3 @@ }

exports.load("./rules");
// loads built-in rules
exports.load(path.join(__dirname, "./rules"));
{
"name": "eslint",
"version": "0.0.4",
"version": "0.0.5",
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",

@@ -20,3 +20,3 @@ "description": "An Esprima-based pattern checker for JavaScript.",

"optimist": "*",
"astw": "*",
"estraverse": "*",
"esprima": "*",

@@ -23,0 +23,0 @@ "jshint": "*"

@@ -11,2 +11,8 @@ [![Build Status](https://secure.travis-ci.org/nzakas/eslint.png?branch=master)](http://travis-ci.org/nzakas/eslint)

## WARNING: Pre-alpha
Right now, ESLint is in early development and should not be relied upon. There are no guarantees that anything is working at any particular point in time. Installing directly from GitHub increases the likelihood that something will explode, so if you'd like to try it out, please install the official release from npm.
Prior to version 0.1.0, this utility should be considered completely unstable.
## Installation

@@ -13,0 +19,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc