question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add the "lean bundle" use-case no-restricted-imports

See original GitHub issue

From discussions with @ljharb in https://github.com/benmosher/eslint-plugin-import/issues/642 I realised that what I wanted to add in eslint-plugin-import is actually already supported by no-restricted-imports and no-restricted-modules. It just wasn’t a very obvious use case in the documentation.

Let me explain a bit what the use case is! Basically we have a plugin https://github.com/eslint-plugins/eslint-plugin-lean-imports that warns people when they pull in a full module instead of pulling just a single file. Some packages advise people to pull single files in order to have smaller bundles (eg: lodash, react-bootstrap).

// with "lean-imports/import": [1, [ "react-bootstrap "] ]
import RB from 'react-bootstrap'; // warns
const RB = require('react-bootstrap'); // warns

const Button = require('react-bootstrap/lib/button'); // passes

As I said, I can have a similar behavior by setting

{
  "no-restricted-imports": [2, "react-bootstrap"],
  "no-restricted-modules":[2, "react-bootstrap"],
}

The issue is just that the error message is not really tailored at that behavior and is really obscure if that is what the wanted behavior was: 'react-bootstrap' import is restricted from being used. It would be nice if there was a way to specify something more tailored for these packages (like have different “sections” or something along that), or have a message that supports both!

The message we have in lean-import is the following Importing the entire lodash library is not permitted, please import the specific functions you need which tells the user why it errored.

Also, Adding documentation about that specific use case in the doc of both of these rules could help people learn about it!

I’m willing to do the PRs with these, I’m just not sure of the approach here.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:30 (16 by maintainers)

github_iconTop GitHub Comments

3reactions
dozoischcommented, Nov 10, 2016

@ilyavolodin Alright! Yes, it’ll support both (old and new)! I should have some time to do it today or tomorrow.

3reactions
ljharbcommented, Nov 4, 2016

I’d suggest making the schema allow an array of either a string (current), or { "name": "<current string>", "message": "<optional message>" } - that lets it be a smooth backwards-compatible upgrade on top of the current schema, and mirrors no-restricted-properties for “message”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-restricted-imports - ESLint - Pluggable JavaScript Linter
This rule allows you to specify imports that you don't want to use in your application. It applies to static imports only, not...
Read more >
Build System · Backstage Software Catalog and Developer ...
The Backstage build system is a collection of build and development tools that help you lint, test, develop and finally release your Backstage...
Read more >
rollup.js
Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, such as a library...
Read more >
Micro Frontend Architecture: Import chunks from another ...
Importing chunks from other Webpack bundles at runtime, using them as if there were always there — interleaved applications.
Read more >
Minimizing bundle size - Material UI - MUI
Be aware that we only support first and second-level imports. Anything deeper is considered private and can cause issues, such as module duplication...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found