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.3 to 0.3.4

files/exports-calc-keys.js

3

index.js

@@ -5,2 +5,4 @@ exports.rules = {

"default": require("./lib/rules/default"),
"namespace": require("./lib/rules/namespace"),
"no-common": require("./lib/rules/no-common")

@@ -12,2 +14,3 @@ };

"named": 2,
"namespace": 2,
"default": 2,

@@ -14,0 +17,0 @@

"use strict";
var
Map = require("es6-map"),
resolve = require("../resolve"),
getExports = require("../getExports");
function importDeclaration(context) {
var ancestors = context.getAncestors();
return ancestors[ancestors.length - 1];
}
module.exports = function (context) {
var namespaces = new Map();
return {
"ImportDeclaration": function (node) {
var path = resolve(node.source.value, context);
if (path == null) {
"ImportNamespaceSpecifier": function (namespace) {
var declaration = importDeclaration(context);
var path = resolve(declaration.source.value, context.getFilename());
if (path == null) return;
var imports = getExports(path);
if (imports.isCommon) return;
if (imports.named.size === 0) context.report(namespace,
"No exported names found in module '" + declaration.source.value + "'.");
namespaces.set(namespace.local.name, imports.named);
},
// todo: check for possible redefinition
"MemberExpression": function (dereference) {
if (dereference.object.type !== "Identifier") return;
if (!namespaces.has(dereference.object.name)) return;
if (dereference.computed) {
context.report(dereference.property,
"Unable to validate computed reference to imported namespace '" + dereference.object.name + "'.");
return;
}
var namespace = namespaces.get(dereference.object.name);
if (!namespace.has(dereference.property.name)) context.report(dereference.property,
"'" + dereference.property.name + "' not found in imported namespace " + dereference.object.name + ".");
}
}
}
};
};

7

package.json
{
"name": "eslint-plugin-import",
"version": "0.3.3",
"version": "0.3.4",
"description": "Import with sanity.",

@@ -20,3 +20,6 @@ "main": "index.js",

"es6",
"jsnext"
"jsnext",
"modules",
"import",
"export"
],

@@ -23,0 +26,0 @@ "author": "Ben Mosher (me@benmosher.com)",

@@ -13,7 +13,5 @@ eslint-plugin-import

* Ensure a default export is present, given a default import. ([`default`](#default))
* Report ES6 import of CommonJS modules. ([`no-common`](#no-common))
* Ensure imported namespaces contain dereferenced properties as they are dereferenced. ([`namespace`](#namespace))
**Planned**:
* Validate that namespace (`*`) imports exist as named exports in remote file, when dereferenced.
## Rules

@@ -44,1 +42,14 @@

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.
### `namespace`
Enforces names exist at the time they are dereferenced, when imported as a full namespace (i.e. `import * as foo from './foo'; foo.bar();` will report if `bar` is not exported by `./foo`.).
If remote module is CommonJS, will not attempt to enforce.
Will report at the import declaration if there are _no_ exported names found.
Also, will report for computed references (i.e. `foo["bar"]()`).
**Implementation note**: currently, this rule does not check for possible redefinition of the namespace in an intermediate scope. Adherence to the ESLint `no-shadow` rule for namespaces will prevent this from being a problem.
"use strict";
var assign = require("object-assign");
var path = require("path");
var linter = require("eslint").linter,

@@ -11,8 +8,4 @@ ESLintTester = require("eslint-tester");

var test = require("../../utils").test;
var FILENAME = path.join(process.cwd(), "./files", "foo.js");
function test(t) {
return assign({filename: FILENAME, ecmaFeatures: {modules: true}}, t);
}
function error(name, module) {

@@ -19,0 +12,0 @@ return { message: name + " not found in '" + module + "'", type: "Identifier" };

@@ -19,4 +19,6 @@ "use strict";

test({code: "import { a } from './export-props';",
errors: [{ message: "'./export-props' is a CommonJS module."}]})
errors: [{ message: "'./export-props' is a CommonJS module."}]}),
test({code: "import { foobar } from './exports-calc-keys';",
errors: [{ message: "'./exports-calc-keys' is a CommonJS module."}]})
]
});

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