From 8db2440b371414156e0191e71edcebbfd5d86c71 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Fri, 3 Jun 2016 07:23:41 -0400 Subject: [PATCH] import/env: provides a fix for the no-unresolved bit of #275 --- src/core/resolve.js | 7 +++++++ tests/src/rules/no-unresolved.js | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/core/resolve.js b/src/core/resolve.js index 1eab64eaf..f4095d525 100644 --- a/src/core/resolve.js +++ b/src/core/resolve.js @@ -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 @@ -202,3 +205,7 @@ function hashObject(object) { settingsShasum.update(JSON.stringify(object)) return settingsShasum.digest('hex') } + +const envCores = new Map([ + ['electron', new Set(['electron'])], +]) diff --git a/tests/src/rules/no-unresolved.js b/tests/src/rules/no-unresolved.js index d6e44ec94..fd59a1825 100644 --- a/tests/src/rules/no-unresolved.js +++ b/tests/src/rules/no-unresolved.js @@ -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'.`], + }), + ], +})