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.

Add setting to disallow "arrow function declarations" at the global/top level

See original GitHub issue

I would like to forbid top level function declarations that use arrow syntax. This works using global.

const bad = () => {
  console.log('bad');
};

But I would like to allow top level arrow functions present within a function call. I cannot get this to work because these are considered global. I recognize they are indeed global. I would like to carve out an exception here. This issue here blocks me from being able to benefit from this plugin and I am going to have to disable it.

const things = [].map(x => console.log('eh, this is ok, it is in a function call');

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
getifycommented, Apr 26, 2021

I debated on what to call it… maybe I made the wrong call here, but I felt like camel-casing would make things more confusing.

1reaction
jfroelichcommented, Apr 26, 2021

This worked exactly how I wanted it to:

{
    "@getify/proper-arrows/where": [
      "error",
      {
        "global": false,
        "global-declaration": true,
        "property": false,
        "export": false,
        "trivial": false
      }
    ]
}

This is an error:

// arrow function declaration
export const topLevelArrowBad = (test: string) => {
  console.log(test);
};

This is not an error:

// arrow function
process.on('unhandledRejection', error => {
  console.log(error);
});

This is not an error:

async function main() {
  console.log('main');
}

main().catch(console.error);

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

getify/eslint-plugin-proper-arrows - GitHub
Placing => arrow functions in the global/top-level-module scope has no benefit other than preferred style; they're more proper as regular function declarations.
Read more >
Arrow function expressions - JavaScript - MDN Web Docs
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate ...
Read more >
Understanding Arrow Functions in JavaScript | DigitalOcean
In this article, you will review function declarations and expressions, learn about the differences between traditional function expressions and ...
Read more >
Learning JavaScript functions and how you should use them
Function names are either global or local, depending on whether the function is at the program's top level or nested inside a class,...
Read more >
Struggling with TypeScript, React, Eslint and simple Arrow ...
In case you want to support both "arrow-function" & "function-declaration", set the value to an array of strings. Consider my setup as below....
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