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 0dc0af9 commit 80cd6ac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 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
13 changes: 10 additions & 3 deletions src/rules/extensions.js
Original file line number Diff line number Diff line change
@@ -1,20 +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'

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

0 comments on commit 80cd6ac

Please sign in to comment.