Socket
Book a DemoInstallSign in
Socket

eslint-plugin-import-srclimits

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-import-srclimits

Limit import source from some special folder in configuration

1.0.1
latest
npmnpm
Version published
Weekly downloads
11
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-import-srclimits

stable_version >= 1.0.0

Limit import source from some special folder in configuration

version  Build Status  GitHub issues  license

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-import-srclimits:

$ npm install eslint-plugin-import-srclimits --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-import-srclimits globally.

Usage

Add import-srclimit to the plugins section of your .eslintrc.js configuration file. You can omit the eslint-plugin- prefix:

Set parserOptions.sourceType value as module in your configuration.

module.exports = {
    // ...
    "plugins": [
        "import-srclimits"
    ],
    "parserOptions": { 
        "ecmaVersion": 2015, 
        "sourceType": "module" 
    }
    // ...
};

Then configure the rules you want to use under the rules section.

The effect is: The files match in files pattern, can only import target match in source pattern

module.exports = {
  // ...
  "rules": {
    "import-srclimits/srclimits": [
      "error", 
      {
        "files": ["./src/**/*.{js,vue,jsx}"],
        "source": ["./src/**/*.*", "node_modules/**", "!./mock/**/*.*"], 
        "errMsg": "The code of the files in the src folder, can't import source file in ./mock/**"
      }
    ]
  }
  // ...
};

option files & source can accepts glob-pattern, regular-expression, function(str){/* return fasle|true; */}

module.exports = {
  // ...
  "rules": {
    "import-srclimits/srclimits": [
      "warn", 
      {
        "files": ["./src/**/*.{js,vue,jsx}"],
        "source": [
          (str) => (str.indexOf('util') == -1),
          /os/g
        ], 
        "errMsg": "Browser code could not use node module 'util' & 'os'!!!"
      }
    ]
  }
  // ...
};

see more: anymatch

Test

srclimits
    valid
      ✓ import qs from 'qs'; (48ms)
      ✓ import abc from 'qs/abc';
      ✓ import kapp from '@scopename/kapp';
      ✓ import abc from '@scopename/bbb/abc';
      ✓ import clone from '../utils/clone.js';
      ✓ import '../utils/clone.js';
      ✓ import '../utils/clone';
      ✓ import { clone } from '../utils/index.js';
      ✓ import { clone } from '../utils/';
      ✓ import { clone } from '../utils';
      ✓ import { clone as copy } from '../utils';
      ✓ import * as _ from '../utils/index.js';
    invalid
      ✓ import '../../mock/storage.js';
      ✓ import '../../mock/storage';
      ✓ import storage from '../../mock/storage.js';
      ✓ import storage from '../../mock/storage';
      ✓ import '../../mock/utils';
      ✓ import '../../mock/utils/';
      ✓ import * as _ from '../../mock/utils/index.js';
      ✓ import { addStyleTag } from '../../mock/utils/';
      ✓ import { addStyleTag as injectStyleDom } from '../../mock/utils/index';
      ✓ // multiple lines
        import { clone } from '../utils/';    // ✓
        import { base } from '../base/index'; // ✓
        import { addStyleTag as injectStyleDom } from '../../mock/utils/index'; // ✘
22 passing

Others

Created by yeoman tool.

Keywords

eslint

FAQs

Package last updated on 20 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.