Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To to disable import/no-unassigned-import? #262

Closed
pavelpichrt opened this issue Oct 23, 2017 · 4 comments
Closed

To to disable import/no-unassigned-import? #262

pavelpichrt opened this issue Oct 23, 2017 · 4 comments

Comments

@pavelpichrt
Copy link

Hello,

I am importing a dependency that doesn't need a named variable (a polyfill - core-js/es6/weak-map) and I need to disable the aforementioned rule. I tried all permutations of override as documented in the readme, however, nothing works:

Examples (I understand I don't need both global and override rule, this is just to illustrate, what I tried so far):

"xo": {
    "esnext": true,
    "import/no-unassigned-import": 0, // + all permutations, like an array syntax etc.
    "overrides": [
      {
        "files": "index.js",
        "import/no-unassigned-import": 0 // + all permutations
      }
    ]
  },

Thanks

@sindresorhus
Copy link
Member

Per the docs, you have to place it in the rules option.

@pavelpichrt
Copy link
Author

Thanks, this worked. For anyone else with the same issue (this want's clear to other devs in the office either), the correct syntax to override a rule is following (in package.json):

  "xo": {
    "rules": {
      "import/no-unassigned-import": 0
    }
  }

@maxfi
Copy link

maxfi commented Jul 22, 2018

Rather than completely disabling this rule you can also add exceptions.

For example, in meteor it's common to do import './some-template.html' for importing blaze templates but this causes an Imported module should be assigned import/no-unassigned-import error.

You can add a rule override for this rule to allow blaze template imports and meteor package (with only side-effects) imports to not throw errors:

// package.json

{
  "xo": {
    "prettier": true,
    "semicolon": false,
    "space": 2,
    "settings": {
      "import/resolver": "meteor"
    },
    "rules": {
      "import/no-absolute-path": 0,           // should be handled by `eslint-import-resolver-meteor` package
      "import/no-unassigned-import": ["error", {
        "allow": ["meteor/*:*", "**/*.html"]  // this allows, for example: `import 'meteor/meteorhacks:unblock'` and `import './some-template.html'`
      }]
    }
  },
  "devDependencies": {
    "eslint-import-resolver-meteor": "^0.4.0",
    "xo": "^0.21.1"
  }
}

Also, in the entry point files you might also be importing other startup files that would throw an error even with the above configuration. I'm thinking it's best to be explicit here and disable the rule as required:

/server/main.js

/* eslint import/no-unassigned-import: "off" */
// Server entry point, imports all server code

import '/imports/startup/server'
import '/imports/startup/both'

References:

@dobromyslov
Copy link

@maxfi thank you for the best solution. I use it to import reflect-metadata package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants