Skip to content
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

Update React rules #43

Merged
merged 5 commits into from
Feb 27, 2019
Merged

Update React rules #43

merged 5 commits into from
Feb 27, 2019

Conversation

calebcassel
Copy link

@calebcassel calebcassel commented Jan 29, 2019

This PR includes some big updates to our React rules. 🎉

Many of these changes were done by manually merging code from Airbnb. Then I went through each Airbnb rule individually, disabled a few and adjusted the levels and configurations of others. The diff for this is difficult to look through, so I've broken down each rule change below. Please review each one and comment with any thoughts or concerns.

After bringing in the Airbnb changes, I also made some updates to the React README.md to bring it more in line with our rules. Finally, I made a few tweaks to the Docker build based on comments from my previous PR (#42). This would be the first release to use the new build.

Major Updates 💪

  • eslint-config-hudl now requires ESLint 4 or 5. This was previously on 3.

New Error Rules 🛑

Violating any of these will be counted as an error.

Fixable Errors 🔧

Each of these rules will also produce an error, but can be fixed automatically by running ESLint with the --fix parameter. These are all related to JSX formatting.

  • jsx-quotes
    Require double quotes in JSX attributes.

  • react/jsx-equals-spacing
    There should be no spaces around JSX equals signs, such as:
    <Hello name = {firstname} />
    <Hello name ={firstname} />
    <Hello name= {firstname} />

  • react/jsx-indent
    JSX should be indented with 2 spaces.

  • react/jsx-closing-tag-location
    Closing tags should be aligned with or on the same line as the opening tag.

  • react/jsx-tag-spacing
    Prevent spaces in JSX brackets, such as:

    • < Hello></Hello>
    • <Hello>< /Hello>
    • <Hello></Hello >

    A trailing space in a self-closing tag is okay: <Hello />

Updated rules ♻️

  • react/sort-comp
    We were previously enforcing an order of:
    • static-methods
    • lifecycle
    • everything-else
    • render

This PR adds two new cases to this rule:

  • instance variables must go after static-methods, but still before the constructor or lifecycle methods
  • any render* method must go at the bottom, before the final render()

New Warnings ⚠️

These are the more egregious issues that may be much more involved to fix. If these were full errors, it may make it difficult to update a repository to the new ESLint rules without having to disable several lines and then forgetting about those violations later. For that reason I have them configured as warnings, but I'm open to any pushback on this.

@Vannevelj
Copy link

I think the react/no-unused-state will cause errors in a piece of VSPA code around drawing on clips:

https://github.com/hudl/hudl-videospa/blob/4e26822664928e8fa0baddf28fd167876280ae83/src/client-app/app/shared/components/Drawing/Canvas/index.jsx#L57

It exposes the component's state by wrapping it in a function and passing that to classes outside of it. The implementation of the canvas specific for effects does not have this and it's all as it should be there but that would be one place with existing code that nobody will want to touch. That's not to say I don't think it's a valid rule, just something to be aware of. If you're going to have that as an error, there will be some extensive refactoring needed for that area.

@calebcassel
Copy link
Author

@Vannevelj Good to know. That sounds like a legitimate place we could use /* eslint-disable react/no-unused-state */ to let the build pass, as long as we all agree that this should apply generally and there aren't too many situations like that one.

@calebcassel calebcassel force-pushed the ReactRules branch 2 times, most recently from be77699 to cb4ab8f Compare February 26, 2019 20:37
@calebcassel calebcassel force-pushed the ReactRules branch 3 times, most recently from aee99d6 to f7aa154 Compare February 26, 2019 23:15
@calebcassel calebcassel merged commit 73e41a7 into master Feb 27, 2019
@calebcassel calebcassel deleted the ReactRules branch February 27, 2019 21:44
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.

2 participants