cowbell/splittypie

View on GitHub

Showing 33 of 33 total issues

Function exports has 52 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function (defaults) {
    const app = new EmberApp(defaults, {
        "ember-cli-babel": {
            includePolyfill: true,
        },
Severity: Major
Found in ember-cli-build.js - About 2 hrs to fix

    Function outputReady has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        outputReady(results) {
            const env = this.app.env;
    
            if (!(env === "production" || env === "staging")) {
                return true;
    Severity: Minor
    Found in lib/upload-rollbar-source-maps/index.js - About 1 hr to fix

      Function transfers has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          transfers: computed("users.@each.balance", function () {
              const users = get(this, "users");
              const currency = get(this, "users.firstObject.event.currency");
      
              const owed = users.filter(u => get(u, "balance") < 0).map(convertToUserAmount);
      Severity: Minor
      Found in app/components/settlement-transfer-list.js - About 1 hr to fix

        Function generateUniqueId has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function generateUniqueId() {
            let now = new Date().getTime();
            const duplicateTime = (now === lastPushTime);
            lastPushTime = now;
        
        
        Severity: Minor
        Found in app/utils/generate-unique-id.js - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function parseTransaction has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function parseTransaction(transactionText) {
            if (!transactionText || !transactionText.trim()) return null;
        
            const parts = transactionText.trim().split(" ");
            const onlyMePattern = /\.\s*me\s*$/;
        Severity: Minor
        Found in app/utils/parse-transaction.js - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function settleUp has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                settleUp(transfer) {
                    get(this, "modal").trigger("show", {
                        name: "settle-up",
                        actions: {
                            yes: () => {
        Severity: Minor
        Found in app/routes/event/index.js - About 1 hr to fix

          Function parseTransaction has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export default function parseTransaction(transactionText) {
              if (!transactionText || !transactionText.trim()) return null;
          
              const parts = transactionText.trim().split(" ");
              const onlyMePattern = /\.\s*me\s*$/;
          Severity: Minor
          Found in app/utils/parse-transaction.js - About 1 hr to fix

            Function generateUniqueId has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export default function generateUniqueId() {
                let now = new Date().getTime();
                const duplicateTime = (now === lastPushTime);
                lastPushTime = now;
            
            
            Severity: Minor
            Found in app/utils/generate-unique-id.js - About 1 hr to fix

              Function initialize has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  initialize(application) {
                      const notify = application.__container__.lookup("service:notify");
              
                      if ("serviceWorker" in window.navigator) {
                          window.navigator.serviceWorker.register("/offline-support.js").then((registration) => {
              Severity: Minor
              Found in app/initializers/offline-support.js - About 1 hr to fix

                Function reportError has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                function reportError(error) {
                    if (Ember.testing) {
                        throw error;
                    }
                
                
                Severity: Minor
                Found in app/initializers/rollbar.js - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function transfers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    transfers: computed("users.@each.balance", function () {
                        const users = get(this, "users");
                        const currency = get(this, "users.firstObject.event.currency");
                
                        const owed = users.filter(u => get(u, "balance") < 0).map(convertToUserAmount);
                Severity: Minor
                Found in app/components/settlement-transfer-list.js - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                'process' is not defined.
                Open

                        const accessToken = process.env.ROLLBAR_SERVER_ACCESS_TOKEN || "";

                Disallow Undeclared Variables (no-undef)

                This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

                Rule Details

                Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

                Examples of incorrect code for this rule:

                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                Examples of correct code for this rule with global declaration:

                /*global someFunction b:true*/
                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                The b:true syntax in /*global */ indicates that assignment to b is correct.

                Examples of incorrect code for this rule with global declaration:

                /*global b*/
                /*eslint no-undef: "error"*/
                
                b = 10;

                By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

                Options

                • typeof set to true will warn for variables used inside typeof check (Default false).

                typeof

                Examples of correct code for the default { "typeof": false } option:

                /*eslint no-undef: "error"*/
                
                if (typeof UndefinedIdentifier === "undefined") {
                    // do something ...
                }

                You can use this option if you want to prevent typeof check on a variable which has not been declared.

                Examples of incorrect code for the { "typeof": true } option:

                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Examples of correct code for the { "typeof": true } option with global declaration:

                /*global a*/
                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Environments

                For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

                browser

                Examples of correct code for this rule with browser environment:

                /*eslint no-undef: "error"*/
                /*eslint-env browser*/
                
                setTimeout(function() {
                    alert("Hello");
                });

                node

                Examples of correct code for this rule with node environment:

                /*eslint no-undef: "error"*/
                /*eslint-env node*/
                
                var fs = require("fs");
                module.exports = function() {
                    console.log(fs);
                };

                When Not To Use It

                If explicit declaration of global variables is not to your taste.

                Compatibility

                This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

                'require' is not defined.
                Open

                const path = require("path");

                Disallow Undeclared Variables (no-undef)

                This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

                Rule Details

                Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

                Examples of incorrect code for this rule:

                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                Examples of correct code for this rule with global declaration:

                /*global someFunction b:true*/
                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                The b:true syntax in /*global */ indicates that assignment to b is correct.

                Examples of incorrect code for this rule with global declaration:

                /*global b*/
                /*eslint no-undef: "error"*/
                
                b = 10;

                By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

                Options

                • typeof set to true will warn for variables used inside typeof check (Default false).

                typeof

                Examples of correct code for the default { "typeof": false } option:

                /*eslint no-undef: "error"*/
                
                if (typeof UndefinedIdentifier === "undefined") {
                    // do something ...
                }

                You can use this option if you want to prevent typeof check on a variable which has not been declared.

                Examples of incorrect code for the { "typeof": true } option:

                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Examples of correct code for the { "typeof": true } option with global declaration:

                /*global a*/
                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Environments

                For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

                browser

                Examples of correct code for this rule with browser environment:

                /*eslint no-undef: "error"*/
                /*eslint-env browser*/
                
                setTimeout(function() {
                    alert("Hello");
                });

                node

                Examples of correct code for this rule with node environment:

                /*eslint no-undef: "error"*/
                /*eslint-env node*/
                
                var fs = require("fs");
                module.exports = function() {
                    console.log(fs);
                };

                When Not To Use It

                If explicit declaration of global variables is not to your taste.

                Compatibility

                This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

                Unexpected console statement.
                Open

                            .then(() => console.log("source maps have been successfully uploaded"));

                disallow the use of console (no-console)

                In JavaScript that is designed to be executed in the browser, it's considered a best practice to avoid using methods on console. Such messages are considered to be for debugging purposes and therefore not suitable to ship to the client. In general, calls using console should be stripped before being pushed to production.

                console.log("Made it here.");
                console.error("That shouldn't have happened.");

                Rule Details

                This rule disallows calls to methods of the console object.

                Examples of incorrect code for this rule:

                /*eslint no-console: "error"*/
                
                console.log("Log a debug level message.");
                console.warn("Log a warn level message.");
                console.error("Log an error level message.");

                Examples of correct code for this rule:

                /*eslint no-console: "error"*/
                
                // custom console
                Console.log("Hello world!");

                Options

                This rule has an object option for exceptions:

                • "allow" has an array of strings which are allowed methods of the console object

                Examples of additional correct code for this rule with a sample { "allow": ["warn", "error"] } option:

                /*eslint no-console: ["error", { allow: ["warn", "error"] }] */
                
                console.warn("Log a warn level message.");
                console.error("Log an error level message.");

                When Not To Use It

                If you're using Node.js, however, console is used to output information to the user and so is not strictly used for debugging purposes. If you are developing for Node.js then you most likely do not want this rule enabled.

                Related Rules

                'module' is not defined.
                Open

                module.exports = {

                Disallow Undeclared Variables (no-undef)

                This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

                Rule Details

                Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

                Examples of incorrect code for this rule:

                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                Examples of correct code for this rule with global declaration:

                /*global someFunction b:true*/
                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                The b:true syntax in /*global */ indicates that assignment to b is correct.

                Examples of incorrect code for this rule with global declaration:

                /*global b*/
                /*eslint no-undef: "error"*/
                
                b = 10;

                By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

                Options

                • typeof set to true will warn for variables used inside typeof check (Default false).

                typeof

                Examples of correct code for the default { "typeof": false } option:

                /*eslint no-undef: "error"*/
                
                if (typeof UndefinedIdentifier === "undefined") {
                    // do something ...
                }

                You can use this option if you want to prevent typeof check on a variable which has not been declared.

                Examples of incorrect code for the { "typeof": true } option:

                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Examples of correct code for the { "typeof": true } option with global declaration:

                /*global a*/
                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Environments

                For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

                browser

                Examples of correct code for this rule with browser environment:

                /*eslint no-undef: "error"*/
                /*eslint-env browser*/
                
                setTimeout(function() {
                    alert("Hello");
                });

                node

                Examples of correct code for this rule with node environment:

                /*eslint no-undef: "error"*/
                /*eslint-env node*/
                
                var fs = require("fs");
                module.exports = function() {
                    console.log(fs);
                };

                When Not To Use It

                If explicit declaration of global variables is not to your taste.

                Compatibility

                This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

                Unexpected console statement.
                Open

                console.log(JSON.stringify(dump));
                Severity: Minor
                Found in get-seed-json.js by eslint

                disallow the use of console (no-console)

                In JavaScript that is designed to be executed in the browser, it's considered a best practice to avoid using methods on console. Such messages are considered to be for debugging purposes and therefore not suitable to ship to the client. In general, calls using console should be stripped before being pushed to production.

                console.log("Made it here.");
                console.error("That shouldn't have happened.");

                Rule Details

                This rule disallows calls to methods of the console object.

                Examples of incorrect code for this rule:

                /*eslint no-console: "error"*/
                
                console.log("Log a debug level message.");
                console.warn("Log a warn level message.");
                console.error("Log an error level message.");

                Examples of correct code for this rule:

                /*eslint no-console: "error"*/
                
                // custom console
                Console.log("Hello world!");

                Options

                This rule has an object option for exceptions:

                • "allow" has an array of strings which are allowed methods of the console object

                Examples of additional correct code for this rule with a sample { "allow": ["warn", "error"] } option:

                /*eslint no-console: ["error", { allow: ["warn", "error"] }] */
                
                console.warn("Log a warn level message.");
                console.error("Log an error level message.");

                When Not To Use It

                If you're using Node.js, however, console is used to output information to the user and so is not strictly used for debugging purposes. If you are developing for Node.js then you most likely do not want this rule enabled.

                Related Rules

                'process' is not defined.
                Open

                const dumpName = process.argv[2];
                Severity: Minor
                Found in get-seed-json.js by eslint

                Disallow Undeclared Variables (no-undef)

                This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

                Rule Details

                Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

                Examples of incorrect code for this rule:

                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                Examples of correct code for this rule with global declaration:

                /*global someFunction b:true*/
                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                The b:true syntax in /*global */ indicates that assignment to b is correct.

                Examples of incorrect code for this rule with global declaration:

                /*global b*/
                /*eslint no-undef: "error"*/
                
                b = 10;

                By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

                Options

                • typeof set to true will warn for variables used inside typeof check (Default false).

                typeof

                Examples of correct code for the default { "typeof": false } option:

                /*eslint no-undef: "error"*/
                
                if (typeof UndefinedIdentifier === "undefined") {
                    // do something ...
                }

                You can use this option if you want to prevent typeof check on a variable which has not been declared.

                Examples of incorrect code for the { "typeof": true } option:

                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Examples of correct code for the { "typeof": true } option with global declaration:

                /*global a*/
                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Environments

                For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

                browser

                Examples of correct code for this rule with browser environment:

                /*eslint no-undef: "error"*/
                /*eslint-env browser*/
                
                setTimeout(function() {
                    alert("Hello");
                });

                node

                Examples of correct code for this rule with node environment:

                /*eslint no-undef: "error"*/
                /*eslint-env node*/
                
                var fs = require("fs");
                module.exports = function() {
                    console.log(fs);
                };

                When Not To Use It

                If explicit declaration of global variables is not to your taste.

                Compatibility

                This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

                'require' is not defined.
                Open

                const RSVP = require("rsvp");

                Disallow Undeclared Variables (no-undef)

                This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

                Rule Details

                Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

                Examples of incorrect code for this rule:

                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                Examples of correct code for this rule with global declaration:

                /*global someFunction b:true*/
                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                The b:true syntax in /*global */ indicates that assignment to b is correct.

                Examples of incorrect code for this rule with global declaration:

                /*global b*/
                /*eslint no-undef: "error"*/
                
                b = 10;

                By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

                Options

                • typeof set to true will warn for variables used inside typeof check (Default false).

                typeof

                Examples of correct code for the default { "typeof": false } option:

                /*eslint no-undef: "error"*/
                
                if (typeof UndefinedIdentifier === "undefined") {
                    // do something ...
                }

                You can use this option if you want to prevent typeof check on a variable which has not been declared.

                Examples of incorrect code for the { "typeof": true } option:

                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Examples of correct code for the { "typeof": true } option with global declaration:

                /*global a*/
                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Environments

                For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

                browser

                Examples of correct code for this rule with browser environment:

                /*eslint no-undef: "error"*/
                /*eslint-env browser*/
                
                setTimeout(function() {
                    alert("Hello");
                });

                node

                Examples of correct code for this rule with node environment:

                /*eslint no-undef: "error"*/
                /*eslint-env node*/
                
                var fs = require("fs");
                module.exports = function() {
                    console.log(fs);
                };

                When Not To Use It

                If explicit declaration of global variables is not to your taste.

                Compatibility

                This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

                'process' is not defined.
                Open

                        const siteUrl = process.env.DEPLOY_SITE_URL || "";

                Disallow Undeclared Variables (no-undef)

                This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

                Rule Details

                Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

                Examples of incorrect code for this rule:

                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                Examples of correct code for this rule with global declaration:

                /*global someFunction b:true*/
                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                The b:true syntax in /*global */ indicates that assignment to b is correct.

                Examples of incorrect code for this rule with global declaration:

                /*global b*/
                /*eslint no-undef: "error"*/
                
                b = 10;

                By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

                Options

                • typeof set to true will warn for variables used inside typeof check (Default false).

                typeof

                Examples of correct code for the default { "typeof": false } option:

                /*eslint no-undef: "error"*/
                
                if (typeof UndefinedIdentifier === "undefined") {
                    // do something ...
                }

                You can use this option if you want to prevent typeof check on a variable which has not been declared.

                Examples of incorrect code for the { "typeof": true } option:

                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Examples of correct code for the { "typeof": true } option with global declaration:

                /*global a*/
                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Environments

                For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

                browser

                Examples of correct code for this rule with browser environment:

                /*eslint no-undef: "error"*/
                /*eslint-env browser*/
                
                setTimeout(function() {
                    alert("Hello");
                });

                node

                Examples of correct code for this rule with node environment:

                /*eslint no-undef: "error"*/
                /*eslint-env node*/
                
                var fs = require("fs");
                module.exports = function() {
                    console.log(fs);
                };

                When Not To Use It

                If explicit declaration of global variables is not to your taste.

                Compatibility

                This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

                'require' is not defined.
                Open

                const exec = require("child_process").execSync;
                Severity: Minor
                Found in utils/code-version.js by eslint

                Disallow Undeclared Variables (no-undef)

                This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

                Rule Details

                Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

                Examples of incorrect code for this rule:

                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                Examples of correct code for this rule with global declaration:

                /*global someFunction b:true*/
                /*eslint no-undef: "error"*/
                
                var a = someFunction();
                b = 10;

                The b:true syntax in /*global */ indicates that assignment to b is correct.

                Examples of incorrect code for this rule with global declaration:

                /*global b*/
                /*eslint no-undef: "error"*/
                
                b = 10;

                By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

                Options

                • typeof set to true will warn for variables used inside typeof check (Default false).

                typeof

                Examples of correct code for the default { "typeof": false } option:

                /*eslint no-undef: "error"*/
                
                if (typeof UndefinedIdentifier === "undefined") {
                    // do something ...
                }

                You can use this option if you want to prevent typeof check on a variable which has not been declared.

                Examples of incorrect code for the { "typeof": true } option:

                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Examples of correct code for the { "typeof": true } option with global declaration:

                /*global a*/
                /*eslint no-undef: ["error", { "typeof": true }] */
                
                if(typeof a === "string"){}

                Environments

                For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

                browser

                Examples of correct code for this rule with browser environment:

                /*eslint no-undef: "error"*/
                /*eslint-env browser*/
                
                setTimeout(function() {
                    alert("Hello");
                });

                node

                Examples of correct code for this rule with node environment:

                /*eslint no-undef: "error"*/
                /*eslint-env node*/
                
                var fs = require("fs");
                module.exports = function() {
                    console.log(fs);
                };

                When Not To Use It

                If explicit declaration of global variables is not to your taste.

                Compatibility

                This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

                Severity
                Category
                Status
                Source
                Language