Skip to content

Commit

Permalink
Breaking change: implicit es6-only for all rules. (closes #20)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Apr 1, 2015
1 parent c2cb833 commit 5ba3d8c
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 99 deletions.
35 changes: 1 addition & 34 deletions lib/getExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var
Map = require("es6-map"),
Set = require("es6-set"),
traverse = require("estraverse").traverse,
parse = require("./parse"),
resolve = require("./resolve"),
isCore = require("resolve").isCore;
Expand All @@ -16,7 +15,6 @@ function ExportMap(context) {
this.hasDefault = false;
this.named = new Set();

this.isCommon = false;
this.errors = [];
}

Expand All @@ -41,11 +39,7 @@ ExportMap.get = function (source, context) {
ExportMap.parse = function (path, context) {
var m = new ExportMap(context);

if (isCore(path)) {
// skip parsing, mark as common
m.isCommon = true;
return m;
}
if (isCore(path)) return m; // skip parsing

try {
var ast = parse(path);
Expand All @@ -60,8 +54,6 @@ ExportMap.parse = function (path, context) {
m.captureNamedDeclaration(n);
});

m.commonJs(ast);

return m;
};

Expand Down Expand Up @@ -101,29 +93,4 @@ ExportMap.prototype.captureNamedDeclaration = function (n) {
}.bind(this));
};

// todo: capture names
ExportMap.prototype.commonJs = function (ast) {
var map = this;
try {
traverse(ast, {
fallback: "iteration",
enter: function (n) {
if (n.type !== "AssignmentExpression") return;

if (n.operator !== "=") return;
if (n.left.type !== "MemberExpression") return;

if (n.left.object.type !== "Identifier") return;

if (n.left.object.name === "module" || n.left.object.name === "exports") {
map.isCommon = true;
this.break();
}
}
});
} catch (err) {
this.errors.push(err);
}
};

module.exports = ExportMap.get;
3 changes: 0 additions & 3 deletions lib/rules/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ module.exports = function (context) {
var imports = getExports(node.source.value, context);
if (imports == null) return;

if (imports.named.size === 0 && context.options[0] !== "es6-only")
return; // ignore for commonjs compatibility

if (!imports.hasDefault)
context.report(defaultSpecifier, "No default export found in module.");
}
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/named.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ module.exports = function (context) {

var names = imports.named;

// if there are no exports, may be a commonjs module.
// TODO: "interop" mode that attempts to read module.exports, exports member assignments?
if (names.size === 0 && !imports.hasDefault && context.options[0] !== "es6-only")
return;

node.specifiers.forEach(function (im) {
if (im.type !== "ImportSpecifier") return;

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function (context) {
var declaration = importDeclaration(context);

var imports = getExports(declaration.source.value, context);
if (imports == null || imports.isCommon) return;
if (imports == null) return;

if (imports.named.size === 0)
context.report(namespace,
Expand Down
16 changes: 0 additions & 16 deletions lib/rules/no-common.js

This file was deleted.

9 changes: 4 additions & 5 deletions tests/lib/rules/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var test = require("../../utils").test;

eslintTester.addRuleTest("lib/rules/default", {
valid: [
test({code: "import crypto from 'crypto';"}),
test({code: "import foo from './empty-folder';"}),
test({code: "import { foo } from './default-export';"}),
test({code: "import foo from './default-export';"}),
Expand All @@ -19,19 +18,19 @@ eslintTester.addRuleTest("lib/rules/default", {
test({
code: "import CoolClass from './default-class';"}),
test({
code: "import bar, { baz } from './default-export';"}),
test({
code: "import bar from './common';"})
code: "import bar, { baz } from './default-export';"})
],

invalid: [
test({
code: "import crypto from 'crypto';",
errors: [{message: "No default export found in module.", type: "ImportDefaultSpecifier"}]}),
test({
code: "import baz from './named-exports';",
errors: [{message: "No default export found in module.", type: "ImportDefaultSpecifier"}]}),

test({
code: "import bar from './common';",
args: [2, "es6-only"],
errors: [{message: "No default export found in module.", type: "ImportDefaultSpecifier"}]})
]
});
5 changes: 4 additions & 1 deletion tests/lib/rules/named.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ eslintTester.addRuleTest("lib/rules/named", {
test({code: "import { foo } from './bar';"}),
test({code: "import { foo } from './empty-module';"}),
test({code: "import bar from './bar.js';"}),
test({code: "import bar, { foo } 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: [
test({code: "import {a, b, d} from './common';",
errors: [error("a", "./common"), error("b", "./common"), error("d", "./common")]}),

test({code: "import { baz } from './bar';",
errors: [error("baz", "./bar")]}),

Expand Down
3 changes: 2 additions & 1 deletion tests/lib/rules/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function error(name, namespace) {
eslintTester.addRuleTest("lib/rules/namespace", {
valid: [
test({code: "import * as foo from './empty-folder';"}),
test({code: "import * as foo from './common';"}),
test({code: "import * as names from './named-exports'; console.log((names.b).c); "}),

test({code: "import * as names from './named-exports'; console.log(names.a); "}),
Expand All @@ -24,6 +23,8 @@ eslintTester.addRuleTest("lib/rules/namespace", {
],

invalid: [
test({code: "import * as foo from './common';",
errors: ["No exported names found in module './common'."]}),
test({code: "import * as names from './default-export';",
errors: ["No exported names found in module './default-export'."]}),

Expand Down
33 changes: 0 additions & 33 deletions tests/lib/rules/no-common.js

This file was deleted.

0 comments on commit 5ba3d8c

Please sign in to comment.