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.

Proposal: Add option to allow sync methods at root level in no-sync

See original GitHub issue

Current state

In Node.js, requiring or importing a file/module is synchronous. Therefore, making more synchronous calls does not hurt anyone, it just slows the loading process down a bit. I believe the rule’s intention is to warn people if they accidentally or intentionally make a blocking call in a place where it could seriously hurt performance (ie. in a hot code path etc.).

Currently, the no-sync rule is either enabled or disabled, ie. either you can use sync methods or you cannot.

Intended state

A new option is introduced to the no-sync rule: allowAtRootLevel (bool, default false) (exact name is subject to discussion, I don’t really think this is appropriate). With this option turned on, ESLint would not warn on sync calls appearing at the root level of the file.

Examples

// no-sync: [1, { allowAtRootLevel: true }]
// index.js
// ok - appears at root of the module
const contents = fs.readFileSync('/super/important.txt')

module.exports = function getImportant() {
  return contents
}
// no-sync: [1, { allowAtRootLevel: true }]
// index.js
module.exports = function getImportant() {
  // not ok - not at root level! (no change to current behaviour)
  return fs.readFileSync('/super/important.txt')
}

The goal is to avoid turning this rule off on a per-line basis at the root of the module when ie. contents of a file are required for the module to operate.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
VictorHomcommented, Jun 25, 2017

If no has started any work, can I jump in to help out with a pr?

1reaction
platinumazurecommented, May 1, 2017

@robertrossmann Thanks for following up! We need the rest of the team to take a look. Unfortunately it looks like this just completely slipped through the cracks, and for that I apologize.

This enhancement seems reasonable to me (helps that it proposes an option rather than change in default behavior), so I’ll champion this.

@eslint/eslint-team Could we give this a review? Just need three 👍s or, if this doesn’t seem like a good enhancement, let’s talk it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Settings Don't Sync in Active/Passive HA?
You must configure the following settings on each firewall in an HA pair in an active/passive deployment. These settings do not sync from...
Read more >
User Guide - Tasktop Sync
Tasktop Sync provides a comprehensive UI for configuring synchronization mappings between pairs of repositories and tasks. The task mapping editor allows users ...
Read more >
Dell Unity: Replication Technologies
This paper outlines the native and non-native options available for replicating data. It also includes information about managing replication, ...
Read more >
Object Gateway Guide Red Hat Ceph Storage 5
An alternative method of defining a logical host name is to define the location of the CRUSH map for ... Root-level access to...
Read more >
Domain Time II Configuration - Greyware Automation Products
protocol available to allow synchronization with Domain Time II Servers over ... Time clients by setting the W32Time service's client portion to "NoSync"....
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