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.

False positive for global-require

See original GitHub issue

Tell 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:closed
  • Created 6 years ago
  • Comments:26 (23 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, Jul 14, 2017

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.

1reaction
platinumazurecommented, Jul 13, 2017

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:

  • global-require ensures that any call to (non-shadowed) require() must be in global or module scope, i.e., not in a block or function scope. It does not care about how the require() is invoked.
  • New rule no-conditional-require ensures that require() calls cannot be in a ConditionalExpression or LogicalExpression.

Would that make sense?

Read more comments on GitHub >

github_iconTop 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 >

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