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.

Configuration globals "off" is not respected for TypeScript files

See original GitHub issue

Tell us about your environment

$ eslint --env-info Environment Info:

Node version: v10.11.0 npm version: v6.4.1 Local ESLint version: v6.8.0 Global ESLint version: v6.8.0 (Currently used)

What parser (default, Babel-ESLint, etc.) are you using? "parser": "@typescript-eslint/parser"

Please show your full configuration:

Configuration
module.exports = {
    "root": true,
    "parserOptions": {
        "ecmaVersion": 6
    },
    "extends": [
        "eslint:recommended"
    ],
    "plugins": [
        "@typescript-eslint"
    ],
    "parser": "@typescript-eslint/parser",

    "overrides": [{
        "files": ["**/*.ts"],
        "parserOptions": {
            "sourceType": "module"
        },
        "globals": {
            "console": "off",
            "document": "off",
            "window": "off"
        },
        "extends": [
            "eslint:recommended",
            "plugin:@typescript-eslint/eslint-recommended",
            "plugin:@typescript-eslint/recommended",
        ]
    }]
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

I want to turn off the globals such as console, document and window, and want eslint to show errors when people try to access them.

// test1.js 
// eslint works well in javascript file. All three globals are found and errors are thrown.
console.log(document, window);
// test2.ts
// eslint just silently let these globals pass in typescript file. 
console.log(document, window);
$ eslint --ext .ts,.js test1.js

...\test1.js
  1:1   error  'console' is not defined   no-undef
  1:13  error  'document' is not defined  no-undef
  1:23  error  'window' is not defined    no-undef

✖ 3 problems (3 errors, 0 warnings)

$ eslint --ext .ts,.js test2.ts

What did you expect to happen?

I expect that eslint can catch the turned-off globals console, document and window in the TypeScript file.

What actually happened? Please include the actual, raw output from ESLint.

eslint just let these globals pass without showing any errors for TypeScript files. =(

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Feb 3, 2020

I believe this is happening because @typescript-eslint/eslint-recommended from your configuration disables the core no-undef rule, as described here:

The eslint-recommended ruleset is meant to be used after extending eslint:recommended. It disables rules that are already checked by the TypeScript compiler and enables rules that promote using the more modern constructs TypeScript allows for.

From eslint-recommended.ts:

// This is checked by Typescript using the option `strictNullChecks`.
        'no-undef': 'off',
0reactions
eslint-deprecated[bot]commented, Mar 5, 2020

It looks like the conversation is stalled here. As this is a question rather than an action item, I’m closing the issue. If you still need help, please send a message to our mailing list or chatroom. Thanks! [//]: # (auto-close)

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Reference - Docs on every TSConfig option
Lets you set a base directory to resolve non-absolute module names. You can define a root folder where you can do absolute file...
Read more >
Message "npm WARN config global `--global`, `--local` are ...
Step 1: Go to the \nodejs folder and open the two files npm.cmd and npm by a text editor. Enter image description here....
Read more >
Understanding TypeScript Configuration Options
If files and include is not provided, TypeScript will automatically compile all files ( .ts, .tsx ) in the directory except for the...
Read more >
Configuring ESLint - ESLint中文文档
If you are using global variables inside of a file then it's worthwhile to define those globals so that ESLint will not warn...
Read more >
Working with JavaScript in Visual Studio Code
Type declaration files are written in TypeScript so they can express the data types ... JavaScript code that uses global variables or non-standard...
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