eslint-plugin-import
Advanced tools
Comparing version 0.3.0 to 0.3.2
"use strict"; | ||
var | ||
Map = require("es6-map"), | ||
Set = require("es6-set"), | ||
parse = require("./parse"); | ||
parse = require("./parse"), | ||
resolve = require("./resolve"); | ||
var exportCache = new Map(); | ||
function captureNamedDeclaration(n, names) { | ||
@@ -29,5 +33,8 @@ // capture declaration | ||
// TODO: recursive getExports for more names for ExportAllDeclaration | ||
module.exports = function getExports(path) { | ||
var exportMap = { | ||
var exportMap = exportCache.get(path); | ||
if (exportMap != null) { return exportMap; } | ||
exportMap = { | ||
hasDefault: false, | ||
@@ -46,7 +53,22 @@ named: new Set() | ||
break; | ||
case "ExportAllDeclaration": | ||
var deepPath = resolve(n.source.value, path); | ||
if (deepPath == null) { break; } | ||
var remoteMap = getExports(deepPath); | ||
remoteMap.named.forEach(function (name) { exportMap.named.add(name); }); | ||
break; | ||
} | ||
}); | ||
exportCache.set(path, exportMap); | ||
// Object.freeze(exportMap); | ||
// Object.freeze(exportMap.named); | ||
return exportMap; | ||
}; |
@@ -9,3 +9,3 @@ "use strict"; | ||
* resolve | ||
* @param {[type]} context [description] | ||
* @param {[type]} file [description] | ||
* @param {[type]} path [description] | ||
@@ -15,6 +15,6 @@ * @param {[type]} extensions [description] | ||
*/ | ||
module.exports = function (p, context) { | ||
module.exports = function (p, file) { | ||
try { | ||
return resolve.sync(p, { | ||
basedir: path.dirname(context.getFilename()) | ||
basedir: path.dirname(file) | ||
}); | ||
@@ -21,0 +21,0 @@ } catch (err) { |
@@ -12,3 +12,3 @@ "use strict"; | ||
"ImportDeclaration": function (node) { | ||
var path = resolve(node.source.value, context); | ||
var path = resolve(node.source.value, context.getFilename()); | ||
if (path == null) { | ||
@@ -15,0 +15,0 @@ return; |
@@ -13,3 +13,3 @@ /** | ||
"ImportDeclaration": function (node) { | ||
if (resolve(node.source.value, context) == null) { | ||
if (resolve(node.source.value, context.getFilename()) == null) { | ||
context.report(node.source, "Imported file does not exist."); | ||
@@ -16,0 +16,0 @@ } |
@@ -10,3 +10,3 @@ "use strict"; | ||
"ImportDeclaration": function (node) { | ||
var path = resolve(node.source.value, context); | ||
var path = resolve(node.source.value, context.getFilename()); | ||
if (path == null) { | ||
@@ -31,3 +31,3 @@ return; | ||
if (!names.has(im.imported.name)){ | ||
context.report(im.imported, "Name not found in module."); | ||
context.report(im.imported, im.imported.name + " not found in '" + node.source.value + "'"); | ||
} | ||
@@ -34,0 +34,0 @@ }); |
{ | ||
"name": "eslint-plugin-import", | ||
"version": "0.3.0", | ||
"version": "0.3.2", | ||
"description": "Import with sanity.", | ||
@@ -40,2 +40,3 @@ "main": "index.js", | ||
"array.prototype.find": "^1.0.0", | ||
"es6-map": "^0.1.1", | ||
"es6-set": "^0.1.1", | ||
@@ -42,0 +43,0 @@ "espree": "^1.12.0", |
@@ -12,87 +12,51 @@ "use strict"; | ||
var ecmaFeatures = {ecmaFeatures: { modules: true }}; | ||
var FILENAME = path.join(process.cwd(), "./files", "foo.js"); | ||
function test(t) { | ||
return assign({filename: FILENAME, ecmaFeatures: {modules: true}}, t); | ||
} | ||
function filename(f) { | ||
return path.join(process.cwd(), "./files", f); | ||
function error(name, module) { | ||
return { message: name + " not found in '" + module + "'", type: "Identifier" }; | ||
} | ||
var ERRORS = [{message: "Name not found in module.", type: "Identifier"}]; | ||
var FILENAME = filename("foo.js"); | ||
eslintTester.addRuleTest("lib/rules/named", { | ||
valid: [ | ||
assign({ | ||
code: "import { foo } from './bar';", | ||
filename: filename("foo.js") | ||
}, ecmaFeatures), | ||
assign({ | ||
code: "import bar from './bar.js';", | ||
settings: { "import/extensions": [".js"] }, | ||
filename: FILENAME | ||
}, ecmaFeatures), | ||
assign({ | ||
code: "import {a, b, d} from './named-exports';", | ||
filename: FILENAME | ||
}, ecmaFeatures), | ||
assign({ | ||
code: "import {ExportedClass} from './named-exports';", | ||
filename: FILENAME | ||
}, ecmaFeatures), | ||
assign({ | ||
code: "import {a, b, d} from './common';", | ||
filename: FILENAME | ||
}, ecmaFeatures), | ||
assign({ | ||
code: "import { ActionTypes } from './qc';", | ||
filename: FILENAME | ||
}, ecmaFeatures) | ||
test({code: "import { foo } from './bar';"}), | ||
test({code: "import bar from './bar.js';"}), | ||
test({code: "import {a, b, d} from './named-exports';"}), | ||
test({code: "import {ExportedClass} from './named-exports';"}), | ||
test({code: "import {a, b, d} from './common';"}), | ||
test({code: "import { ActionTypes } from './qc';"}), | ||
test({code: "import {a, b, c, d} from './re-export';"}), | ||
test({code: "import {foo, bar} from './re-export-names';", args: [2, "es6-only"]}) | ||
], | ||
invalid: [ | ||
// assign({ | ||
// code: "import foo from './bar';", | ||
// filename: filename("foo.js"), | ||
// errors: ERRORS | ||
// }, ecmaFeatures), | ||
assign({ | ||
code: "import { baz } from './bar';", | ||
filename: filename("foo.js"), | ||
errors: ERRORS | ||
}, ecmaFeatures), | ||
test({code: "import { baz } from './bar';", | ||
errors: [error("baz", "./bar")]}), | ||
// test multiple | ||
assign({ | ||
code: "import { baz, bop } from './bar';", | ||
filename: filename("foo.js"), | ||
errors: ERRORS.concat(ERRORS) | ||
}, ecmaFeatures), | ||
test({code: "import { baz, bop } from './bar';", | ||
errors: [error("baz", "./bar"), error("bop", "./bar")]}), | ||
assign({ | ||
code: "import {a, b, c} from './named-exports';", | ||
filename: FILENAME, | ||
errors: ERRORS | ||
}, ecmaFeatures), | ||
test({code: "import {a, b, c} from './named-exports';", | ||
errors: [error("c", "./named-exports")]}), | ||
assign({ | ||
code: "import { a } from './default-export';", | ||
filename: FILENAME, | ||
errors: ERRORS | ||
}, ecmaFeatures), | ||
test({code: "import { a } from './default-export';", | ||
errors: [error("a", "./default-export")]}), | ||
assign({ | ||
code: "import { a } from './common';", | ||
test({code: "import { a } from './common';", args: [2, "es6-only"], | ||
errors: [error("a", "./common")]}), | ||
test({code: "import { ActionTypess } from './qc';", | ||
errors: [error("ActionTypess", "./qc")]}), | ||
test({code: "import {a, b, c, d, e} from './re-export';", | ||
errors: [error("e", "./re-export")]}), | ||
test({code: "import { a } from './re-export-names';", | ||
args: [2, "es6-only"], | ||
filename: FILENAME, | ||
errors: ERRORS | ||
}, ecmaFeatures), | ||
assign({ | ||
code: "import { ActionTypess } from './qc';", | ||
filename: FILENAME, | ||
errors: ERRORS | ||
}, ecmaFeatures) | ||
errors: [error("a", "./re-export-names")]}) | ||
] | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16187
29
6
379
+ Addedes6-map@^0.1.1
+ Addedes6-map@0.1.5(transitive)