-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Add an ESLint rule to prevent the usage of useRef other than for HTML elements. #2014
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
Conversation
… elements Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Apply Sweep Rules to your PR?
|
charlesBochet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was quick! Left a comment :)
| @@ -0,0 +1,39 @@ | |||
| "use strict"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not commit dist file.
Let's actually add dist folder to gitignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charlesBochet dist in eslint-plugin-twenty is ignored, but eslint-plugin-twenty-ts was added and I figured, perhaps it serves a special purpose, hence the commits and updates
| 'plugin:prettier/recommended', | ||
| 'plugin:storybook/recommended', | ||
| 'react-app', | ||
| 'plugin:react/recommended', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm moving to these plugins as the react-app config is not compatible with the newer eslint version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright
| { | ||
| files: ['*.js', '*.jsx', '*.ts', '*.tsx'], | ||
| rules: { | ||
| 'react/no-unescaped-entities': 'off', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disabling these as the new plugin is stricter. I think it would be great to reactivate jsx-key one, others do not seem that useful (I'm not sure about prop-types)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright
| "chromatic": "dotenv cross-var npx chromatic --project-token=$CHROMATIC_PROJECT_TOKEN", | ||
| "install": "yarn eslint-plugin:setup" | ||
| }, | ||
| "eslintConfig": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing this section as we use .eslintrc
|
|
||
| const noStateUseRef = createRule({ | ||
| create: (context) => { | ||
| return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gitstart-twenty we prefer this way of writing if condition that avoids making a complex conditions and enforce runtime typing properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright
| ], | ||
| }, | ||
| { | ||
| code: "const ref = useRef<string>('');", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added this case that was not taken into account
| return; | ||
| } | ||
|
|
||
| if (!node.typeArguments || !node.typeArguments.params?.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using typeArguments instead of typeParameters which is deprecated :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charlesBochet I saw this and made the necessary changes but then reverted them after I noticed the rule wasn't behaving as expected. This is because the AST generated by @typescript-eslint/parser uses typeParameters and not typeArguments
|
@gitstart-twenty I've left a few comments, please have a look for next times :) |
Thanks for the update |
Fixes #1996