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.

no-use-before-define - Add option for specific ignores (like useStyles)

See original GitHub issue

What rule do you want to change? no-use-before-define - new option

Does this change cause the rule to produce more or fewer warnings? Fewer, and the option would report fewer errors if specified.

How will the change be implemented? (New option, new default behavior, etc.)? New option for ignoring user-specified variables like useStyles, to allow less-important styles to be relocated to the bottom, or potentially other cases where you might want to save uninteresting variables for last, as a pattern throughout an entire codebase.

Please provide some example code that this change will affect:

import { makeStyles } from '@material-ui/core';

function MyComponent() {
  const classes = useStyles();
  return <div className={classes.myDiv}>Stuff</div>;
}

const useStyles = makeStyles({
  myDiv: {
    backgroundColor: '#ddd';
  }
});

What does the rule currently do for this code? An error is reported because useStyles is defined after it’s used, though in this context it’s safe because React components are instantiated and run their code after the file has finished defining all variables.

What will the rule do after it’s changed? This code would not report an error - useStyles could be specified as an exception to the no-use-before-define

Are you willing to submit a pull request to implement this change? …Quite possibly, though I only have minimal experience with eslint rule code.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jeffvandykecommented, Jun 26, 2020

Thanks for informing me about that change, was not aware! I’ll be sure to look into eslint-rule-composer, though that might be its own challenge 😃

1reaction
kaicataldocommented, Jun 26, 2020

Thanks for the explanation. This sounds to me like it falls under our new policy to freeze stylistic rules (please see https://eslint.org/blog/2020/05/changes-to-rules-policies for more details).

The good news is that this should be fairly easy to enforce by creating a custom rule using eslint-rule-composer!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLint no-use-before-define - javascript - Stack Overflow
It looks like you might be interested in the variables option, ... Otherwise, the rule ignores a reference if the declaration is in...
Read more >
no-use-before-define - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Design Patterns with React Easy State | by Bertalan Miklos
React Easy State is a transparent reactive state management library with two functions and two accompanying rules. Always wrap your components with view()...
Read more >
@mui/styled-engine | Yarn - Package Manager
This package is a wrapper around the @emotion/react package. It also provides a shared interface that can be used with other styled engines,...
Read more >
no-use-before-define - TypeScript ESLint
Options ​. See eslint/no-use-before-define options. This rule adds the following ... If this is true , this rule ignores all type references, such...
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