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

feat: extend the functionality of inconsistent-naming #166

Open
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

illright
Copy link
Member

@illright illright commented Jan 9, 2025

Closes #8

Extends the functionality of inconsistent-naming to support multi-word names and handle rename collisions

@illright illright requested a review from daniilsapa January 9, 2025 13:36
Copy link

changeset-bot bot commented Jan 9, 2025

🦋 Changeset detected

Latest commit: a9b25be

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@feature-sliced/steiger-plugin Minor
steiger Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Collaborator

@daniilsapa daniilsapa left a comment

Choose a reason for hiding this comment

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

High-quality code as always. I have only several minor suggestions/questions. Thank you!

I highly appreciated the get-main-subject utility, it is a great example of good logic! 👍

The corresponding issue also has a subtask about auto-fixes. As I see, the auto-fixes have already been added to this rule. Can we consider that subtask as done?

])
})

it('allows inconsistency between different slice groups', () => {
Copy link
Collaborator

@daniilsapa daniilsapa Jan 16, 2025

Choose a reason for hiding this comment

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

Should this one also be renamed to entity instead of slice, like the other test case names?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, indeed

expect(diagnostics).toEqual([
{
message: 'Inconsistent pluralization of slice names. Prefer all plural names',
message: 'Inconsistent pluralization of entity names. Prefer all plural names.',
fixes: [
{
type: 'rename',
Copy link
Collaborator

Choose a reason for hiding this comment

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

(non-blocking): Should it prefer singular names in this case (when it's 50/50)? It looks to me as a more favorable convention, which is more common in documentation examples, etc

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I didn't really think about it before, I agree

@@ -82,3 +112,48 @@ it('prefers the singular form when there are more singular slices', () => {
},
])
})

it('recognizes the special case when there are two pluralizations of the same name', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

when there are two pluralizations of the same name

It seems a little misleading, more like a typo, should it be "when there is a plural and singular form of the same name"

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds good!

const message = 'Inconsistent pluralization of entity names'
if (
pluralNames.length >= singularNames.length &&
singularNames.some(([name]) => !duplicates.singular.includes(name))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we filter the duplicates out somewhere at the top at once? Just keep the code a bit cleaner and remove the need to filter out the duplicates in 4 places

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll try, but the logic here is pretty convoluted, so maybe it won't work, no promises :)

@illright
Copy link
Member Author

I marked the autofixes task as incomplete because it didn't yet support the cases where there's a singular and a plural form. It should be done completely with this PR

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.

2 participants