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.2 to 0.3.3

files/common-module.js

2

files/common.js

@@ -8,2 +8,2 @@ module.exports = {

exports.d = c;
exports.d = c;
exports.rules = {
"exists": require("./lib/rules/exists"),
"named": require("./lib/rules/named"),
"default": require("./lib/rules/default")
"default": require("./lib/rules/default"),
"no-common": require("./lib/rules/no-common")
};

@@ -10,3 +11,5 @@

"named": 2,
"default": 2
"default": 2,
"no-common": 0
};

@@ -11,3 +11,57 @@ "use strict";

function captureNamedDeclaration(n, names) {
function getExports(path) {
var exportMap = exportCache.get(path);
if (exportMap != null) return exportMap;
exportMap = ExportMap.forPath(path);
exportCache.set(path, exportMap);
// Object.freeze(exportMap);
// Object.freeze(exportMap.named);
return exportMap;
};
function ExportMap() {
this.hasDefault = false
this.named = new Set();
this.isCommon = false;
}
ExportMap.forPath = function (path) {
var m = new ExportMap();
parse(path).body.forEach(function (n) {
m.captureDefault(n);
m.captureAll(n, path);
m.captureNamedDeclaration(n);
m.commonJs(n);
});
return m;
}
ExportMap.prototype.captureDefault = function (n) {
if (n.type !== "ExportDefaultDeclaration") return;
this.hasDefault = true;
}
ExportMap.prototype.captureAll = function (n, path) {
if (n.type !== "ExportAllDeclaration") return;
var deepPath = resolve(n.source.value, path);
if (deepPath == null) return;
var remoteMap = getExports(deepPath);
remoteMap.named.forEach(function (name) { this.named.add(name); }.bind(this));
}
ExportMap.prototype.captureNamedDeclaration = function (n) {
if (n.type !== "ExportNamedDeclaration") return;
// capture declaration

@@ -18,8 +72,8 @@ if (n.declaration != null){

case "ClassDeclaration":
names.add(n.declaration.id.name);
this.named.add(n.declaration.id.name);
break;
case "VariableDeclaration":
n.declaration.declarations.forEach(function (d) {
names.add(d.id.name);
});
this.named.add(d.id.name);
}.bind(this));
break;

@@ -31,45 +85,25 @@ }

n.specifiers.forEach(function (s) {
names.add(s.exported.name);
});
this.named.add(s.exported.name);
}.bind(this));
}
module.exports = function getExports(path) {
// todo: capture names
ExportMap.prototype.commonJs = function (n) {
if (this.isCommon) return;
var exportMap = exportCache.get(path);
if (exportMap != null) { return exportMap; }
if (n.type !== "ExpressionStatement") return;
var expr = n.expression;
exportMap = {
hasDefault: false,
named: new Set()
};
if (expr.type !== "AssignmentExpression") return;
parse(path).body.forEach(function (n) {
switch (n.type) {
case "ExportNamedDeclaration":
captureNamedDeclaration(n, exportMap.named);
break;
if (expr.operator !== "=") return;
if (expr.left.type !== "MemberExpression") return;
case "ExportDefaultDeclaration":
exportMap.hasDefault = true;
break;
if (expr.left.object.type !== "Identifier") return;
case "ExportAllDeclaration":
var deepPath = resolve(n.source.value, path);
if (deepPath == null) { break; }
if (expr.left.object.name === "module" || expr.left.object.name === "exports") {
this.isCommon = true;
}
}
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;
};
module.exports = getExports;
{
"name": "eslint-plugin-import",
"version": "0.3.2",
"version": "0.3.3",
"description": "Import with sanity.",

@@ -5,0 +5,0 @@ "main": "index.js",

eslint-plugin-import
---
![build status](https://travis-ci.org/benmosher/eslint-plugin-import.svg)
[![build status](https://travis-ci.org/benmosher/eslint-plugin-import.svg)](https://travis-ci.org/benmosher/eslint-plugin-import)
[![npm](https://img.shields.io/npm/v/eslint-plugin-import.svg)](https://www.npmjs.com/package/eslint-plugin-import)

@@ -16,5 +17,3 @@ This plugin intends to support linting of ES6 import syntax, and prevent issues with misspelling of file paths and import names. All the goodness that the ES6 static module syntax intends to provide, marked up in your editor.

* Validate that namespace (`*`) imports exist as named exports in remote file, when dereferenced.
* Currently, will spuriously report on named imports that are the result of re-exporting from a third file (`export * from "./baz"`).
## Rules

@@ -41,1 +40,5 @@

Provide the `es6-only` option in your rule config if you would like to enforce this on all imports.
### `no-common`
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.

Sorry, the diff of this file is not supported yet

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