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.

Enabling globals only for part of a file

See original GitHub issue

@platinumazure suggested that I open this issue. I’m not sure which template it fits, so I’m just beginning discussion.

In the example below puppeteer uses window, document etc in Node without providing them as function parameters, and I don’t want ESLint to complain about that, but I also don’t want them available outside the puppeteer functions which use them. I tried to fix it using directives:

const results = await page.evaluate(selector => {
  /* global document:readonly */
  const titleNodes = [...document.querySelectorAll(selector)];
  const titles = titleNodes
    .filter(node => node.textContent.includes('. '))
    .map(node => node.textContent.trim());
  return titles;
  /* global document:off */
}, selector);

However, those directives don’t work as I thought they would. Apparently, they only apply to the entire file, unlike

/* eslint-disable rule */
// targeted code
/* eslint-enable rule */

@platinumazure suggested no-undef as a workaround, but I want more precision than that.

I’m wondering if this can be solved as a new option related to globals on the no-undef rule or something entirely different.

What are your thoughts?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
eslint-deprecated[bot]commented, Apr 18, 2020

Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

0reactions
jsejcksncommented, Apr 18, 2020

@eslint I know you don’t really mean that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

disable certain global types for specific files, or ... - GitHub
The idea here is that some option would allow us to specify which files certain types or typeRoots apply to, and our configuration...
Read more >
python - Using global variables between files? - Stack Overflow
The problem is you defined myList from main.py , but subfile.py needs to use it. Here is a clean way to solve this...
Read more >
Working with the GLOBALS File - GoldenGate
From the Oracle GoldenGate installation location, run GGSCI and enter the following command, or open a file in a text editor. Copy. EDIT...
Read more >
Enable global file locking - Product documentation
Global file locking requires the clusters containing the origin and all associated caches to be running ONTAP 9.9.1 or later. Global file ......
Read more >
no-implicit-globals - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
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