Skip to content

Commit

Permalink
import/env: provides a fix for the no-unresolved bit of #275
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Jun 3, 2016
1 parent 21cec5a commit 1441ece
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ function fileExistsWithCaseSync(filepath, cacheSettings) {
}

export function relative(modulePath, sourceFile, settings) {
// check if this is a bonus core module
const envCore = envCores.get(settings['import/env'])
if (envCore != null && envCore.has(modulePath)) return { path: null, found: true }

const sourceDir = dirname(sourceFile)
, cacheKey = sourceDir + hashObject(settings) + modulePath

Expand Down Expand Up @@ -210,3 +214,7 @@ function hashObject(object) {
settingsShasum.update(JSON.stringify(object))
return settingsShasum.digest('hex')
}

const envCores = new Map([
['electron', new Set(['electron'])],
])
15 changes: 15 additions & 0 deletions tests/src/rules/no-unresolved.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,18 @@ ruleTester.run('no-unresolved unknown resolver', rule, {
}),
],
})

ruleTester.run('no-unresolved electron', rule, {
valid: [
test({
code: 'import "electron"',
settings: { 'import/env': 'electron' },
}),
],
invalid:[
test({
code: 'import "electron"',
errors: [`Unable to resolve path to module 'electron'.`],
}),
],
})

0 comments on commit 1441ece

Please sign in to comment.