Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[New] create ignorePrivate option for no-multi-comp rule#3842

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
vwillyams wants to merge14 commits intojsx-eslint:master
base:master
Choose a base branch
Loading
fromvwillyams:export-only-multi-comp

Conversation

vwillyams
Copy link

@vwillyamsvwillyams commentedOct 18, 2024
edited
Loading

Adds a new option to no-multi-comp which ignores components that are not exported.

Currently WIP:

  • Thorough testing, find edge cases.npm test wasn't working locally so I'm hoping to rely on CI for this.
  • Comparisons between exports and React components probably needs more work. Maybe there's a pre-existing lib function for this. Maybe this functionality should be moved into lib.

@vwillyamsvwillyams changed the title[New] create exportOnly rule for no-multi-comp[New] create ignorePrivate option for no-multi-comp ruleOct 18, 2024
@@ -69,6 +69,55 @@ class HelloJohn extends React.Component {
module.exports = HelloJohn;
```

### `ignorePrivate`
Copy link
Member

Choose a reason for hiding this comment

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

"private" might not be the best name here. maybe "ignoreNonExported"?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I originally had this labeled asexportOnly but wanted to stick closer to theignoreStateless convention already established.

Copy link
Author

Choose a reason for hiding this comment

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

ignoreNonExported feels a little clunky to me but I can't think of anything better. just one of those hard problems in software.

Copy link
Member

Choose a reason for hiding this comment

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

yeah totally :-) "ignoreInternal"?

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good to me, switched over.

const ignorePrivate = configuration.ignorePrivate || false;

const exportedComponents = new Set(); // Track exported components
const validIdentifiers = new Set(['ArrowFunctionExpression', 'Identifier', 'FunctionExpression']);
Copy link
Member

Choose a reason for hiding this comment

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

i believe in react 19, async functions can be components as well.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah good point, I had not thought about RSCs.

Copy link
Author

Choose a reason for hiding this comment

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

Added a little coverage for this - I'm not an RSC dev by day though so may have made some oversights.

ljharb reacted with thumbs up emoji
Comment on lines 136 to 144
if (ignorePrivate) {
rule.ExportNamedDeclaration = (node) => {
exportedComponents.add(getExportedComponentName(node));
};

rule.ExportDefaultDeclaration = (node) => {
exportedComponents.add(getExportedComponentName(node));
};
}
Copy link
Member

Choose a reason for hiding this comment

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

instead of mutating maybe we could use Object.assign here?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah sure, sounds good. I'm not clear on why but I'm not super experienced in the eslint lifecycle and I can imagine that mutation may introduce issues somehow.

Copy link
Member

Choose a reason for hiding this comment

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

it probably doesn't matter much at all, but mutation generally risks slowdowns later, as opposed to creating objects all at once.

Copy link
Author

Choose a reason for hiding this comment

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

Switched over.

vwillyamsand others added3 commitsOctober 21, 2024 11:57
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
@vwillyams
Copy link
Author

FYI I will hopefully find time to have this ready for merge in the next 2-3 days. I'm going to get this working with RSCs and I also want to look at making the tests programmatically generated so that we can iterate over every possible permutation without having to write them all out individually (and risk missing something). In practice there's likely to be diminishing returns on that kind of testing but I assume that individual test cases are very cheap here and I don't really like the maintenance burden of the test cases I've added in this PR.

ljharb reacted with heart emoji

@vwillyams
Copy link
Author

FYI I'm currently iterating on the test coverage and making sure this works in all cases. I didn't entirely expect the amount of complexity that would go into this feature! But it's been a fun learning process.

ljharb reacted with heart emoji

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

@ljharbljharbljharb left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@vwillyams@ljharb

[8]ページ先頭

©2009-2025 Movatter.jp