Skip to content

Conversation

@jinmayamashita
Copy link
Collaborator

@jinmayamashita jinmayamashita commented Mar 7, 2024

Pull Request Checklist

  • I have checked that this pull request is not a duplicate of a pre-existing pull request
  • I have self-reviewed my changes
    • There are no spelling mistakes
    • There are no remaining debug log prints (i.e. console.log())
    • Comments were written for complex code
  • I have checked that all tests are passing (for bug fixes and enhancements)
    • CLI Test (npm run test:cli)
    • Unit Test (npm run test:modules)
    • E2E Test (npm run e2e)
  • I have added and/or modified relevant tests for my changes (for bug fixes and enhancements)
  • I have added and/or modified relevant documentations for my changes (if necessary)

Description

This is a PR for discussing rules in the codebase. Let's start by evaluating whether the ESLint rules are appropriate. (Considering if anything has been overlooked or if there's overkill, etc.)
Feel free to also discuss Biome mentioned in #1201 (comment)

FYI @mvn-huynguyen-hn @mvn-tiennguyen-hn

Context

#1201 (comment)

@changeset-bot
Copy link

changeset-bot bot commented Mar 7, 2024

⚠️ No Changeset found

Latest commit: 5c2db40

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@jinmayamashita jinmayamashita requested a review from ptrkdan March 7, 2024 22:42
@jinmayamashita jinmayamashita self-assigned this Mar 7, 2024
@jinmayamashita jinmayamashita changed the title Coding rule and convention with auto lint Proposals for ESLint rules regarding React app Mar 7, 2024
{
files: ['**/*.{jsx,ts,tsx}'],
rules: {
'react/jsx-pascal-case': 2,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote it in the discussion page, but I would like to discuss whether setting the severity to 2 (error) is appropriate.

It may be beneficial, especially for beginners, to enforce best practice, although it may become an annoyance to more experienced developers. Of course, it will vary on the rule, so I'd like to discuss with this in mind.

Regarding naming conventions, it may be enough to set it to 1 (warning).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptrkdan Normal syntax errors such as quotes and semicolons do not have a big impact on the normal working flow. I think these errors should be in the form of warning. For errors that affect the entire team's work flow, such as file name and export method, I think we should set level to error.

Copy link
Collaborator Author

@jinmayamashita jinmayamashita Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptrkdan The main reason for setting rule error is to prevent human oversight during code reviews. (Most of rule error is related to team development guidelines. If the rules are defined to a reasonable extent without being overwhelming, it might eliminate the need to explain them, and violations can be caught by CI failures, relieving reviewers from having to worry about them.)

If there are rules that may become noise for experienced developers, I believe it's possible to discuss and adjust them to rule warning.

extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:unicorn/recommended',
Copy link

@mvn-tiennguyen-hn mvn-tiennguyen-hn Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jinmayamashita It is so big plugin. Because it has more than 100 eslint rules, I wonder if there are any rules that conflict with the rules from other official plugins 🧐

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvn-tiennguyen-hn It is indeed so. I have added rules to ensure code efficiency, avoiding duplication with other rules, and enforcing them as errors rather than warnings regarding team development rules. bcdb969

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest the following rules to be added

"no-unused-vars": 2,
"no-var": 2,
"prefer-const": 2,
"no-eval": 2,
"no-magic-numbers": 2,

Copy link
Collaborator Author

@jinmayamashita jinmayamashita May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seiya0914

Thank you for the proposal! I've reviewed rules and it looks good, so I've added it.

ea971a3

It would be helpful if you could discuss with @mvn-luanvu-hn whether to approve the PR after reviewing the final rules.

@jinmayamashita jinmayamashita requested a review from seiya0914 May 13, 2024 08:49
Copy link
Collaborator

@mvn-luanvu-hn mvn-luanvu-hn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jinmayamashita Thank you for your work! 🙇 I left some comments. Please help to check them.
In addition, we can change to new config system of eslint v9 later: https://eslint.org/blog/2023/10/flat-config-rollout-plans/

"no-eval": 2,
"no-magic-numbers": 2,
"unicorn/filename-case": [2, { case: "kebabCase" }],
"react/jsx-filename-extension": [2, { extensions: [".tsx"] }],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add the following rule to disable when not import React in the component file

'react/react-in-jsx-scope': "off",

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, we should add React Compiler's ESLint plugin to prepare our code to adapt to React Compiler in the future
https://react.dev/learn/react-compiler#installing-eslint-plugin-react-compiler

Copy link
Collaborator Author

@jinmayamashita jinmayamashita May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add the following rule to disable when not import React in the component file

We can add this plugin. I'll check it.

https://github.com/jsx-eslint/eslint-plugin-react/blob/577cb64fb6/README.md#configuration

If you are using the new JSX transform from React 17, extend react/jsx-runtime in your eslint config (add "plugin:react/jsx-runtime" to "extends") to disable the relevant rules.

rules: {
'no-console': 2,
eqeqeq: 2,
"no-unused-vars": 2,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use only single quotes or double quotes.

Copy link
Collaborator Author

@jinmayamashita jinmayamashita May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you.

@mvn-luanvu-hn @seiya0914
What’s the difference between double and single quotes?
Can your team decide on the best practice?

@jinmayamashita jinmayamashita mentioned this pull request Jun 14, 2024
1 task
@jinmayamashita
Copy link
Collaborator Author

jinmayamashita commented Jun 27, 2024

FYI @mvn-luanvu-hn @seiya0914
The PR has been open for quite some time.
As Luan mentioned, it might be better to migrate to ESLint 9.

#1208 (review)
In addition, we can change to new config system of eslint v9 later: https://eslint.org/blog/2023/10/flat-config-rollout-plans/

e.g. https://github.com/jinmayamashita/sandbox-nextjs-eslint/commit/64094658cabe2b4d6588d245d3872275e33d86ec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants