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

no-invalid-this error is suppressed in node environment #3961

Closed
mhipszki opened this issue Sep 28, 2015 · 3 comments · Fixed by netiam/oauth#3, ampproject/amphtml#523, HBM/node-jet#93, netiam/errors#3 or netiam/acl#3
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@mhipszki
Copy link

The version of ESLint you are using (run eslint -v)

1.5.1

What you did (the source code and ESLint configuration)

source code

// some Node.js module's code
'use strict';

this.a = 3;

eslint config

{
    "extends": "eslint:recommended",
    "env": { "node": true },
    "rules": {
        "no-invalid-this": 2
    }
}

The actual ESLint output complete with numbers

nothing

What you expected to happen instead

Expected ESLint to report no-invalid-this error, but instead got nothing.

this refers to the module object itself in a context of a Node module, so it won't be undefined in any case.

However I would not encourage developers to use this.a = 3; in Node modules instead of exports.a = 3; as the latter one is more explicit, however it might be just my personal preference?

Node modules are cached after loading, which actually advocating the "singleton pattern" in a way, and again it might be my own preference, but I would not encourage developers to do that as a habit.

See https://nodejs.org/api/modules.html#modules_caching

Proposal: an option to warn developers not to use this in Node modules' root scope.

@eslintbot
Copy link

Thanks for the issue! If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Sep 28, 2015
@michaelficarra
Copy link
Member

This is simply a bug in no-invalid-this. It should report top-level this, but is likely getting tripped up by the implicit top-level function wrapper in node programs.

@ilyavolodin ilyavolodin added bug ESLint is working incorrectly rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Sep 28, 2015
@mysticatea
Copy link
Member

Thanks for the report.
It's a bug of no-invalid-this.
I will fix it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.