import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.55k stars 1.56k forks source link

How can I ignore URL imports? #1988

Open stefanfrede opened 3 years ago

stefanfrede commented 3 years ago

I have this import and would like to ignore it: import confetti from 'https://cdn.skypack.dev/canvas-confetti';.

I tried the following in my .eslintrc.js, but it did not work:

  settings: {
    'import/ignore': ['^(https://cdn.skypack.dev/)'],
  },

I also tried something simpler without success:

  settings: {
    'import/ignore': ['^https'],
  },

Now I'm wondering what I have to do to ignore imports like that.

ljharb commented 3 years ago

When you say "it did not work", can you elaborate?

stefanfrede commented 3 years ago

With it did not work I mean that my linter is still throwing the error import/no-unresolved: Unable to resolve path to module 'https://cdn.skypack.dev/canvas-confetti'..

ljharb commented 3 years ago

See https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md#ignore - you need to configure the no-unresolved rule separately.

stefanfrede commented 3 years ago

Thank you, but it seems I'm still doing something wrong.

I changed my settings now to the following:

  settings: {
    'import/no-unresolved': [2, { ignore: ['^https'] }],
  },

Sadly this does not change anything.

ljharb commented 3 years ago

what's your full eslint config?

stefanfrede commented 3 years ago

This is my config:

module.exports = {
  root: true,
  extends: [
    'eslint:recommended',
    'plugin:import/errors',
    'plugin:import/warnings',
    'plugin:prettier/recommended',
  ],
  parserOptions: {
    ecmaVersion: 11,
    sourceType: 'module',
    allowImportExportEverywhere: true,
    ecmaFeatures: {
      impliedStrict: true,
    },
  },
  env: {
    browser: true,
    node: true,
    es6: true,
  },
  plugins: ['html'],
  settings: {
    'import/no-unresolved': [2, { ignore: ['^https'] }],
  },
};
ljharb commented 3 years ago

(i'm confused by allowImportExportEverywhere, since import/export statements don't work except at Module level)

that definitely seems like it should work. You're not using any custom resolvers, you have root true, and none of those extended configs do anything wonky.

can you share the file that's being linted?

stefanfrede commented 3 years ago

Sure:

import Template from './template.js';

import confetti from 'https://cdn.skypack.dev/canvas-confetti';

export default class App extends HTMLElement {
  constructor() {
    super();

    this.attachShadow({ mode: 'open' });
    this.shadowRoot.innerHTML = Template.render();
    this.dom = Template.mapDOM(this.shadowRoot);

    confetti();
  }
}

if (!customElements.get('mf-app')) {
  customElements.define('mf-app', App);
}

Screenshot-from-2021-02-10-17-47-25.png

stefanfrede commented 3 years ago

I pushed my code to GitHub: https://github.com/stefanfrede/monkey-funnel/tree/fix-problem-with-import.

I removed the skypack import for now but maybe the rest of my code is helping to figure out why import/no-unresolved': [2, { ignore: ['^https'] }] is not ignoring imports like import confetti from 'https://cdn.skypack.dev/canvas-confetti'.

ljharb commented 3 years ago

@stefanfrede npm run lint:eslint errors out on "no files matching src/".

If i run npx eslint . it does not produce an error.

stefanfrede commented 3 years ago

Yes, sorry, my bad. I adjusted the code and if you now run npm run lint:eslint you get the import/no-unresolved error.

This is the .eslintrc.js and this is the file where the error is happening.