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

eslint

Package Overview
Dependencies
Maintainers
1
Versions
372
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint - npm Package Compare versions

Comparing version 0.10.0-alpha.1 to 0.10.0-alpha.2

lib/rules/space-unary-ops.js

2

conf/environments.json

@@ -411,3 +411,5 @@ {

"globals": {
"afterAll": false,
"afterEach": false,
"beforeAll": false,
"beforeEach": false,

@@ -414,0 +416,0 @@ "describe": false,

2

conf/eslint.json

@@ -142,3 +142,3 @@ {

"space-return-throw-case": 2,
"space-unary-word-ops": 0,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-line-comment": [0, "always"],

@@ -145,0 +145,0 @@ "strict": 2,

@@ -19,6 +19,8 @@ /**

util = require("./util"),
attachComments = require("./util/attach-comments"),
Validator = require("./util/validator"),
RuleContext = require("./rule-context"),
timing = require("./timing"),
EventEmitter = require("events").EventEmitter;
EventEmitter = require("events").EventEmitter,
createDebug = require("debug");

@@ -29,2 +31,4 @@ //------------------------------------------------------------------------------

var debug = createDebug("eslint:linter");
function escapeRegExp(rx) {

@@ -395,3 +399,4 @@ return rx.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");

try {
return esprima.parse(text, {
debug("Parsing text");
var ast = esprima.parse(text, {
loc: true,

@@ -401,7 +406,10 @@ range: true,

tokens: true,
comment: true,
attachComment: true
comment: true
});
attachComments(ast, ast.comments, ast.tokens);
return ast;
} catch (ex) {
debug("Parse failed: " + ex.message);
messages.push({

@@ -654,2 +662,4 @@ fatal: true,

debug("Starting traversal");
emitCommentsEnter(comments.leading);

@@ -656,0 +666,0 @@ node.parent = parent;

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

"VariableDeclaration": function (node) {
if (node.parent.type === "SwitchCase") {
variableDeclarationHandler(node);
}
},
"BlockStatement:exit": popScope,

@@ -126,0 +132,0 @@

@@ -41,2 +41,11 @@ /**

/**
* Gets the last element of an array.
* @param {Array} arr An array.
* @returns {any} Last element of arr.
*/
function last(arr) {
return arr[arr.length - 1];
}
//------------------------------------------------------------------------------

@@ -105,2 +114,36 @@ // Rule Definition

/**
* Verifies correct vertical alignment of a group of properties.
* @param {ASTNode[]} properties List of Property AST nodes.
* @returns {void}
*/
function verifyAlignment(properties) {
var length = properties.length,
widths = properties.map(getKeyWidth), // Width of keys, including quotes
targetWidth = Math.max.apply(null, widths),
i, property, whitespace, width;
// Conditionally include one space before or after colon
targetWidth += (align === "colon" ? beforeColon : afterColon);
for (i = 0; i < length; i++) {
property = properties[i];
whitespace = getPropertyWhitespace(property);
if (!whitespace) {
continue; // Object literal getters/setters lack a colon
}
width = widths[i];
if (align === "value") {
report(property, "key", whitespace.beforeColon, beforeColon);
report(property, "value", whitespace.afterColon, targetWidth - width);
} else { // align = "colon"
report(property, "key", whitespace.beforeColon, targetWidth - width);
report(property, "value", whitespace.afterColon, afterColon);
}
}
}
if (align) { // Verify vertical alignment

@@ -110,29 +153,16 @@

"ObjectExpression": function(node) {
var properties = node.properties,
length = properties.length,
widths = properties.map(getKeyWidth), // Width of keys, including quotes
targetWidth = Math.max.apply(null, widths),
i, property, whitespace, width;
node.properties.reduce(function(groups, property) {
var currentGroup = last(groups);
var prev = last(currentGroup);
// Conditionally include one space before or after colon
targetWidth += (align === "colon" ? beforeColon : afterColon);
for (i = 0; i < length; i++) {
property = properties[i];
whitespace = getPropertyWhitespace(property);
if (!whitespace) {
continue; // Object literal getters/setters lack a colon
if (!prev || property.loc.start.line - prev.loc.end.line <= 1) {
currentGroup.push(property);
} else {
groups.push([property]);
}
width = widths[i];
if (align === "value") {
report(property, "key", whitespace.beforeColon, beforeColon);
report(property, "value", whitespace.afterColon, targetWidth - width);
} else { // align = "colon"
report(property, "key", whitespace.beforeColon, targetWidth - width);
report(property, "value", whitespace.afterColon, afterColon);
}
}
return groups;
}, [[]]).forEach(function(group) {
verifyAlignment(group);
});
}

@@ -139,0 +169,0 @@ };

@@ -27,17 +27,17 @@ /**

switch (node.type) {
case "Literal":
case "FunctionExpression":
case "ObjectExpression":
case "ArrayExpression":
return true;
case "UnaryExpression":
return isConstant(node.argument);
case "BinaryExpression":
case "LogicalExpression":
return isConstant(node.left) && isConstant(node.right);
case "AssignmentExpression":
return isConstant(node.right);
case "SequenceExpression":
return isConstant(node.expressions[node.expressions.length - 1]);
// no default
case "Literal":
case "FunctionExpression":
case "ObjectExpression":
case "ArrayExpression":
return true;
case "UnaryExpression":
return isConstant(node.argument);
case "BinaryExpression":
case "LogicalExpression":
return isConstant(node.left) && isConstant(node.right);
case "AssignmentExpression":
return isConstant(node.right);
case "SequenceExpression":
return isConstant(node.expressions[node.expressions.length - 1]);
// no default
}

@@ -44,0 +44,0 @@ return false;

@@ -22,3 +22,3 @@ /**

if (node.value && typeof(node.value) === "string") {
if (node.value && typeof node.value === "string") {
value = node.value.toLowerCase();

@@ -25,0 +25,0 @@

@@ -20,3 +20,3 @@ /**

if (context.options[0]) {
if (typeof(context.options[0]) === "string") {
if (typeof context.options[0] === "string") {
config.vars = context.options[0];

@@ -23,0 +23,0 @@ } else {

/**
* @fileoverview Disallows or enforces spaces inside of parentheses.
* @author Jonathan Rajavuori
* @copyright 2014 David Clark. All rights reserved.
* @copyright 2014 Jonathan Rajavuori. All rights reserved.

@@ -14,13 +15,147 @@ */

var RE, MESSAGE;
var MISSING_SPACE_MESSAGE = "There must be a space inside this paren.",
REJECTED_SPACE_MESSAGE = "There should be no spaces inside this paren.",
exceptionsArray = (context.options.length === 2) ? context.options[1].exceptions : [],
options = {},
rejectedSpaceRegExp,
missingSpaceRegExp,
spaceChecks;
if (context.options[0] === "always") {
RE = /\([^ \)\r\n]|[^ \(\r\n]\)/mg;
MESSAGE = "There must be a space inside this paren.";
} else {
RE = /\( +[^ \r\n]|[^ \r\n] +\)/mg;
MESSAGE = "There should be no spaces inside this paren.";
if (exceptionsArray && exceptionsArray.length) {
options.braceException = exceptionsArray.indexOf("{}") !== -1 || false;
options.bracketException = exceptionsArray.indexOf("[]") !== -1 || false;
options.parenException = exceptionsArray.indexOf("()") !== -1 || false;
options.empty = exceptionsArray.indexOf("empty") !== -1 || false;
}
/**
* Used with the `never` option to produce, given the exception options,
* two regular expressions to check for missing and rejected spaces.
* @param {Object} opts The exception options
* @returns {Object} `missingSpace` and `rejectedSpace` regular expressions
* @private
*/
function getNeverChecks(opts) {
var missingSpaceOpeners = [],
missingSpaceClosers = [],
rejectedSpaceOpeners = [" ", "\\n", "\\r"],
rejectedSpaceClosers = [" ", "\\n", "\\r"],
missingSpaceCheck,
rejectedSpaceCheck;
// Populate openers and closers
if (opts.braceException) {
missingSpaceOpeners.push("\\{");
missingSpaceClosers.push("\\}");
rejectedSpaceOpeners.push("\\{");
rejectedSpaceClosers.push("\\}");
}
if (opts.bracketException) {
missingSpaceOpeners.push("\\[");
missingSpaceClosers.push("\\]");
rejectedSpaceOpeners.push("\\[");
rejectedSpaceClosers.push("\\]");
}
if (opts.parenException) {
missingSpaceOpeners.push("\\(");
missingSpaceClosers.push("\\)");
rejectedSpaceOpeners.push("\\(");
rejectedSpaceClosers.push("\\)");
}
if (opts.empty) {
missingSpaceOpeners.push("\\)");
missingSpaceClosers.push("\\(");
rejectedSpaceOpeners.push("\\)");
rejectedSpaceClosers.push("\\(");
}
if (missingSpaceOpeners.length) {
missingSpaceCheck = "\\((" + missingSpaceOpeners.join("|") + ")";
if (missingSpaceClosers.length) {
missingSpaceCheck += "|";
}
}
if (missingSpaceClosers.length) {
missingSpaceCheck += "(" + missingSpaceClosers.join("|") + ")\\)";
}
// compose the rejected regexp
rejectedSpaceCheck = "\\( +[^" + rejectedSpaceOpeners.join("") + "]";
rejectedSpaceCheck += "|[^" + rejectedSpaceClosers.join("") + "] +\\)";
return {
// e.g. \((\{)|(\})\) --- where {} is an exception
missingSpace: missingSpaceCheck || ".^",
// e.g. \( +[^ \n\r\{]|[^ \n\r\}] +\) --- where {} is an exception
rejectedSpace: rejectedSpaceCheck
};
}
/**
* Used with the `always` option to produce, given the exception options,
* two regular expressions to check for missing and rejected spaces.
* @param {Object} opts The exception options
* @returns {Object} `missingSpace` and `rejectedSpace` regular expressions
* @private
*/
function getAlwaysChecks(opts) {
var missingSpaceOpeners = [" ", "\\)", "\\r", "\\n"],
missingSpaceClosers = [" ", "\\(", "\\r", "\\n"],
rejectedSpaceOpeners = [],
rejectedSpaceClosers = [],
missingSpaceCheck,
rejectedSpaceCheck;
// Populate openers and closers
if (opts.braceException) {
missingSpaceOpeners.push("\\{");
missingSpaceClosers.push("\\}");
rejectedSpaceOpeners.push(" \\{");
rejectedSpaceClosers.push("\\} ");
}
if (opts.bracketException) {
missingSpaceOpeners.push("\\[");
missingSpaceClosers.push("\\]");
rejectedSpaceOpeners.push(" \\[");
rejectedSpaceClosers.push("\\] ");
}
if (opts.parenException) {
missingSpaceOpeners.push("\\(");
missingSpaceClosers.push("\\)");
rejectedSpaceOpeners.push(" \\(");
rejectedSpaceClosers.push("\\) ");
}
if (opts.empty) {
rejectedSpaceOpeners.push(" \\)");
rejectedSpaceClosers.push("\\( ");
}
// compose the allowed regexp
missingSpaceCheck = "\\([^" + missingSpaceOpeners.join("") + "]";
missingSpaceCheck += "|[^" + missingSpaceClosers.join("") + "]\\)";
// compose the rejected regexp
if (rejectedSpaceOpeners.length) {
rejectedSpaceCheck = "\\((" + rejectedSpaceOpeners.join("|") + ")";
if (rejectedSpaceClosers.length) {
rejectedSpaceCheck += "|";
}
}
if (rejectedSpaceClosers.length) {
rejectedSpaceCheck += "(" + rejectedSpaceClosers.join("|") + ")\\)";
}
return {
// e.g. \([^ \)\r\n\{]|[^ \(\r\n\}]\) --- where {} is an exception
missingSpace: missingSpaceCheck,
// e.g. \(( \{})|(\} )\) --- where {} is an excpetion
rejectedSpace: rejectedSpaceCheck || ".^"
};
}
spaceChecks = (context.options[0] === "always") ? getAlwaysChecks(options) : getNeverChecks(options);
missingSpaceRegExp = new RegExp(spaceChecks.missingSpace, "mg");
rejectedSpaceRegExp = new RegExp(spaceChecks.rejectedSpace, "mg");
//--------------------------------------------------------------------------

@@ -72,2 +207,3 @@ // Helpers

//--------------------------------------------------------------------------

@@ -88,5 +224,3 @@ // Public

sortSkipRanges();
while ((match = RE.exec(source)) !== null) {
function checkMatch(match, message) {
if (source.charAt(match.index) !== "(") {

@@ -104,6 +238,16 @@ // Matched a closing paren pattern

context.report(node, { line: line, column: column }, MESSAGE);
context.report(node, { line: line, column: column }, message);
}
}
sortSkipRanges();
while ((match = rejectedSpaceRegExp.exec(source)) !== null) {
checkMatch(match, REJECTED_SPACE_MESSAGE);
}
while ((match = missingSpaceRegExp.exec(source)) !== null) {
checkMatch(match, MISSING_SPACE_MESSAGE);
}
},

@@ -110,0 +254,0 @@

@@ -41,15 +41,2 @@ /**

if (node.loc.start.line === 1 && /^#!/.test(context.getSourceLines()[0])) {
/*
* HACK: return if we are on the first line and
* encounter a shebang at the beginning.
* It seems the parser will return this as a
* comment and filter out the # so we must fetch
* the actual source line. Is this being caused
* by esprima or eslint? Something else?
*/
return;
}
if (requireSpace) {

@@ -56,0 +43,0 @@

@@ -105,3 +105,3 @@ /**

context.report(jsdocNode, "Duplicate JSDoc parameter '{{name}}'.", { name: tag.name });
} else if (tag.name.indexOf(".") === - 1) {
} else if (tag.name.indexOf(".") === -1) {
params[tag.name] = 1;

@@ -108,0 +108,0 @@ }

@@ -6,2 +6,3 @@ /**

*/
/*eslint no-underscore-dangle:0*/

@@ -31,4 +32,3 @@ "use strict";

var nodeTypes = yaml.safeLoad(fs.readFileSync(
path.resolve(__dirname, "../../conf/nodetypes.yml"), "utf8"));
var nodeTypes = yaml.safeLoad(fs.readFileSync(path.resolve(__dirname, "../../conf/nodetypes.yml"), "utf8"));

@@ -68,10 +68,11 @@ //------------------------------------------------------------------------------

if (typeof nodeInfo.version === "number") {
return nodeInfo.version <= this._options.ecmascript;
} else if (nodeInfo.version === "jsx") {
return this._options.jsx;
} else {
return false;
if (nodeInfo && "version" in nodeInfo) {
if (typeof nodeInfo.version === "number") {
return nodeInfo.version <= this._options.ecmascript;
} else if (nodeInfo.version === "jsx") {
return this._options.jsx;
}
}
return false;
},

@@ -78,0 +79,0 @@

{
"name": "eslint",
"version": "0.10.0-alpha.1",
"version": "0.10.0-alpha.2",
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",

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

"debug": "^2.0.0",
"deepcopy": "^0.3.3",
"doctrine": "^0.5.2",

@@ -69,2 +70,3 @@ "escope": "~1.0.0",

"mocha-phantomjs": "^3.5.0",
"npm-license": "^0.2.3",
"phantomjs": "^1.9.9",

@@ -71,0 +73,0 @@ "proxyquire": "^1.0.0",

@@ -1,4 +0,5 @@

[![Build Status](https://travis-ci.org/eslint/eslint.svg?branch=master)](http://travis-ci.org/eslint/eslint)
[![NPM version](https://badge.fury.io/js/eslint.svg)](http://badge.fury.io/js/eslint)
[![Coverage Status](https://img.shields.io/coveralls/eslint/eslint.svg)](https://coveralls.io/r/eslint/eslint)
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Downloads][downloads-image]][downloads-url]
[![Bountysource](https://www.bountysource.com/badge/tracker?tracker_id=282608)](https://www.bountysource.com/trackers/282608-eslint?utm_source=282608&utm_medium=shield&utm_campaign=TRACKER_BADGE)

@@ -66,1 +67,11 @@

Join our [Mailing List](https://groups.google.com/group/eslint)
[npm-image]: https://img.shields.io/npm/v/eslint.svg?style=flat-square
[npm-url]: https://npmjs.org/package/eslint
[travis-image]: https://img.shields.io/travis/eslint/eslint.svg?style=flat-square
[travis-url]: https://travis-ci.org/eslint/eslint
[coveralls-image]: https://img.shields.io/coveralls/eslint/eslint.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/eslint/eslint?branch=master
[downloads-image]: http://img.shields.io/npm/dm/eslint.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/eslint
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