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

Improvement/hoc react functional modules #355

Closed

Conversation

Vadko
Copy link

@Vadko Vadko commented Jun 6, 2022

Description

Solution in relevant pull request complements one of previous fixes related to the React functional components: #219

Related Issues

Fix that included in mentioned above PR resolves issue about cognitive complexity score redundancy when using React functional components with additional score for nested if else condition inside of functional component methods. It works as expected, but the problem comes up when we are wrapping our functional component with HOC - in my case it was memoization function which are often used inline - this leaded to same issue with redundant +1 score for nested conditions in methods.

For fixing that, I've decided to look for a parent node name with additionally considering if we are returning JSX element/fragment to properly check is that a functional component or not.

Tests

I added the following test in cognitive complexity rule tester:

 {
      code: `
      const Welcome = memo(() => {
        const handleSomething = () => {
          if (x) {} // +1
        }
        if (x) {} // +1
        return <h1>Hello, world</h1>;
      })`,
      parserOptions: { ecmaFeatures: { jsx: true } },
      options: [0],
      errors: [message(1, { line: 2 }), message(1, { line: 3 })],
    }

Test Suites: 34 passed, 34 total
Tests: 561 passed, 561 total
Snapshots: 0 total
Time: 6.116 s

@saberduck
Copy link
Contributor

we did some improvements to cognitive complexity and JSX interaction, I think it's sufficient now.

@saberduck saberduck closed this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants