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

eslint-plugin-import-helpers

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-import-helpers - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

4

lib/util/import-type.js
const cond = require('lodash/cond');
const coreModules = require('resolve/lib/core');
const coreModules = require('builtin-modules/static');
const { join } = require('path');

@@ -27,3 +27,3 @@

const extras = settings && settings['import/core-modules'] || [];
return coreModules[base] || extras.indexOf(base) > -1;
return coreModules.indexOf(base) > -1 || extras.indexOf(base) > -1;
}

@@ -30,0 +30,0 @@

{
"name": "eslint-plugin-import-helpers",
"version": "0.1.3",
"version": "0.1.4",
"description": "ESLint Rules to Aid with Imports",

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

"eslint",
"import"
"import",
"eslint-plugin-import",
"configurable"
],

@@ -15,0 +17,0 @@ "repository": {

@@ -9,4 +9,38 @@ # eslint-plugin-import-helpers

- enforce a _configurable_ convention in module import order ([`order-imports`])
#### [`order-imports`]
Enforce a _configurable_ convention in module import order
```javascript
// Given ESLint Config
rules: {
'import-helpers/order-imports': [
'warn',
{
'newlines-between': 'always', // new line between groups
groups: [
['builtin', 'external', 'internal'],
'/^@shared/',
['parent', 'sibling', 'index'],
],
alphabetize: { order: 'asc', ignoreCase: true },
},
],
}
// will fix
import SiblingComponent from './SiblingComponent';
import lodash from 'lodash';
import SharedComponent from '@shared/components/SharedComponent';
import React from 'react';
// into
import lodash from 'lodash';
import React from 'react';
import SharedComponent from '@shared/components/SharedComponent';
import SiblingComponent from './SiblingComponent';
```
[`order-imports`]: ./docs/rules/order-imports.md

@@ -27,13 +61,23 @@

All rules are off by default. However, you may configure them manually
in your `.eslintrc.(yml|json|js)`, or extend one of the canned configs:
To add a rule, update your `.eslintrc.(yml|json|js)`:
```yaml
---
plugins:
- import-helpers
rules:
import-helpers/order-imports: [2]
# etc...
```js
{
// .eslintrc.js
plugins: ['eslint-plugin-import-helpers'],
rules: {
'import-helpers/order-imports': [
'warn',
{ // example configuration
'newlines-between': 'always',
groups: [
['builtin', 'external', 'internal'],
'/^@shared/',
['parent', 'sibling', 'index'],
],
alphabetize: { order: 'asc', ignoreCase: true },
},
],
}
}
```

@@ -47,6 +91,4 @@

An array of additional modules to consider as "core" modules--modules that should
be considered resolved but have no path on the filesystem (ie `builtins`). Your resolver may
already define some of these (for example, the Node resolver knows about `fs` and
`path`), so you need not redefine those.
An array of additional modules to consider as core/builtin modules--modules that should
be considered resolved but have no path on the filesystem. Currently, we are using the [builtin-modules](https://github.com/sindresorhus/builtin-modules), which knows about `fs`, `path`, and more), so you need not redefine those.

@@ -56,3 +98,3 @@ For example, Electron exposes an `electron` module:

```js
import 'electron'; // without extra config, will be flagged as unresolved!
import 'electron'; // without extra config, will be flagged as an "internal" module
```

@@ -63,6 +105,11 @@

```yaml
# .eslintrc.yml
settings:
import/core-modules: [electron]
```js
{
// .eslintrc.js
settings: {
'core-modules': ['electron']
},
plugins: [ ... ],
rules: { ... }
}
```

@@ -73,1 +120,5 @@

An array of folders. Resolved modules only from those folders will be considered as "external". By default - `["node_modules"]`. Makes sense if you have configured your path or webpack to handle your internal paths differently and want to considered modules from some folders, for example `bower_components` or `jspm_modules`, as "external".
# TypeScript
To use this plugin with TypeScript, you must use the TypeScript parser for ESLint. See [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser) for more details.
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