Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
[Perf] Remove getRange() from rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevils committed Apr 12, 2016
1 parent 56a84ba commit ff293c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
6 changes: 1 addition & 5 deletions lib/rules/disallow-spaces-in-call-expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@ module.exports.prototype = {

check: function(file, errors) {
file.iterateNodesByType(['CallExpression', 'NewExpression'], function(node) {
function doesTokenBelongToNode(token, node) {
return token.getRange()[1] <= node.getRange()[1];
}

var lastCalleeToken = file.getLastNodeToken(node.callee);
var roundBraceToken = file.findNextToken(lastCalleeToken, 'Punctuator', '(');

// CallExpressions can't have missing parens, otherwise they're identifiers
if (node.type === 'NewExpression') {
if (roundBraceToken === null || !doesTokenBelongToNode(roundBraceToken, node)) {
if (roundBraceToken === null || roundBraceToken.parentElement !== node) {
return;
}
}
Expand Down
18 changes: 4 additions & 14 deletions lib/rules/require-blocks-on-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,9 @@

var assert = require('assert');

function hasCommentInBlock(block, commentTokens) {
var count;
var comment;

for (count = 0; count < commentTokens.length; count++) {
comment = commentTokens[count];
if (comment.getRange()[0] >= block.getRange()[0] &&
comment.getRange()[1] <= block.getRange()[1]) {
function hasCommentInBlock(block) {
for (var i = 0; i < block.childElements.length; i++) {
if (block.childElements[i].isComment) {
return true;
}
}
Expand Down Expand Up @@ -215,16 +210,11 @@ module.exports.prototype = {
check: function(file, errors) {
var minLines = this._minLines;
var includeComments = this._includeComments;
var commentTokens = [];

file.iterateTokensByType(['CommentLine', 'CommentBlock'], function(commentToken) {
commentTokens.push(commentToken);
});

file.iterateNodesByType('BlockStatement', function(node) {
var hasComment = false;
if (includeComments === true) {
hasComment = hasCommentInBlock(node, commentTokens);
hasComment = hasCommentInBlock(node);
}

if (hasComment === false && node.body.length <= minLines) {
Expand Down

0 comments on commit ff293c9

Please sign in to comment.