From bea057689f8645dfb38b0ebbae7ed01bd3cb7644 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 | 10 +++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index d49f36cb38..0d02e57bdd 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 d463695a03..535ebf2b7d 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 23f878e824..f8717bc41e 100644 --- a/src/rules/extensions.js +++ b/src/rules/extensions.js @@ -1,5 +1,7 @@ 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' @@ -7,14 +9,16 @@ import { isBuiltIn } from '../core/importType' 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 (modifiers[extension] || defaultConfig) === 'always' + if (!has(modifiers, extension)) { modifiers[extension] = defaultConfig } + return modifiers[extension] === 'always' } function isUseOfExtensionForbidden(extension) { - return (modifiers[extension] || defaultConfig) === 'never' + if (!has(modifiers, extension)) { modifiers[extension] = defaultConfig } + return modifiers[extension] === 'never' } function isResolvableWithoutExtension(file) {