Socket
Socket
Sign inDemoInstall

eslint-plugin-import

Package Overview
Dependencies
Maintainers
1
Versions
130
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-import - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

files/nested-common.js

66

lib/getExports.js

@@ -6,2 +6,3 @@ "use strict";

Set = require("es6-set"),
traverse = require("estraverse").traverse,
parse = require("./parse"),

@@ -12,8 +13,15 @@ resolve = require("./resolve");

function getExports(path) {
function ExportMap() {
this.hasDefault = false;
this.named = new Set();
this.isCommon = false;
}
ExportMap.get = function (path) {
var exportMap = exportCache.get(path);
if (exportMap != null) return exportMap;
exportMap = ExportMap.forPath(path);
exportMap = ExportMap.parse(path);

@@ -26,13 +34,5 @@ exportCache.set(path, exportMap);

return exportMap;
};
function ExportMap() {
this.hasDefault = false
this.named = new Set();
this.isCommon = false;
}
ExportMap.forPath = function (path) {
ExportMap.parse = function (path) {
var m = new ExportMap();

@@ -48,3 +48,3 @@

return m;
}
};

@@ -55,3 +55,3 @@ ExportMap.prototype.captureDefault = function (n) {

this.hasDefault = true;
}
};

@@ -64,5 +64,5 @@ ExportMap.prototype.captureAll = function (n, path) {

var remoteMap = getExports(deepPath);
var remoteMap = ExportMap.get(deepPath);
remoteMap.named.forEach(function (name) { this.named.add(name); }.bind(this));
}
};

@@ -73,3 +73,3 @@ ExportMap.prototype.captureNamedDeclaration = function (n) {

// capture declaration
if (n.declaration != null){
if (n.declaration != null)
switch (n.declaration.type) {

@@ -85,3 +85,2 @@ case "FunctionDeclaration":

break;
}
}

@@ -93,23 +92,30 @@

}.bind(this));
}
};
// todo: capture names
ExportMap.prototype.commonJs = function (n) {
ExportMap.prototype.commonJs = function (node) {
if (this.isCommon) return;
if (n.type !== "ExpressionStatement") return;
var expr = n.expression;
var map = this;
if (expr.type !== "AssignmentExpression") return;
traverse(node, {
enter: function (n) {
if (n.type !== "ExpressionStatement") return;
var expr = n.expression;
if (expr.operator !== "=") return;
if (expr.left.type !== "MemberExpression") return;
if (expr.type !== "AssignmentExpression") return;
if (expr.left.object.type !== "Identifier") return;
if (expr.operator !== "=") return;
if (expr.left.type !== "MemberExpression") return;
if (expr.left.object.name === "module" || expr.left.object.name === "exports") {
this.isCommon = true;
}
}
if (expr.left.object.type !== "Identifier") return;
module.exports = getExports;
if (expr.left.object.name === "module" || expr.left.object.name === "exports") {
map.isCommon = true;
this.break();
}
}
});
};
module.exports = ExportMap.get;
{
"name": "eslint-plugin-import",
"version": "0.3.4",
"version": "0.3.5",
"description": "Import with sanity.",

@@ -46,4 +46,5 @@ "main": "index.js",

"espree": "^1.12.0",
"estraverse": "^3.1.0",
"resolve": "^1.1.6"
}
}

@@ -40,3 +40,3 @@ eslint-plugin-import

Report for imports that are defined as CommonJS modules, identified by the presence of `module.exports` or `exports[...]` assignments at the root scope of the module. Off by default.
Report for imports that are defined as CommonJS modules, identified by the presence of `module.exports` or `exports[...]` assignments within the module. Off by default.

@@ -43,0 +43,0 @@ ### `namespace`

@@ -21,4 +21,7 @@ "use strict";

test({code: "import { foobar } from './exports-calc-keys';",
errors: [{ message: "'./exports-calc-keys' is a CommonJS module."}]})
errors: [{ message: "'./exports-calc-keys' is a CommonJS module."}]}),
test({code: "import {x} from './nested-common';",
errors: [{ message: "'./nested-common' is a CommonJS module."}]})
]
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc