Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-import

Package Overview
Dependencies
Maintainers
1
Versions
131
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.7.8 to 0.7.9

lib/rules/imports-first.js

35

lib/core/getExports.js

@@ -61,3 +61,3 @@ 'use strict';

m.captureAll(n, path);
m.captureNamedDeclaration(n);
m.captureNamedDeclaration(n, path);
});

@@ -68,2 +68,9 @@

ExportMap.prototype.resolveReExport = function (node, base) {
var remotePath = resolve.relative(node.source.value, base, this.settings);
if (remotePath == null) return null;
return ExportMap['for'](remotePath, this.settings);
};
ExportMap.prototype.captureDefault = function (n) {

@@ -89,7 +96,5 @@ if (n.type !== 'ExportDefaultDeclaration') return;

var remotePath = resolve.relative(n.source.value, path, this.settings);
if (remotePath == null) return false;
var remoteMap = this.resolveReExport(n, path);
if (remoteMap == null) return false;
var remoteMap = ExportMap['for'](remotePath, this.settings);
remoteMap.named.forEach((function (name) {

@@ -102,3 +107,3 @@ this.named.add(name);

ExportMap.prototype.captureNamedDeclaration = function (n) {
ExportMap.prototype.captureNamedDeclaration = function (n, path) {
if (n.type !== 'ExportNamedDeclaration') return;

@@ -122,4 +127,20 @@

// capture specifiers
var remoteMap = undefined;
if (n.source) remoteMap = this.resolveReExport(n, path);
n.specifiers.forEach((function (s) {
this.named.add(s.exported.name);
if (s.type === 'ExportDefaultSpecifier') {
// don't add it if it is not present in the exported module
if (!remoteMap || !remoteMap.hasDefault) return;
if (s.exported.name === 'default') {
// export default from "..."
this.hasDefault = true;
} else {
// export bar from "..."
this.named.add(s.exported.name);
}
} else {
this.named.add(s.exported.name);
}
}).bind(this));

@@ -126,0 +147,0 @@ };

54

lib/core/resolve.js

@@ -5,2 +5,4 @@ 'use strict';

var _getIterator = require('babel-runtime/core-js/get-iterator')['default'];
var fs = require('fs'),

@@ -56,16 +58,50 @@ path = require('path'),

module.exports = function (p, context) {
// resolve just returns the core module id, which won't appear to exist
if (resolve.isCore(p)) return p;
function withResolver(resolver) {
// resolve just returns the core module id, which won't appear to exist
if (resolver.isCore(p)) return p;
try {
var file = resolver.sync(p, opts(path.dirname(context.getFilename()), context.settings));
if (!fileExists(file)) return null;
return file;
} catch (err) {
// probably want something more general here
if (err.message.indexOf('Cannot find module') === 0) {
return null;
}
throw err;
}
}
var resolvers = (context.settings['import/resolvers'] || ['resolve']).map(require);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
var file = resolve.sync(p, opts(path.dirname(context.getFilename()), context.settings));
if (!fileExists(file)) return null;
return file;
for (var _iterator = _getIterator(resolvers), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var resolver = _step.value;
var file = withResolver(resolver);
if (file) return file;
}
} catch (err) {
if (err.message.indexOf('Cannot find module') === 0) {
return null;
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator['return']) {
_iterator['return']();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
throw err;
}
return null;
};

@@ -72,0 +108,0 @@

@@ -18,2 +18,5 @@ 'use strict';

'no-duplicates': require('./rules/no-duplicates'),
'imports-first': require('./rules/imports-first'),
// removed

@@ -36,2 +39,7 @@ 'no-reassign': function noReassign() {

// warnings
'no-duplicates': 1,
// optional
'imports-first': 0,
'no-errors': 0,

@@ -38,0 +46,0 @@ 'no-require': 0,

{
"name": "eslint-plugin-import",
"version": "0.7.8",
"version": "0.7.9",
"description": "Import with sanity.",

@@ -12,6 +12,6 @@ "main": "lib/index.js",

"cover": "eslint ./src && istanbul cover --dir reports/coverage _mocha tests/src/ -- --recursive --reporter dot --compilers js:babel/register",
"test": "mocha --timeout 5000 --recursive --reporter dot --compilers js:babel/register tests/src/",
"test": "mocha --recursive --reporter dot tests/lib/",
"compile": "babel -d lib/ src/",
"prepublish": "npm run compile",
"pretest": "eslint ./src"
"pretest": "eslint ./src && npm run compile && babel -d tests/lib/ tests/src/"
},

@@ -18,0 +18,0 @@ "repository": {

@@ -20,2 +20,4 @@ eslint-plugin-import

* Report any invalid exports, i.e. re-export of the same name ([`export`](#export))
* Report repeated import of the same module in multiple places ([`no-duplicates`](#no-duplicates), warning by default)
* Ensure all imports appear before other statements ([`imports-first`](#imports-first), off by default)

@@ -138,3 +140,5 @@ ## Installation

In the case of named/default re-export, all `n` re-exports will be reported,
as at least `n-1` of them are clearly mistakes, but it is not clear which one (if any) is intended. Could be the result of copy/paste, code duplication with intent to rename, etc.
as at least `n-1` of them are clearly mistakes, but it is not clear which one
(if any) is intended. Could be the result of copy/paste, code duplication with
intent to rename, etc.

@@ -145,2 +149,56 @@

### `no-duplicates`
Reports if a resolved path is imported more than once.
Valid:
```js
import SomeDefaultClass, * as names from './mod'
```
...whereas here, both `./mod` imports will be reported:
```js
import SomeDefaultClass from './mod'
// oops, some other import separated these lines
import foo from './some-other-mod'
import * as names from './mod'
```
The motivation is that this is likely a result of two developers importing different
names from the same module at different times (and potentially largely different
locations in the file.) This rule brings both (or n-many) to attention.
This rule is only set to a warning, by default.
### `imports-first`
By popular demand, this rule reports any imports that come after non-import
statments:
```js
import foo from './foo'
// some module-level initializer
initWith(foo)
import bar from './bar' // <- reported
```
Providing `absolute-first` as an option will report any absolute imports (i.e.
packages) that come after any relative imports:
```js
import foo from 'foo'
import bar from './bar'
import * as _ from 'lodash' // <- reported
```
This rule is disabled by default.
## Settings

@@ -147,0 +205,0 @@

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