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

ESLint: jsx-max-depth #7819

Closed
wants to merge 1 commit into from
Closed

ESLint: jsx-max-depth #7819

wants to merge 1 commit into from

Conversation

grahamlangford
Copy link
Collaborator

@grahamlangford grahamlangford commented Mar 5, 2024

What does this PR do?

Discussion

Future Work

  • Once rule is implemented completely, migrate to eslint-config-pixiebrix

Checklist

  • Designate a primary reviewer

Copy link

codecov bot commented Mar 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.54%. Comparing base (93c88b6) to head (bf527c7).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7819      +/-   ##
==========================================
- Coverage   72.56%   72.54%   -0.03%     
==========================================
  Files        1274     1274              
  Lines       39834    39834              
  Branches     7399     7399              
==========================================
- Hits        28905    28897       -8     
- Misses      10929    10937       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BLoe
Copy link
Collaborator

BLoe commented Mar 5, 2024

I would be open to this, but I think there are exceptions where nesting deeply makes the code more readable, such as top level App components that need to nest a lot of Providers/Wrappers/etc. I wouldn't want to force ourselves to arbitrarily split those up into multiple stacks of nested 1-line component calls, so we'd just need to suppress this lint rule at those places.

@grahamlangford
Copy link
Collaborator Author

I would be open to this, but I think there are exceptions where nesting deeply makes the code more readable, such as top level App components that need to nest a lot of Providers/Wrappers/etc. I wouldn't want to force ourselves to arbitrarily split those up into multiple stacks of nested 1-line component calls, so we'd just need to suppress this lint rule at those places.

This is fair. But I would suggest that those situations would be so rare we could readily eslint-ignore those.

@fregante
Copy link
Collaborator

fregante commented Mar 5, 2024

I agree with Ben. This rule only makes sense if we view it as an opportunity to break up larger components into smaller ones, however I'm not entirely convinced:

  • that this won't just be ignored
  • that it offers a meaningful solution to this at 5 levels

I do like some sort of hard limit on excessive code though, but only when it's very obviously "bad" and hard to follow: "10K LOC files", "1K LOC functions", "20 nested levels".

The complexity rule is similar to this and still has a few suppressions in the codebase, even as a warning. I have low hopes for this at 5 levels.

@grahamlangford
Copy link
Collaborator Author

I agree with Ben. This rule only makes sense if we view it as an opportunity to break up larger components into smaller ones, however I'm not entirely convinced:

  • that this won't just be ignored
  • that it offers a meaningful solution to this at 5 levels

I do like some sort of hard limit on excessive code though, but only when it's very obviously "bad" and hard to follow: "10K LOC files", "1K LOC functions", "20 nested levels".

The complexity rule is similar to this and still has a few suppressions in the codebase, even as a warning. I have low hopes for this at 5 levels.

Here's an example of one of the violations. Breaking this up into smaller components would dramatically increase clarity.

return (
<Modal
className={cx(styles.root, modalClassName)}
show
centered
size="xl"
onHide={close}
backdrop
keyboard={false}
>
<Modal.Body className={styles.body}>
<Container fluid>
<Row>
<Col xs={5} className={styles.results}>
<Form>
<InputGroup>
<InputGroup.Prepend>
<InputGroup.Text>Search</InputGroup.Text>
</InputGroup.Prepend>
<Form.Control
ref={searchInput}
placeholder="Start typing to find results"
value={query}
onChange={({ target }) => {
setQuery(target.value);
}}
/>
</InputGroup>
</Form>
<div>
<AutoSizer>
{({ height, width }: Size) => (
<LazyList
height={height}
width={width}
itemCount={searchResults.length}
itemSize={brickResultSizePx}
itemKey={itemKey}
itemData={
{
searchResults,
setDetailBrick,
activeBrick: detailBrick,
selectCaption,
onSelect,
close,
} as ItemType<T>
}
>
{ItemRenderer}
</LazyList>
)}
</AutoSizer>
</div>
</Col>
<Col
xs={7}
className={cx(styles.brickDetail)}
key={detailBrick?.id}
>
{detailBrick ? (
<BrickDetail
brick={detailBrick}
listing={listings[detailBrick.id]}
selectCaption={selectCaption}
onSelect={() => {
onSelect(detailBrick);
close();
}}
/>
) : (
<QuickAdd
onSelect={(brick) => {
onSelect(brick);
close();
}}
recommendations={recommendedBricks}
/>
)}
</Col>
</Row>
</Container>
</Modal.Body>
</Modal>
);
}

Number of levels is something I'm definitely willing to have a discussion on. I honestly picked 5 more or less at random. Just a "feels kinda right" amount.

If we were to merge the rule, I would argue to keep it on "error" and actually fix everything. We should also look at actually enforcing our complexity rule finally in a separate DevEx ticket.

@twschiller
Copy link
Contributor

Closing in favor of: #7865

@twschiller twschiller closed this Mar 9, 2024
@fregante fregante deleted the eslint-jsx-max-depth branch March 9, 2024 12:37
fregante added a commit that referenced this pull request Mar 13, 2024
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.

None yet

4 participants