Skip to content

Commit

Permalink
Merge 1dfc428 into 1c5935b
Browse files Browse the repository at this point in the history
  • Loading branch information
platinumazure committed Jun 27, 2023
2 parents 1c5935b + 1dfc428 commit 6930715
Show file tree
Hide file tree
Showing 20 changed files with 2,096 additions and 9,398 deletions.
4 changes: 2 additions & 2 deletions lib/rules/assert-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ module.exports = {
function getAssertContext() {
assert.ok(testStack.length);

return testStack[testStack.length - 1].assertContextVar;
return testStack.at(-1).assertContextVar;
}

function checkAssertArity(callExpressionNode) {
const allowedArities = utils.getAllowedArities(callExpressionNode.callee, getAssertContext()),
assertArgs = callExpressionNode.arguments,
lastArg = assertArgs[assertArgs.length - 1],
lastArg = assertArgs.at(-1),
mayHaveMessage = lastArg && isPossibleMessage(lastArg);

const definitelyTooFewArgs = allowedArities.every(function (arity) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/literal-compare-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
function getAssertContext() {
assert.ok(testStack.length);

return testStack[testStack.length - 1].assertContextVar;
return testStack.at(-1).assertContextVar;
}

function checkLiteralCompareOrder(args, compareActualFirst) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-assert-equal-boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
function getCurrentAssertContextVariable() {
assert(testStack.length, "Test stack should not be empty");

return testStack[testStack.length - 1].assertVar;
return testStack.at(-1).assertVar;
}

// Check for something like `equal(...)` without assert parameter.
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-assert-equal.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
function getCurrentAssertContextVariable() {
assert(testStack.length, "Test stack should not be empty");

return testStack[testStack.length - 1].assertVar;
return testStack.at(-1).assertVar;
}

function isAssertEqual(calleeNode) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-assert-logical-expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = {
let result = null;

if (testStack.length > 0) {
result = testStack[testStack.length - 1].assertContextVar;
result = testStack.at(-1).assertContextVar;
}

return result;
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-async-in-loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
assertVariableStack = [];

function isAsyncCallExpression(node) {
const assertContextVar = assertVariableStack[assertVariableStack.length - 1];
const assertContextVar = assertVariableStack.at(-1);
return utils.isAsyncCallExpression(node, assertContextVar);
}

Expand Down Expand Up @@ -65,7 +65,7 @@ module.exports = {

/* istanbul ignore else: correctly returning undefined */
if (isAsyncCallExpression(node)) {
const assertContextVar = assertVariableStack[assertVariableStack.length - 1];
const assertContextVar = assertVariableStack.at(-1);
callType = `${assertContextVar}.async()`;
} else if (utils.isStop(node.callee)) {
callType = "stop()";
Expand All @@ -77,7 +77,7 @@ module.exports = {
}

function reportError(node) {
const loopNode = loopStack[loopStack.length - 1],
const loopNode = loopStack.at(-1),
loopType = loopNode.type;

context.report({
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-compare-relation-boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
function shouldCheckArguments(calleeNode) {
assert.ok(testStack.length);

const assertContextVar = testStack[testStack.length - 1].assertContextVar;
const assertContextVar = testStack.at(-1).assertContextVar;

return utils.isAssertion(calleeNode, assertContextVar) && utils.isComparativeAssertion(calleeNode, assertContextVar);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-conditional-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = {
}

function isAssertion(calleeNode) {
const assertContextVar = testStack[testStack.length - 1].assertContextVar;
const assertContextVar = testStack.at(-1).assertContextVar;
return utils.isAssertion(calleeNode, assertContextVar);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-early-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = {
if (utils.isTest(node.callee)) {
assertContextVar = utils.getAssertContextNameForTest(node.arguments);
} else if (utils.isAssertion(node.callee, assertContextVar) && functionScopes.length > 0) {
functionScopes[functionScopes.length - 1].returnAndAssertNodes.push(node);
functionScopes.at(-1).returnAndAssertNodes.push(node);
}
},

Expand All @@ -84,7 +84,7 @@ module.exports = {

"ReturnStatement": function (node) {
if (functionScopes.length > 0) {
functionScopes[functionScopes.length - 1].returnAndAssertNodes.push(node);
functionScopes.at(-1).returnAndAssertNodes.push(node);
}
},

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-hooks-from-ancestor-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = {
moduleStackInfo.hookIdentifierName = hooksParam ? hooksParam.name : null;
moduleStack.push(moduleStackInfo);
} else if (isHookInvocation(node)) {
const containingModuleInfo = moduleStack[moduleStack.length - 1];
const containingModuleInfo = moduleStack.at(-1);
const expectedHooksIdentifierName = containingModuleInfo.hookIdentifierName;
const usedHooksIdentifierName = node.callee.object.name;
const invokedMethodName = node.callee.property.name;
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/no-identical-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ module.exports = {
}

function getCurrentModuleNode() {
const parentModule = mapModuleNodeToInfo.get(modulesStack[modulesStack.length - 1]);
const parentModule = mapModuleNodeToInfo.get(modulesStack.at(-1));
if (parentModule.modules.length > 0) {
// Find the last test-less module at the current level if one exists, i.e: module('foo');
const lastTestLessModule = findLast(parentModule.modules, node => !mapModuleNodeToInfo.get(node).hasNestedTests);
if (lastTestLessModule) {
return lastTestLessModule;
}
}
return modulesStack[modulesStack.length - 1];
return modulesStack.at(-1);
}

function handleTestNames(node) {
Expand Down Expand Up @@ -96,7 +96,7 @@ module.exports = {
function handleModuleNames(node) {
if (utils.isModule(node.callee)) {
const title = node.arguments[0].value;
const currentModuleNode = modulesStack[modulesStack.length - 1];
const currentModuleNode = modulesStack.at(-1);
const currentModuleInfo = mapModuleNodeToInfo.get(currentModuleNode);

// Check if we have seen the same title in a sibling module.
Expand Down Expand Up @@ -149,7 +149,7 @@ module.exports = {
},

"CallExpression:exit": function (node) {
if (modulesStack.length > 0 && modulesStack[modulesStack.length - 1] === node) {
if (modulesStack.length > 0 && modulesStack.at(-1) === node) {
// Exiting a module so pop it from the stack.
modulesStack.pop();

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-negated-ok.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = {

/* istanbul ignore else: correctly returns null */
if (asyncStateStack.length > 0) {
result = asyncStateStack[asyncStateStack.length - 1].assertContextVar;
result = asyncStateStack.at(-1).assertContextVar;
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-ok-equality.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = {
const NEGATIVE_ASSERTIONS = new Set(["notOk", "false"]);

function getAssertContextVar() {
const state = asyncStateStack[asyncStateStack.length - 1];
const state = asyncStateStack.at(-1);
return state && state.assertContextVar;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-qunit-start-in-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = {
if (utils.isTest(node.callee)) {
contextStack.push("test");
} else if (contextStack.length > 0 && isQUnitStart(node.callee)) {
const currentContext = contextStack[contextStack.length - 1];
const currentContext = contextStack.at(-1);

context.report({
node: node,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-throws-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const assert = require("assert"),
function getAssertVar(testStack) {
assert.ok(testStack && testStack.length > 0);

return testStack[testStack.length - 1].assertVar;
return testStack.at(-1).assertVar;
}

function isThrows(calleeNode, assertVar) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-object-in-propequal.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
function getCurrentAssertContextVariable() {
assert(testStack.length, "Test stack should not be empty");

return testStack[testStack.length - 1].assertVar;
return testStack.at(-1).assertVar;
}

function isGlobalPropEqual(calleeNode) {
Expand Down
10 changes: 5 additions & 5 deletions lib/rules/resolve-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ module.exports = {
const asyncStateStack = [];

function isAsyncCallExpression(callExpressionNode) {
const asyncState = asyncStateStack[asyncStateStack.length - 1];
const asyncState = asyncStateStack.at(-1);
const assertContextVar = asyncState && asyncState.assertContextVar;

return utils.isAsyncCallExpression(callExpressionNode, assertContextVar);
}

function getAsyncCallbackVarOrNull(calleeNode) {
const asyncState = asyncStateStack[asyncStateStack.length - 1];
const asyncState = asyncStateStack.at(-1);
let result = null;

if (asyncState) {
Expand All @@ -62,14 +62,14 @@ module.exports = {
}

function incrementSemaphoreCount(amount) {
const asyncState = asyncStateStack[asyncStateStack.length - 1];
const asyncState = asyncStateStack.at(-1);
if (asyncState) {
asyncState.stopSemaphoreCount += amount;
}
}

function addAsyncCallbackVar(lhsNode) {
const asyncState = asyncStateStack[asyncStateStack.length - 1];
const asyncState = asyncStateStack.at(-1);

/* istanbul ignore else: will correctly do nothing */
if (asyncState) {
Expand All @@ -78,7 +78,7 @@ module.exports = {
}

function markAsyncCallbackVarCalled(name) {
const asyncState = asyncStateStack[asyncStateStack.length - 1];
const asyncState = asyncStateStack.at(-1);

/* istanbul ignore else: will correctly do nothing */
if (asyncState) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ exports.createAssertionCheck = function (assertions, errorMessageConfig) {
function getCurrentAssertContextVariable() {
assert(testStack.length, "Test stack should not be empty");

return testStack[testStack.length - 1].assertVar;
return testStack.at(-1).assertVar;
}

function isMethodCalledOnLocalAssertObject(calleeNode) {
Expand Down

0 comments on commit 6930715

Please sign in to comment.