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 21, 2016
1 parent 8141713 commit 8db2440
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ 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 = path.dirname(sourceFile)
, cacheKey = sourceDir + hashObject(settings) + modulePath
Expand Down Expand Up @@ -202,3 +205,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 8db2440

Please sign in to comment.