-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[no-use-before-define] 'React' was used before it was defined on edited code #2540
Comments
React scripts does not use the latest versions of our packages yet, so likely your lint is using the wrong versions. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
To anybody responding here. Neither comments help us diagnose the problem. Please, please, please include relevant information. HELP ME TO HELP YOU (Note that including the versions from your As it stands right now. I cannot repro this against master. That means that either:
I'll say again here: |
My own config complains the same linter error: To add context, the image above is from a TSX file with element declarations: https://github.com/LXSMNSYC/scoped-model/blob/master/packages/react-scoped-model/src/create-model.tsx Interestingly, function types complains about Edit: Regardless, nothing changes if I add or remove these rules: "no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error"],
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": ["error"], Edit 2: |
To reproduce the issue, see this sample app. Reproduction steps, see this workfow:
Error, see this CI build:
Hope this helps, even if this sample app uses |
You need to wait for 3rd party tool with dependencies on our tooling to upgrade@lxsmnsyc - your example repo uses https://github.com/LXSMNSYC/scoped-model/blob/master/yarn.lock#L9749-L9750 @hb0 - your example repo uses https://github.com/hb0/typescript-eslint_issue-2540/blob/master/package-lock.json#L11661-L11682 It coordinates the lint run during the webpack run, and as such it uses its dependencies, not the root dependencies. As I mentioned earlier - if you're running into this issue, please check your If you find an entry in your file that is less than |
@bradzacher I'm currently working on a cleanup where I am removing TSDX in favor of my own setup. The problem still persists. |
We have passing tests for this exact case in master, which is why I believe that this is due to incorrect package versions locally in your projects. typescript-eslint/packages/eslint-plugin/tests/rules/no-use-before-define.test.ts Lines 294 to 345 in f785965
If someone can create an isolated repro with just our packages, then I am happy to dig more into this. Without that - there's only so much I can do to look into here. |
This comment has been minimized.
This comment has been minimized.
I have removed everything unrelated to eslint in this example repo. Look in the App.tsx for the two errors.
|
https://github.com/a-heryani/typescript-eslint-test/blob/master/.eslintrc#L3 You extend airbnb, which turns on Your config never turns it off, nor does it turn on our version of the rule ( This is listed in the FAQ: https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md#i-am-using-a-rule-from-eslint-core-and-it-doesnt-work-correctly-with-typescript-code For the This is not a false positive. JSX is a 3rd party global type (defined in See the docs on |
Thanks @bradzacher. I can confirm that following works.
Got it. I pruned @types/react when I was cleaning package.json for the repo. Thanks. |
I believe this was fixed in react-scripts now: facebook/create-react-app#9434 |
Yup - thanks for linking it. Once it's released, users will be able to upgrade and they will no longer have old versions of our packages installed. I'm going to close this, as there isn't a repro. |
If you encounter this error, then do the following, in this order: (1)Check your ESLint config - you MUST be using (2)In some cases, your Try deleting your (3)Check your local install for old versions of our tooling. You can use one of the following commands to do so: $ npm list @typescript-eslint/eslint-plugin @typescript-eslint/parser
$ yarn list @typescript-eslint/eslint-plugin @typescript-eslint/parser If you see any versions that do not start with |
Repro
This is some strange error I incur.
Create a new react app with typescript using CRA
and add @typescript-eslint/eslint-plugin and @typescript-eslint/parser
In package.json update all the packages to the latest versions (either using
ncu
or manually) and removeCreate a
.eslintrc.js
file with the following code:To enable react-scripts to parse this file, create a
.env
file with this content:And now,
npm start
The app compiles and complains about some functions return types not specified. Standard stuff. The browser opens as expected and display the default page as usual for a fresh project.
And now the "curious" part. If I edit any file, for example if I remove
import './index.css';
fromindex.tsx
file, compiler emits an error:If i restore the old code, everything is back fine.
On issue #2502, user linonetwo suggested to add these rules (also FAQs give this hint)
But with no luck for me.
I believe that ESLint version is 6.8.0 as it comes with
"react-scripts": "3.4.3"
Versions
@typescript-eslint/parser
4.1.0
TypeScript
4.0.2
ESLint
6.8.0
node
14.10.1
The text was updated successfully, but these errors were encountered: