Skip to content

Commit

Permalink
Merge pull request #5458 from captbaritone/issue5456
Browse files Browse the repository at this point in the history
Update: Replace getLast() with lodash.last() (fixes #5456)
  • Loading branch information
nzakas committed Mar 3, 2016
2 parents a8cf60b + 0547072 commit e86a736
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 74 deletions.
10 changes: 5 additions & 5 deletions docs/developer-guide/code-path-analysis.md
Expand Up @@ -198,7 +198,7 @@ bar();
### To check whether or not this is reachable

```js
var getLast = require("../ast-utils").getLast;
var last = require("lodash").last;

function isReachable(segment) {
return segment.reachable;
Expand All @@ -218,7 +218,7 @@ module.exports = function(context) {

// Checks reachable or not.
"ExpressionStatement": function(node) {
var codePath = getLast(codePathStack);
var codePath = last(codePathStack);

// Checks the current code path segments.
if (!codePath.currentSegments.some(isReachable)) {
Expand All @@ -242,7 +242,7 @@ So a rule must not modify those instances.
Please use a map of information instead.

```js
var getLast = require("../ast-utils").getLast;
var last = require("lodash").last;

function hasCb(node, context) {
if (node.type.indexOf("Function") !== -1) {
Expand Down Expand Up @@ -289,7 +289,7 @@ module.exports = function(context) {
// Manages state of code paths.
"onCodePathSegmentStart": function(segment) {
// Ignores if `cb` doesn't exist.
if (!getLast(funcInfoStack).hasCb) {
if (!last(funcInfoStack).hasCb) {
return;
}

Expand All @@ -307,7 +307,7 @@ module.exports = function(context) {

// Checks reachable or not.
"CallExpression": function(node) {
var funcInfo = getLast(funcInfoStack);
var funcInfo = last(funcInfoStack);

// Ignores if `cb` doesn't exist.
if (!funcInfo.hasCb) {
Expand Down
21 changes: 5 additions & 16 deletions lib/rules/comma-dangle.js
Expand Up @@ -10,21 +10,10 @@
"use strict";

//------------------------------------------------------------------------------
// Helpers
// Requirements
//------------------------------------------------------------------------------

/**
* Gets the last element of a given array.
*
* @param {*[]} xs - An array to get.
* @returns {*} The last element, or undefined.
*/
function getLast(xs) {
if (xs.length === 0) {
return null;
}
return xs[xs.length - 1];
}
var lodash = require("lodash");

/**
* Checks whether or not a trailing comma is allowed in a given node.
Expand Down Expand Up @@ -74,7 +63,7 @@ module.exports = function(context) {
* @returns {boolean} `true` if the node is multiline.
*/
function isMultiline(node) {
var lastItem = getLast(node.properties || node.elements || node.specifiers);
var lastItem = lodash.last(node.properties || node.elements || node.specifiers);
if (!lastItem) {
return false;
}
Expand Down Expand Up @@ -106,7 +95,7 @@ module.exports = function(context) {
* @returns {void}
*/
function forbidTrailingComma(node) {
var lastItem = getLast(node.properties || node.elements || node.specifiers);
var lastItem = lodash.last(node.properties || node.elements || node.specifiers);
if (!lastItem || (node.type === "ImportDeclaration" && lastItem.type !== "ImportSpecifier")) {
return;
}
Expand Down Expand Up @@ -142,7 +131,7 @@ module.exports = function(context) {
* @returns {void}
*/
function forceTrailingComma(node) {
var lastItem = getLast(node.properties || node.elements || node.specifiers);
var lastItem = lodash.last(node.properties || node.elements || node.specifiers);
if (!lastItem || (node.type === "ImportDeclaration" && lastItem.type !== "ImportSpecifier")) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-fallthrough.js
Expand Up @@ -8,7 +8,7 @@
// Requirements
//------------------------------------------------------------------------------

var getLast = require("../util").getLast;
var lodash = require("lodash");

//------------------------------------------------------------------------------
// Helpers
Expand All @@ -24,7 +24,7 @@ var FALLTHROUGH_COMMENT = /falls?\s?through/i;
*/
function hasFallthroughComment(node, context) {
var sourceCode = context.getSourceCode();
var comment = getLast(sourceCode.getComments(node).leading);
var comment = lodash.last(sourceCode.getComments(node).leading);

return Boolean(comment && FALLTHROUGH_COMMENT.test(comment.value));
}
Expand Down Expand Up @@ -76,7 +76,7 @@ module.exports = function(context) {
// And allows empty cases and the last case.
if (currentCodePath.currentSegments.some(isReachable) &&
node.consequent.length > 0 &&
getLast(node.parent.cases) !== node
lodash.last(node.parent.cases) !== node
) {
fallthroughCase = node;
}
Expand Down
22 changes: 0 additions & 22 deletions lib/util.js

This file was deleted.

28 changes: 0 additions & 28 deletions tests/lib/util.js

This file was deleted.

0 comments on commit e86a736

Please sign in to comment.