diff --git a/CHANGELOG.md b/CHANGELOG.md index 78fb629..4e45f54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## 0.4.2 +- Fixes false positives from object prototype fields + ## 0.4.1 - Readme and copy updates diff --git a/index.js b/index.js index 36f96cb..6342e47 100644 --- a/index.js +++ b/index.js @@ -11,12 +11,15 @@ function warnOnce() { } function createExpectedCountMap(countMapOrNameList) { - if (!Array.isArray(countMapOrNameList)) { - return countMapOrNameList; - } - const expectedCountMap = {}; - for (const functionName of countMapOrNameList) { - expectedCountMap[functionName] = 1; + const expectedCountMap = new Map(); + if (Array.isArray(countMapOrNameList)) { + countMapOrNameList.forEach(functionName => + expectedCountMap.set(functionName, 1) + ); + } else { + Object.entries(countMapOrNameList).forEach(([key, value]) => + expectedCountMap.set(key, value) + ); } return expectedCountMap; } @@ -61,8 +64,9 @@ function getCalleeNames(node) { function assertThatNodeHasExpectedGenerics({ context, expectedCountMap, node, nodeType }) { const possibleNames = getCalleeNames(node); - const matchingRuleName = possibleNames.find(possibleName => expectedCountMap[possibleName]); - const expectedCount = expectedCountMap[matchingRuleName]; + const matchingRuleName = possibleNames.find(possibleName => expectedCountMap.has(possibleName)); + if (!matchingRuleName) return; + const expectedCount = expectedCountMap.get(matchingRuleName); if (!expectedCount) return; const actualCount = getParamsLength(node.typeParameters) || getParamsLength(node.typeArguments) || 0; diff --git a/package.json b/package.json index 33c2962..163717e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "eslint-plugin-require-explicit-generics", "description": "Force configured functions to include explicit generics", - "version": "0.4.1", + "version": "0.4.2", "main": "index.js", "homepage": "https://github.com/mattorchard/eslint-plugin-require-explicit-generics", "repository": {