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:
- Created 4 years ago
- Reactions:1
- Comments:11 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@eslint I know you don’t really mean that.