False positive for global-require
See original GitHub issueTell us about your environment
- ESLint Version: 4.0.0
- Node Version: 7.10.0
- npm Version: 5.0.3
What parser (default, Babel-ESLint, etc.) are you using? default
Please show your full configuration:
{
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"rules": {
"global-require": "error"
}
}
What did you do? Please include the actual source code causing the issue. This code is at the top level of the file:
var botVersion = process.env.npm_package_version || require('./package.json').version;
What did you expect to happen? I expect this code to work without warnings, as the statement is at the top level of the file. Notably, as the documentation of the global-require rule states, using a ternary operator instead gives no warnings:
var botVersion = process.env.npm_package_version ? process.env.npm_package_version : require('./package.json').version;
And the documentation for the no-unneeded-ternary rule asserts that using a logical OR operator should provide “the same functionality” as a ternary in this case.
What actually happened? Please include the actual, raw output from ESLint. ESLint gives a warning:
1:53 error Unexpected require() global-require
Issue Analytics
- State:
- Created 6 years ago
- Comments:26 (23 by maintainers)
Top Results From Across the Web
Typescript + Eslint false positive for imports + `declare global`
1 Answer 1 ... Turn off "no-undef": "off"(disallow the use of undeclared variables unless mentioned in /*global */ comments) and to be handled...
Read more >False-Positive Results in Rapid Antigen Tests for SARS-CoV-2
This study examines the incidence of false-positive results in a sample ... requirements of deploying rapid antigen screens in workplaces.
Read more >Factors Associated with False-Positive Results from ...
Testing a larger population with lower disease prevalence will lead to an increase in false-positive tests. These developments, therefore, merit further efforts ...
Read more >Address false positives/negatives in Microsoft Defender for ...
Learn how to handle false positives or false negatives in Microsoft Defender for Endpoint.
Read more >False Positive Rate - Feature Flag Management Platform
Glossary /. False Positive Rate. False positive rate (FPR) is a measure of accuracy for a test: be it a medical diagnostic test,...
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 Free
Top 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
Lumping everything into
no-restricted-syntax
makes it really hard to configure in a shared config, because there’s no way to specify in JSON/YML that I want to add to the existing array of restricted syntaxes - which means I have to gather up and copy/paste the entire list from wherever it’s defined.It seems to me that this rule might be taking on too much responsibility. I think we should consider splitting this into two rules with ESLint 5.x:
require()
must be in global or module scope, i.e., not in a block or function scope. It does not care about how therequire()
is invoked.require()
calls cannot be in a ConditionalExpression or LogicalExpression.Would that make sense?