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) {