From f507ff35ff01946d8e06f0af4001c12a24592522 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 16 Sep 2016 02:13:24 -0700 Subject: [PATCH] Cache extension settings using `has`. --- package.json | 1 + resolvers/webpack/index.js | 3 ++- src/rules/extensions.js | 15 ++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index d49f36cb3..0d02e57bd 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "es6-map": "^0.1.3", "es6-set": "^0.1.4", "eslint-import-resolver-node": "^0.2.0", + "has": "^1.0.1", "lodash.cond": "^4.3.0", "lodash.endswith": "^4.0.1", "lodash.find": "^4.3.0", diff --git a/resolvers/webpack/index.js b/resolvers/webpack/index.js index d463695a0..535ebf2b7 100644 --- a/resolvers/webpack/index.js +++ b/resolvers/webpack/index.js @@ -10,6 +10,7 @@ var findRoot = require('find-root') , assign = require('object-assign') , resolve = require('resolve') , semver = require('semver') + , has = require('has') var log = require('debug')('eslint-plugin-import:resolver:webpack') @@ -265,7 +266,7 @@ function findExternal(source, externals, context) { // else, vanilla object for (var key in externals) { - if (!externals.hasOwnProperty(key)) continue + if (!has(externals, key)) continue if (source === key) return true } return false diff --git a/src/rules/extensions.js b/src/rules/extensions.js index e4acd188b..1522ffe7c 100644 --- a/src/rules/extensions.js +++ b/src/rules/extensions.js @@ -1,22 +1,27 @@ import path from 'path' import endsWith from 'lodash.endswith' +import has from 'has' +import assign from 'object-assign' import resolve from '../core/resolve' import { isBuiltIn } from '../core/importType' -const has = Object.prototype.hasOwnProperty; - module.exports = function (context) { const configuration = context.options[0] || 'never' const defaultConfig = typeof configuration === 'string' ? configuration : null - const modifiers = typeof configuration === 'object' ? configuration : context.options[1] || {} + const modifiers = assign( + {}, + typeof configuration === 'object' ? configuration : context.options[1] + ) function isUseOfExtensionRequired(extension) { - return (has.call(modifiers, extension) || defaultConfig) === 'always' + if (!has(modifiers, extension)) { modifiers[extension] = defaultConfig } + return modifiers[extension] === 'always' } function isUseOfExtensionForbidden(extension) { - return (has.call(modifiers, extension) || defaultConfig) === 'never' + if (!has(modifiers, extension)) { modifiers[extension] = defaultConfig } + return modifiers[extension] === 'never' } function isResolvableWithoutExtension(file) {