Skip to content

Commit

Permalink
Cache extension settings using has.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Sep 16, 2016
1 parent ff49b83 commit a0bb733
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion resolvers/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/rules/extensions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path'
import endsWith from 'lodash.endswith'
import has from 'has'

import resolve from '../core/resolve'
import { isBuiltIn } from '../core/importType'
Expand All @@ -10,11 +11,13 @@ module.exports = function (context) {
const modifiers = 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) {
Expand Down

0 comments on commit a0bb733

Please sign in to comment.