Skip to content

Commit

Permalink
Chore: Convert all var to const or let
Browse files Browse the repository at this point in the history
  • Loading branch information
Casey Visco committed Aug 13, 2016
1 parent 293675c commit 5d4b5c8
Show file tree
Hide file tree
Showing 46 changed files with 331 additions and 336 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ rules:
named: never
no-use-before-define: off
require-jsdoc: off
no-var: error
one-var:
- error
- never
21 changes: 9 additions & 12 deletions lib/rules/amd-function-arity.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

var util = require("../util");
const util = require("../util");

module.exports = {
meta: {
Expand Down Expand Up @@ -36,9 +36,9 @@ module.exports = {
},

create: function (context) {
var allowExtraDependencies = (context.options && context.options[0] && context.options[0].allowExtraDependencies) || false;
var TOO_MANY_PARAMS_MESSAGE = "Too many parameters in {{functionName}} callback (expected {{expected}}, found {{actual}}).";
var TOO_FEW_PARAMS_MESSAGE = "Not enough parameters in {{functionName}} callback (expected {{expected}}, found {{actual}}).";
const allowExtraDependencies = (context.options && context.options[0] && context.options[0].allowExtraDependencies) || false;
const TOO_MANY_PARAMS_MESSAGE = "Too many parameters in {{functionName}} callback (expected {{expected}}, found {{actual}}).";
const TOO_FEW_PARAMS_MESSAGE = "Not enough parameters in {{functionName}} callback (expected {{expected}}, found {{actual}}).";

function isFunctionExpression(node) {
return node.type === "FunctionExpression";
Expand All @@ -53,26 +53,23 @@ module.exports = {
return allowExtraDependencies;
}

var unassignedPaths = dependencyNodes.slice(callbackParams.length);
const unassignedPaths = dependencyNodes.slice(callbackParams.length);

return unassignedPaths.every(function (path) {
return allowExtraDependencies.indexOf(path.value) !== -1;
});
}

function checkArity(node, funcName) {
var dependencyNodes = util.getDependencyNodes(node),
dependencyCount,
callbackParams,
actualParamCount;
const dependencyNodes = util.getDependencyNodes(node);

if (!dependencyNodes) {
return;
}

dependencyCount = dependencyNodes.length;
callbackParams = util.getAmdCallback(node).params;
actualParamCount = callbackParams.length;
const dependencyCount = dependencyNodes.length;
const callbackParams = util.getAmdCallback(node).params;
const actualParamCount = callbackParams.length;

if (dependencyCount < actualParamCount) {
context.report(node, TOO_MANY_PARAMS_MESSAGE, {
Expand Down
18 changes: 8 additions & 10 deletions lib/rules/enforce-define.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

"use strict";

var path = require("path");
var util = require("../util");
const path = require("path");
const util = require("../util");

module.exports = {
meta: {
Expand All @@ -30,9 +30,8 @@ module.exports = {
},

create: function (context) {

var MESSAGE = "File must be wrapped in a `define` call";
var ignoredFiles = context.options[0] || [];
const MESSAGE = "File must be wrapped in a `define` call";
const ignoredFiles = context.options[0] || [];

/**
* Determine if supplied `node` represents an expression of any kind.
Expand All @@ -53,21 +52,20 @@ module.exports = {
* @returns {Boolean} true if filename is allowed
*/
function isIgnoredFile(filename) {
var basename = path.basename(filename);
const basename = path.basename(filename);
return ignoredFiles.indexOf(basename) !== -1;
}

return {
"Program": function (node) {
var filename = context.getFilename(),
child, length, i;
const filename = context.getFilename();

if (isIgnoredFile(filename)) {
return;
}

for (i = 0, length = node.body.length; i < length; i += 1) {
child = node.body[i];
for (let i = 0, length = node.body.length; i < length; i += 1) {
const child = node.body[i];

if (!(isExpressionStatement(child) && util.isDefineCall(child.expression))) {
context.report(node, MESSAGE);
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-amd-define.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

var util = require("../util");
const util = require("../util");

module.exports = {
meta: {
Expand All @@ -14,7 +14,7 @@ module.exports = {
},

create: function (context) {
var MESSAGE = "AMD form of `define` is not allowed.";
const MESSAGE = "AMD form of `define` is not allowed.";

return {
"CallExpression": function (node) {
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-assign-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

var util = require("../util");
const util = require("../util");

module.exports = {
meta: {
Expand All @@ -14,8 +14,8 @@ module.exports = {
},

create: function (context) {
var MESSAGE = "Invalid assignment to `exports`.";
var fnStack = [];
const MESSAGE = "Invalid assignment to `exports`.";
const fnStack = [];

/**
* Determine if supplied `node` represents an assignment to `exports`.
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-assign-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
},

create: function (context) {
var MESSAGE = "Invalid assignment to `require`.";
const MESSAGE = "Invalid assignment to `require`.";

/**
* Determine if supplied `node` represents a `require` identifier
Expand Down
7 changes: 3 additions & 4 deletions lib/rules/no-commonjs-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

var util = require("../util");
const util = require("../util");

module.exports = {
meta: {
Expand All @@ -14,9 +14,8 @@ module.exports = {
},

create: function (context) {

var MESSAGE = "Unexpected use of `exports` in module definition.";
var fnStack = [];
const MESSAGE = "Unexpected use of `exports` in module definition.";
const fnStack = [];

/**
* Determine if supplied `node` represents an assignment to a property of
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-commonjs-module-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

var util = require("../util");
const util = require("../util");

module.exports = {
meta: {
Expand All @@ -14,8 +14,8 @@ module.exports = {
},

create: function (context) {
var MESSAGE = "Unexpected use of `module.exports` in module definition.";
var fnStack = [];
const MESSAGE = "Unexpected use of `module.exports` in module definition.";
const fnStack = [];

/**
* Determine if supplied `node` represents an assignment to `module.exports`
Expand Down
12 changes: 6 additions & 6 deletions lib/rules/no-commonjs-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

"use strict";

var isDefineCall = require("../util").isDefineCall;
var isCommonJsWrapper = require("../util").isCommonJsWrapper;
const isDefineCall = require("../util").isDefineCall;
const isCommonJsWrapper = require("../util").isCommonJsWrapper;

module.exports = {
meta: {
Expand All @@ -17,8 +17,8 @@ module.exports = {
},

create: function (context) {
var MESSAGE = "Unexpected `return` in module definition.";
var functions = [];
const MESSAGE = "Unexpected `return` in module definition.";
const functions = [];

/**
* Mark entrance into a function by pushing a new object onto the functions
Expand All @@ -29,7 +29,7 @@ module.exports = {
* @returns {void}
*/
function enterFunction(node) {
var parent = node.parent;
const parent = node.parent;

functions.push({
isModuleDef: isDefineCall(parent) && isCommonJsWrapper(parent)
Expand All @@ -54,7 +54,7 @@ module.exports = {
"FunctionExpression:exit": exitFunction,

"ReturnStatement": function (node) {
var fn = functions[functions.length - 1];
const fn = functions[functions.length - 1];

if (fn.isModuleDef) {
context.report(node, MESSAGE);
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-commonjs-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

var util = require("../util");
const util = require("../util");

module.exports = {
meta: {
Expand All @@ -14,7 +14,7 @@ module.exports = {
},

create: function (context) {
var MESSAGE = "Simplified CommonJS Wrapper form of `define` is not allowed";
const MESSAGE = "Simplified CommonJS Wrapper form of `define` is not allowed";

return {
"CallExpression": function (node) {
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/no-conditional-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

var util = require("../util");
const util = require("../util");

module.exports = {
meta: {
Expand All @@ -14,8 +14,8 @@ module.exports = {
},

create: function (context) {
var MESSAGE = "Conditional `require` calls are not allowed.";
var condStack = [];
const MESSAGE = "Conditional `require` calls are not allowed.";
const condStack = [];

/**
* Determine if we are currently inside of a conditional.
Expand Down Expand Up @@ -47,7 +47,7 @@ module.exports = {
* @returns {void}
*/
function popConditional(node) {
var len = condStack.length;
const len = condStack.length;

if (len && condStack[len - 1] === node) {
condStack.pop();
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-dynamic-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

var util = require("../util");
const util = require("../util");

module.exports = {
meta: {
Expand All @@ -14,7 +14,7 @@ module.exports = {
},

create: function (context) {
var MESSAGE = "Dynamic `require` calls are not allowed.";
const MESSAGE = "Dynamic `require` calls are not allowed.";

return {
"CallExpression": function (node) {
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-function-define.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

var util = require("../util");
const util = require("../util");

module.exports = {
meta: {
Expand All @@ -14,7 +14,7 @@ module.exports = {
},

create: function (context) {
var MESSAGE = "Simple function form of `define` is not allowed";
const MESSAGE = "Simple function form of `define` is not allowed";

return {
"CallExpression": function (node) {
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-invalid-define.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

var util = require("../util");
const util = require("../util");

module.exports = {
meta: {
Expand All @@ -14,7 +14,7 @@ module.exports = {
},

create: function (context) {
var MESSAGE = "Invalid module definition";
const MESSAGE = "Invalid module definition";

return {
"CallExpression": function (node) {
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-invalid-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

var util = require("../util");
const util = require("../util");

module.exports = {
meta: {
Expand All @@ -14,7 +14,7 @@ module.exports = {
},

create: function (context) {
var MESSAGE = "Invalid arguments provided to `require` call.";
const MESSAGE = "Invalid arguments provided to `require` call.";

return {
"CallExpression": function (node) {
Expand Down
Loading

0 comments on commit 5d4b5c8

Please sign in to comment.