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.

global-require should allow `require` statements as properties in object literals

See original GitHub issue

eslint version: ^1.4.1

rule config: "global-require": 1

Assuming I have a folder structure like this

/ app 
   / validators
      - validate-string.js
      - validate-number.js
      - index.js

And /app/validators/index.js

// index.js
module.exports = {
  string: require('./validate-string'),           // this violates global-require rule
  number: require('./validate-number')
};

It does not make sense to me that this is a violation.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nzakascommented, Oct 5, 2015

@jamestalmage you can always create your own rule to do this. The fact is, once you add in enough exceptions then the rule is no longer doing what it was intended to do, and that’s when people get confused. That’s why we allow custom rules - you don’t have to convince us, just write a rule that does exactly what you want.

1reaction
ilyavolodincommented, Oct 5, 2015

Agree. This rule was created to make sure that all require statements are clearly marked at the top of the file. If you don’t follow that pattern - just turn off this rule.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with objects - JavaScript - MDN Web Docs - Mozilla
The same way, JavaScript objects can have properties, ... object literal in parentheses if the object appears where a statement is expected, ...
Read more >
Self-references in object literals / initializers - Stack Overflow
The return statement both creates the replacement property foo.c and returns its value. It would be possible to use get c() { return...
Read more >
Rules - ESLint - Pluggable JavaScript Linter
The "extends": "eslint:recommended" property in a configuration file enables this rule ... Require grouped accessor pairs in object literals and classes.
Read more >
List of available rules - ESLint - Pluggable JavaScript linter
disallow calling global object properties as functions. no-prototype-builtins ... require return statements to either always or never specify values.
Read more >
tslint-eslint-rules - npm Package Health Analysis | Snyk
You can connect your project's repository to Snyk to stay up to date on security ... enforce spacing between keys and values in...
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