Skip to content

Commit

Permalink
Merge pull request #261 from lo1tuma/includes
Browse files Browse the repository at this point in the history
Use includes instead of indexOf
  • Loading branch information
lo1tuma authored Jul 31, 2020
2 parents ddb7ef2 + d53a8cf commit a9c51b3
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 14 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "holidaycheck/es2015",
"plugins": [ "node" ],
"plugins": [ "node", "unicorn" ],

"env": {
"node": true
Expand All @@ -12,7 +12,8 @@
},

"rules": {
"node/no-unsupported-features": "error"
"node/no-unsupported-features": "error",
"unicorn/prefer-includes": "error"
},

"overrides": [
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-exclusive-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
function matchesMochaTestFunction(object) {
const name = astUtils.getNodeName(object);

return mochaTestFunctions.indexOf(name) !== -1;
return mochaTestFunctions.includes(name);
}

function isPropertyNamedOnly(property) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-hooks-for-single-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = {
if (layer.testCount <= 1) {
layer.hookNodes
.filter(function (hookNode) {
return allowedHooks.indexOf(hookNode.name) === -1;
return !allowedHooks.includes(hookNode.name);
})
.forEach(function (hookNode) {
context.report({
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-identical-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function newLayer() {

function handlTestCaseTitles(context, titles, node, title) {
if (astUtil.isTestCase(node)) {
if (titles.indexOf(title) !== -1) {
if (titles.includes(title)) {
context.report({
node,
message: 'Test title is used multiple times in the same test suite.'
Expand All @@ -28,7 +28,7 @@ function handlTestSuiteTitles(context, titles, node, title) {
if (!astUtil.isDescribe(node, additionalSuiteNames(settings))) {
return;
}
if (titles.indexOf(title) !== -1) {
if (titles.includes(title)) {
context.report({
node,
message: 'Test suite title is used multiple times.'
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-setup-in-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {

function isNestedInDescribeBlock() {
return nesting.length &&
nesting.indexOf(PURE) === -1 &&
!nesting.includes(PURE) &&
nesting.lastIndexOf(FUNCTION) < nesting.lastIndexOf(DESCRIBE);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-skipped-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let mochaTestFunctions;
let mochaXFunctions;

function matchesMochaTestFunction(object) {
return object && mochaTestFunctions.indexOf(object.name) !== -1;
return object && mochaTestFunctions.includes(object.name);
}

function isPropertyNamedSkip(property) {
Expand All @@ -20,7 +20,7 @@ function isCallToMochasSkipFunction(callee) {
}

function isMochaXFunction(name) {
return mochaXFunctions.indexOf(name) !== -1;
return mochaXFunctions.includes(name);
}

function isCallToMochaXFunction(callee) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/valid-suite-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {
inlineOptions(context.options);

function isSuite(node) {
return node.callee && node.callee.name && suiteNames.indexOf(node.callee.name) > -1;
return node.callee && node.callee.name && suiteNames.includes(node.callee.name);
}

function hasValidSuiteDescription(mochaCallExpression) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/valid-test-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports = {
inlineOptions(context.options);

function isTest(node) {
return node.callee && node.callee.name && testNames.indexOf(node.callee.name) > -1;
return node.callee && node.callee.name && testNames.includes(node.callee.name);
}

function hasValidTestDescription(mochaCallExpression) {
Expand Down
6 changes: 3 additions & 3 deletions lib/util/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ function getNodeName(node) {
function isDescribe(node, additionalSuiteNames = []) {
const describeAliases = getSuiteNames({ modifiers: [ 'skip', 'only' ], additionalSuiteNames });

return isCallExpression(node) && describeAliases.indexOf(getNodeName(node.callee)) > -1;
return isCallExpression(node) && describeAliases.includes(getNodeName(node.callee));
}

function isHookIdentifier(node) {
return node &&
node.type === 'Identifier' &&
hooks.indexOf(node.name) !== -1;
hooks.includes(node.name);
}

function isHookCall(node) {
Expand All @@ -48,7 +48,7 @@ function isTestCase(node, options = {}) {
const { modifiers = [ 'skip', 'only' ] } = options;

const testCaseNames = getTestCaseNames({ modifiers });
return isCallExpression(node) && testCaseNames.indexOf(getNodeName(node.callee)) > -1;
return isCallExpression(node) && testCaseNames.includes(getNodeName(node.callee));
}

function isSuiteConfigExpression(node) {
Expand Down
Loading

0 comments on commit a9c51b3

Please sign in to comment.