Skip to content

Commit f507ff3

Browse files
committed
Cache extension settings using has.
1 parent daf38ac commit f507ff3

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"es6-map": "^0.1.3",
7878
"es6-set": "^0.1.4",
7979
"eslint-import-resolver-node": "^0.2.0",
80+
"has": "^1.0.1",
8081
"lodash.cond": "^4.3.0",
8182
"lodash.endswith": "^4.0.1",
8283
"lodash.find": "^4.3.0",

resolvers/webpack/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var findRoot = require('find-root')
1010
, assign = require('object-assign')
1111
, resolve = require('resolve')
1212
, semver = require('semver')
13+
, has = require('has')
1314

1415
var log = require('debug')('eslint-plugin-import:resolver:webpack')
1516

@@ -265,7 +266,7 @@ function findExternal(source, externals, context) {
265266

266267
// else, vanilla object
267268
for (var key in externals) {
268-
if (!externals.hasOwnProperty(key)) continue
269+
if (!has(externals, key)) continue
269270
if (source === key) return true
270271
}
271272
return false

src/rules/extensions.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
import path from 'path'
22
import endsWith from 'lodash.endswith'
3+
import has from 'has'
4+
import assign from 'object-assign'
35

46
import resolve from '../core/resolve'
57
import { isBuiltIn } from '../core/importType'
68

7-
const has = Object.prototype.hasOwnProperty;
8-
99
module.exports = function (context) {
1010
const configuration = context.options[0] || 'never'
1111
const defaultConfig = typeof configuration === 'string' ? configuration : null
12-
const modifiers = typeof configuration === 'object' ? configuration : context.options[1] || {}
12+
const modifiers = assign(
13+
{},
14+
typeof configuration === 'object' ? configuration : context.options[1]
15+
)
1316

1417
function isUseOfExtensionRequired(extension) {
15-
return (has.call(modifiers, extension) || defaultConfig) === 'always'
18+
if (!has(modifiers, extension)) { modifiers[extension] = defaultConfig }
19+
return modifiers[extension] === 'always'
1620
}
1721

1822
function isUseOfExtensionForbidden(extension) {
19-
return (has.call(modifiers, extension) || defaultConfig) === 'never'
23+
if (!has(modifiers, extension)) { modifiers[extension] = defaultConfig }
24+
return modifiers[extension] === 'never'
2025
}
2126

2227
function isResolvableWithoutExtension(file) {

0 commit comments

Comments
 (0)