Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: remove unused arguments in codebase #9340

Merged
merged 1 commit into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,12 @@ function parseListConfig(string) {
* Ensures that variables representing built-in properties of the Global Object,
* and any globals declared by special block comments, are present in the global
* scope.
* @param {ASTNode} program The top node of the AST.
* @param {Scope} globalScope The global scope.
* @param {Object} config The existing configuration data.
* @param {Environments} envContext Env context
* @returns {void}
*/
function addDeclaredGlobals(program, globalScope, config, envContext) {
function addDeclaredGlobals(globalScope, config, envContext) {
const declaredGlobals = {},
exportedGlobals = {},
explicitGlobals = {},
Expand Down Expand Up @@ -946,7 +945,7 @@ module.exports = class Linter {
});

// augment global scope with declared global variables
addDeclaredGlobals(sourceCode.ast, scopeManager.scopes[0], config, this.environments);
addDeclaredGlobals(scopeManager.scopes[0], config, this.environments);

const eventGenerator = new CodePathAnalyzer(new NodeEventGenerator(emitter));

Expand Down
5 changes: 2 additions & 3 deletions lib/rules/max-len.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,10 @@ module.exports = {
* Gets the line after the comment and any remaining trailing whitespace is
* stripped.
* @param {string} line The source line with a trailing comment
* @param {number} lineNumber The one-indexed line number this is on
* @param {ASTNode} comment The comment to remove
* @returns {string} Line without comment and trailing whitepace
*/
function stripTrailingComment(line, lineNumber, comment) {
function stripTrailingComment(line, comment) {

// loc.column is zero-indexed
return line.slice(0, comment.loc.start.column).replace(/\s+$/, "");
Expand Down Expand Up @@ -306,7 +305,7 @@ module.exports = {
if (isFullLineComment(line, lineNumber, comment)) {
lineIsComment = true;
} else if (ignoreTrailingComments && isTrailingComment(line, lineNumber, comment)) {
line = stripTrailingComment(line, lineNumber, comment);
line = stripTrailingComment(line, comment);
}
}
if (ignorePattern && ignorePattern.test(line) ||
Expand Down
19 changes: 5 additions & 14 deletions lib/rules/no-alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ function findReference(scope, node) {
/**
* Checks if the given identifier node is shadowed in the given scope.
* @param {Object} scope The current scope.
* @param {Object} globalScope The global scope.
* @param {string} node The identifier node to check
* @returns {boolean} Whether or not the name is shadowed.
*/
function isShadowed(scope, globalScope, node) {
function isShadowed(scope, node) {
const reference = findReference(scope, node);

return reference && reference.resolved && reference.resolved.defs.length > 0;
Expand All @@ -66,15 +65,14 @@ function isShadowed(scope, globalScope, node) {
/**
* Checks if the given identifier node is a ThisExpression in the global scope or the global window property.
* @param {Object} scope The current scope.
* @param {Object} globalScope The global scope.
* @param {string} node The identifier node to check
* @returns {boolean} Whether or not the node is a reference to the global object.
*/
function isGlobalThisReferenceOrGlobalWindow(scope, globalScope, node) {
function isGlobalThisReferenceOrGlobalWindow(scope, node) {
if (scope.type === "global" && node.type === "ThisExpression") {
return true;
} else if (node.name === "window") {
return !isShadowed(scope, globalScope, node);
return !isShadowed(scope, node);
}

return false;
Expand All @@ -96,14 +94,7 @@ module.exports = {
},

create(context) {
let globalScope;

return {

Program() {
globalScope = context.getScope();
},

CallExpression(node) {
const callee = node.callee,
currentScope = context.getScope();
Expand All @@ -112,11 +103,11 @@ module.exports = {
if (callee.type === "Identifier") {
const identifierName = callee.name;

if (!isShadowed(currentScope, globalScope, callee) && isProhibitedIdentifier(callee.name)) {
if (!isShadowed(currentScope, callee) && isProhibitedIdentifier(callee.name)) {
report(context, node, identifierName);
}

} else if (callee.type === "MemberExpression" && isGlobalThisReferenceOrGlobalWindow(currentScope, globalScope, callee.object)) {
} else if (callee.type === "MemberExpression" && isGlobalThisReferenceOrGlobalWindow(currentScope, callee.object)) {
const identifierName = getPropertyName(callee);

if (isProhibitedIdentifier(identifierName)) {
Expand Down
5 changes: 2 additions & 3 deletions lib/rules/no-loop-func.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ function getTopLoopNode(node, excludedNode) {
* Checks whether a given reference which refers to an upper scope's variable is
* safe or not.
*
* @param {ASTNode} funcNode - A target function node.
* @param {ASTNode} loopNode - A containing loop node.
* @param {eslint-scope.Reference} reference - A reference to check.
* @returns {boolean} `true` if the reference is safe or not.
*/
function isSafe(funcNode, loopNode, reference) {
function isSafe(loopNode, reference) {
const variable = reference.resolved;
const definition = variable && variable.defs[0];
const declaration = definition && definition.parent;
Expand Down Expand Up @@ -183,7 +182,7 @@ module.exports = {
const references = context.getScope().through;

if (references.length > 0 &&
!references.every(isSafe.bind(null, node, loopNode))
!references.every(isSafe.bind(null, loopNode))
) {
context.report({ node, message: "Don't make functions within a loop." });
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/padding-line-between-statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ function verifyForAny() {
* blank lines automatically.
*
* @param {RuleContext} context The rule context to report.
* @param {ASTNode} prevNode The previous node to check.
* @param {ASTNode} _ Unused. The previous node to check.
* @param {ASTNode} nextNode The next node to check.
* @param {Array<Token[]>} paddingLines The array of token pairs that blank
* lines exist between the pair.
* @returns {void}
* @private
*/
function verifyForNever(context, prevNode, nextNode, paddingLines) {
function verifyForNever(context, _, nextNode, paddingLines) {
if (paddingLines.length === 0) {
return;
}
Expand Down
14 changes: 6 additions & 8 deletions lib/rules/space-unary-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,19 @@ module.exports = {

/**
* Checks if an override exists for a given operator.
* @param {ASTnode} node AST node
* @param {string} operator Operator
* @returns {boolean} Whether or not an override has been provided for the operator
*/
function overrideExistsForOperator(node, operator) {
function overrideExistsForOperator(operator) {
return options.overrides && options.overrides.hasOwnProperty(operator);
}

/**
* Gets the value that the override was set to for this operator
* @param {ASTnode} node AST node
* @param {string} operator Operator
* @returns {boolean} Whether or not an override enforces a space with this operator
*/
function overrideEnforcesSpaces(node, operator) {
function overrideEnforcesSpaces(operator) {
return options.overrides[operator];
}

Expand Down Expand Up @@ -153,8 +151,8 @@ module.exports = {
function checkUnaryWordOperatorForSpaces(node, firstToken, secondToken, word) {
word = word || firstToken.value;

if (overrideExistsForOperator(node, word)) {
if (overrideEnforcesSpaces(node, word)) {
if (overrideExistsForOperator(word)) {
if (overrideEnforcesSpaces(word)) {
verifyWordHasSpaces(node, firstToken, secondToken, word);
} else {
verifyWordDoesntHaveSpaces(node, firstToken, secondToken, word);
Expand Down Expand Up @@ -292,8 +290,8 @@ module.exports = {

const operator = node.prefix ? tokens[0].value : tokens[1].value;

if (overrideExistsForOperator(node, operator)) {
if (overrideEnforcesSpaces(node, operator)) {
if (overrideExistsForOperator(operator)) {
if (overrideEnforcesSpaces(operator)) {
verifyNonWordsHaveSpaces(node, firstToken, secondToken);
} else {
verifyNonWordsDontHaveSpaces(node, firstToken, secondToken);
Expand Down