question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule no-invalid-this fails on functions which name starts with "_"

See original GitHub issue

What version of ESLint are you using? v2.7.0 What parser (default, Babel-ESLint, etc.) are you using? default Please show your full configuration:

{
    "env": {
        "browser": false,
        "amd": true,
        "es6": true
    },
    "globals": {
        "document": true,
        "window": true,
        "console": true,
        "requestAnimationFrame": true,
        "XMLHttpRequest": true,
        "setInterval": true,
        "clearInterval": true,
        "setTimeout": true,
        "clearTimeout": true
    },
    "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "script",
        "ecmaFeatures": {
            "globalReturn": false,
            "impliedStrict": true,
            "jsx": false,
            "experimentalObjectRestSpread": false
        }
    },
    "rules": {

        "comma-dangle": [2, "never"],

        "no-cond-assign": [2, "always"],

        "no-console": 1,

        "no-constant-condition": 1,

        "no-control-regex": 2,

        "no-debugger": 2,

        "no-dupe-args": 2,

        "no-dupe-keys": 2,

        "no-duplicate-case": 2,

        "no-empty": 2,

        "no-empty-character-class": 2,

        "no-ex-assign": 2,

        "no-extra-boolean-cast": 0,

        "no-extra-parens": [2, "functions"],

        "no-extra-semi": 2,

        "no-func-assign": 2,

        "no-inner-declarations": 2,

        "no-invalid-regexp": 2,

        "no-irregular-whitespace": 2,

        "no-negated-in-lhs": 2,

        "no-obj-calls": 2,

        "no-regex-spaces": 2,

        "no-sparse-arrays": 2,

        "no-unexpected-multiline": 2,

        "no-unreachable": 2,

        "use-isnan": 2,

        "valid-jsdoc": [0, {"requireParamDescription": false, "requireReturnDescription": false, "requireReturn": false}],

        "valid-typeof": 2,

        "accessor-pairs": 0,

        "array-callback-return": 2,

        "block-scoped-var": 0,

        "complexity": [0, 11],

        "consistent-return": 0,

        "curly": [2, "all"],

        "default-case": 0,

        "dot-location": 0,

        "dot-notation": [2, { "allowKeywords": true}],

        "eqeqeq": 2,

        "guard-for-in": 0,

        "no-alert": 2,

        "no-caller": 2,

        "no-case-declarations": 2,

        "no-div-regex": 0,

        "no-else-return": 0,

        "no-empty-function": [2, {"allow": ["constructors", "methods"]}],

        "no-empty-pattern": 2,

        "no-eq-null": 2,

        "no-eval": 2,

        "no-extend-native": 2,

        "no-extra-bind": 2,

        "no-extra-label": 2,

        "no-fallthrough": 2,

        "no-floating-decimal": 2,

        "no-implicit-coercion": 0,

        "no-implicit-globals": 2,

        "no-implied-eval": 2,

        "no-invalid-this": 2,

        "no-iterator": 2,

        "no-labels": 2,

        "no-lone-blocks": 2,

        "no-loop-func": 2,

        "no-magic-numbers": 0,

        "no-multi-spaces": 2,

        "no-multi-str": 2,

        "no-native-reassign": 2,

        "no-new": 2,

        "no-new-func": 2,

        "no-new-wrappers": 2,

        "no-octal": 2,

        "no-octal-escape": 2,

        "no-param-reassign": 0,

        "no-proto": 2,

        "no-redeclare": 2,

        "no-return-assign": 2,

        "no-script-url": 2,

        "no-self-assign": 2,

        "no-self-compare": 2,

        "no-sequences": 2,

        "no-throw-literal": 2,

        "no-unmodified-loop-condition": 2,

        "no-unused-expressions": 2,

        "no-unused-labels": 2,

        "no-useless-call": 2,

        "no-useless-concat": 2,

        "no-useless-escape": 0,

        "no-void": 2,

        "no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],

        "no-with": 2,

        "radix": 2,

        "vars-on-top": 0,

        "wrap-iife": [2, "any"],

        "yoda": [2, "never"],

        "strict": [0, "never"],

        "init-declarations": 0,

        "no-catch-shadow": 0,

        "no-delete-var": 2,

        "no-label-var": 2,

        "no-restricted-globals": [2, "event", "name", "top", "History", "Text", "location", "self", "history", "Map", "Set", "WeakMap", "WeakSet", "Proxy", "Symbol", "Reflect"],

        "no-shadow":2,

        "no-shadow-restricted-names": 2,

        "no-undef": 2,

        "no-undef-init": 0,

        "no-undefined": 0,

        "no-unused-vars": [2, {"vars": "local", "args": "all"}],

        "no-use-before-define": [2, {"functions": false, "classes": true}],

        "callback-return": 0,

        "global-require": 0,

        "handle-callback-err": 0,

        "no-mixed-requires": [0, false],

        "no-new-require": 0,

        "no-path-concat": 0,

        "no-process-env": 0,

        "no-process-exit": 0,

        "no-restricted-modules": 0,

        "no-sync": 0,

        "array-bracket-spacing": [2, "never"],

        "block-spacing": 2,

        "brace-style": [2, "stroustrup"],

        "camelcase": [2, {"properties": "never"}],

        "comma-spacing": [2, {"before": false, "after": true}],

        "comma-style": [2, "last"],

        "computed-property-spacing": 0,

        "consistent-this": [2, "self"],

        "eol-last": 2,

        "func-names": 0,

        "func-style": [0, "declaration", { "allowArrowFunctions": true }],

        "id-blacklist": [0, "data", "err", "e", "cb", "callback"],

        "id-length": 0,

        "id-match": 0,

        "indent": [2, 4, {"SwitchCase": 1}],

        "jsx-quotes": 2,

        "key-spacing": [2, {"beforeColon": false, "afterColon": true}],

        "keyword-spacing": 2,

        "linebreak-style": 0,

        "lines-around-comment": 0,

        "max-depth": [0, 4],

        "max-len": [0, 80, 4],

        "max-nested-callbacks": 0,

        "max-params": [0, 3],

        "max-statements": [0, 10],

        "max-statements-per-line": 0,

        "new-cap": [2, {"newIsCap": true}],

        "new-parens": 2,

        "newline-after-var": 0,

        "newline-before-return": 0,

        "newline-per-chained-call": [0, { "ignoreChainWithDepth": 3 }],

        "no-array-constructor": 2,

        "no-bitwise": 2,

        "no-continue": 0,

        "no-inline-comments": 0,

        "no-lonely-if": 0,

        "no-mixed-spaces-and-tabs": 2,

        "no-multiple-empty-lines": [2, { "max": 1, "maxEOF": 1, "maxBOF": 1 }],

        "no-negated-condition": 0,

        "no-nested-ternary": 2,

        "no-new-object": 2,

        "no-plusplus": 0,

        "no-restricted-syntax": [2, "ClassDeclaration", "ClassBody", "ForOfStatement", "ImportDeclaration", "ObjectPattern", "ArrayPattern", "YieldExpression", "AssignmentPattern"],

        "no-spaced-func": 2,

        "no-ternary": 0,

        "no-trailing-spaces": 2,

        "no-underscore-dangle": [0, { "allowAfterThis": true }],

        "no-unneeded-ternary":  [2, { "defaultAssignment": false }],

        "no-whitespace-before-property": 2,

        "object-curly-spacing": [2, "always"],

        "one-var": [2, "never"],

        "one-var-declaration-per-line": [2, "always"],

        "operator-assignment": 0,

        "operator-linebreak": [2, "after", { "overrides": { "+=": "none", "-=": "none", "*=": "none", "/=": "none", "%=": "none", , "=": "none" } }],

        "padded-blocks": [0, "never"],

        "quote-props": [2, "as-needed"],

        "quotes": [2, "single", "avoid-escape"],

        "require-jsdoc": 0,

        "semi": [2, "always"],

        "semi-spacing": [2, {"before": false, "after": true}],

        "sort-imports": 0,

        "sort-vars": 0,

        "space-before-blocks": 2,

        "space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],

        "space-in-parens": [2, "never"],

        "space-infix-ops": 2,

        "space-unary-ops": 2,

        "spaced-comment": [0, "always", {
            "exceptions": ["-", "+"],
            "markers": ["=", "!"]
        }],

        "wrap-regex": 0,

        "arrow-body-style": [2, "as-needed"],

        "arrow-parens": 0,

        "arrow-spacing": [2, { "before": true, "after": true }],

        "constructor-super": 0,

        "generator-star-spacing": 0,

        "no-class-assign": 0,

        "no-confusing-arrow": [2, {
            "allowParens": true,
        }],

        "no-const-assign": 2,

        "no-dupe-class-members": 2,

        "no-duplicate-imports": 2,

        "no-new-symbol": 2,

        "no-restricted-imports": 0,

        "no-this-before-super": 2,

        "no-useless-constructor": 2,

        "no-var": 2,

        "object-shorthand": [2, "always"],

        "prefer-arrow-callback": 0,

        "prefer-const": 2,

        "prefer-reflect": 0,

        "prefer-rest-params": 0,

        "prefer-spread": 0,

        "prefer-template": 2,

        "require-yield": 0,

        "template-curly-spacing": 2,

        "yield-star-spacing": [2, "after"]
    }
}

What did you do? Please include the actual source code causing the issue.

define([], function (
) {

    function _foo() {
        this.bar(); // Error expected here
    }

    return _foo;
});

What did you expect to happen? Getting an error when using “this” inside the function declaration “_foo” (line 5).

What actually happened? Please include the actual, raw output from ESLint. No error. However, and that’s the interesting part, if I remove the underscore from the name of the function declaration, the error appears. Renaming “_foo” to “foo” fixes the problem

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mysticateacommented, Jun 14, 2016

In fact, the rule’s behavior has been changed a bit since #6085. Please try to use latest ESLint.

0reactions
rafayepescommented, Jun 14, 2016

That was definitely the issue. Updating ESLint fixed the problem.

Thanks everyone!

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-invalid-this - Pluggable JavaScript Linter - ESLint
This rule judges from following conditions whether or not the function is a constructor: The name of the function starts with uppercase.
Read more >
Eslint rule no-invalid-this and fat arrow function in class
You are getting this error because when you create an arrow function, you are creating an object that could be called in a...
Read more >
no-invalid-this - Rule
Rule: no-invalid-this. Disallows using the this keyword outside of classes. Rationale. See the rule's author's rationale here. Config.
Read more >
no-invalid-this | typescript-eslint
This rule extends the base eslint/no-invalid-this rule. ... Note: you must disable the base rule as it can report incorrect errors "no-invalid-this": "off",...
Read more >
Rules | Stylelint
A rule's name is split into two parts: the thing the rule applies to ... Invalid​. Disallow invalid syntax with these (sometimes implicit)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found