0

Working in electron vue-cli project. Trying to upgrade eslint but the default setup has no-use-before-define enabled.

This causes it to catch every use of things like window.process.env.username as an error.

I tried setting my rules as "no-use-before-define": ["error", { "variables": false }], but it didn't help. Adding window as a global also didn't help. Is there a way to fix eslint to be happy with the window variable?

I do like the idea of this feature, so I would like to leave it on if possible. But just turning it off is ok too if that's the best answer.

If it helps, this is my current .eslintrc.js file

// https://eslint.org/docs/user-guide/configuring

module.exports = {
  root: true,
  parserOptions: {
    parser: 'babel-eslint'
  },
  env: {
    browser: true
  },
  extends: [
    // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
    // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
    'plugin:vue/essential',
    // https://github.com/standard/standard/blob/master/docs/RULES-en.md
    'standard'
  ],
  // required to lint *.vue files
  plugins: [
    'vue'
  ],
  // add your custom rules here
  rules: {
    // Don't error on variables that are global, like window, not working.
    "no-use-before-define": ["error", { "variables": false }],
    'generator-star-spacing': 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    "vue/html-self-closing": ["error", {
      "html": {
        "void": "always",
        "normal": "any",
        "component": "always"
      },
      "svg": "always",
      "math": "always"
    }]
  }
}

Thanks

-Edit

Tried

globals: {
    window: 'writable'
  },

But to no effect

Trevor
  • 2,792
  • 1
  • 30
  • 43
  • My guess is that you need to let eslint know about some globals. (from your own link) https://eslint.org/docs/user-guide/configuring#specifying-environments seems like it would probably be useful. If nothing else, you can always add globals directly https://eslint.org/docs/user-guide/configuring#specifying-globals) – CollinD Sep 17 '19 at 18:53
  • @CollinD no luck, it almost seems to ignore globals entirely – Trevor Sep 17 '19 at 19:01
  • 1
    The global you're interested in is not `window`, it's `process`. You've set your env to browser which (correctly) does not have a `process` global variable. Hard to say for sure w/o a full repro, so I might be totally off-base. – CollinD Sep 17 '19 at 20:59

0 Answers0