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

'console' is not defined. (when env broswer is defined in config) #132

Closed
johndugan opened this issue Sep 8, 2016 · 1 comment
Closed

Comments

@johndugan
Copy link

Hi folks,

I am getting a 'console is not defined. (no-undef)` error. I do have both browser and node defined in my eslint config.

However, when I add /*eslint-env browser*/ to a file with a console statement, I don't get the error. It seems the environment definitions in my eslint.options object are being ignored.

Below is my configuration:

    "eslint.options": {
        "parserOptions": {
            "ecmaVersion": 6
        },
        "env": {
            "es6": true,
            "node": true,
            "browser": true
        },
        "rules": {
            "arrow-body-style": [2, "always"], // es6
            "arrow-parens": [2, "always"], // es6
            "arrow-spacing": [1, {"before": true, "after": true}], // es6
            "block-scoped-var": 2,
            "brace-style": [1, "1tbs", { "allowSingleLine": true }],
            "comma-spacing": [1, {"before": false, "after": true}],
            "consistent-return": 1,
            "constructor-super": 2, // es6
            "curly": [2, "all"],
            "default-case": 1,
            "dot-notation": [1, {"allowKeywords": true}],
            "eol-last": 1,
            "eqeqeq": 1,
            "indent": [1, 4],
            "key-spacing": [1, {"beforeColon": false, "afterColon": true}],
            "keyword-spacing": [1, {"before": true, "after": true}],
            "linebreak-style": [1, "unix"],
            "new-cap": [2, {"newIsCap": true, "capIsNew": true, "newIsCapExceptions": [], "capIsNewExceptions": []}],
            "new-parens": 2,
            "no-case-declarations": 2,
            "no-class-assign": 2, // es6
            "no-confusing-arrow": [2, {"allowParens": true}], //es6
            "no-console": 1,
            "no-const-assign": 2, // es6
            "no-constant-condition": 2,
            "no-div-regex": 2,
            "no-dupe-class-members": 2, // es6
            "no-else-return": 2,
            "no-empty-pattern": 2,
            "no-extend-native": 2,
            "no-extra-bind": 2,
            "no-extra-parens": [1, "all"],
            "no-fallthrough": 1,
            "no-iterator": 2,
            "no-lone-blocks": 2,
            "no-loop-func": 1,
            "no-multi-spaces": 1, // flags variable `=` alignment
            "no-multi-str": 1,
            "no-native-reassign": 2,
            "no-new-func": 2,
            "no-new-wrappers": 2,
            "no-octal-escape": 2,
            // "no-param-reassign": 2, // flags `myNum += 1`
            "no-proto": 2,
            "no-return-assign": 2,
            "no-script-url": 2,
            "no-self-assign": 1,
            "no-self-compare": 1,
            "no-sequences": 2,
            "no-shadow": [2, {"builtinGlobals": true, "hoist": "all", "allow": ["$", "Plugin", "self"]}],
            "no-shadow-restricted-names": 2,
            "no-spaced-func": 2,
            "no-this-before-super": 1, // es6
            "no-throw-literal": 2,
            "no-trailing-spaces": 1,
            "no-undef": 2,
            "no-undef-init": 2,
            "no-undefined": 2,
            "no-unneeded-ternary": 1,
            "no-unexpected-multiline": 2,
            "no-unused-expressions": [2, {"allowShortCircuit": false, "allowTernary": true}],
            "no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
            "no-use-before-define": [2, "nofunc"], // exception for function declarations
            "no-useless-call": 1,
            "no-useless-concat": 1,
            "no-void": 2,
            "no-with": 2,
            "object-curly-spacing": [1, "never"],
            "object-shorthand": [1, "never"], // es6
            "prefer-arrow-callback": 1, // es6
            "prefer-spread": 1, // es6
            "quotes": [1, "single"],
            "radix": [2, "as-needed"],
            "semi": [2, "always"],
            "semi-spacing": [1, {"before": false, "after": true}],
            "space-before-blocks": [1, {"functions": "always", "keywords": "always"}],
            "space-before-function-paren": [1, {"anonymous": "never", "named": "never"}],
            "space-in-parens": [1, "never"],
            // "space-infix-ops": 1, // flags `'str'+'ing'`
            "space-unary-ops": [1, { "words": true, "nonwords": false }],
            "spaced-comment": [1, "always", {"exceptions": ["!"]}], // exception for `!`
            "vars-on-top": 1,
            "wrap-iife": [1, "outside"],
            "wrap-regex": 1,
            "yoda": [1, "never"]
        },

        // http://eslint.org/docs/user-guide/configuring#extending-configuration-files
        // ---------------------------------------------------------------------------
        "extends": "eslint:recommended"
    }

In a test.js file, this throws the no-undef error:

const foo = 'bar';

(function() {
    console.log(foo);
}());

This does not:

/* eslint-env browser */

const foo = 'bar';

(function() {
    console.log(foo);
}());
@dbaeumer
Copy link
Member

If you put options into the settings file they have to follow the style of the command line / CLIEngine (see doc here: http://eslint.org/docs/developer-guide/nodejs-api#executeontext) For some reason the decided to name env in that case envs and make it an array. Changing this accordingly make everything work. I updated the doc of the eslint setting to make this more clear.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants