core icon indicating copy to clipboard operation
core copied to clipboard

Pluralization is broken

Open ShahriarKh opened this issue 1 year ago • 19 comments

Package version

6.2.2

Describe the bug

When I want to create new models or controllers (and probably other things), the name formatter behaves wrongly in some cases. For example, try:

node ace make:model cookies

This creates cooky.ts!

This happens for many other words, including made-up words.

I investigated a bit, and seems like the problem comes from pluralize library which is used under the hood by poppinss/utils. Pluralize was last updated in 2019, and has many open pull requests.

So, 3 possible solutions come to my mind:

  1. replace pluralize or fork it to fix this bugs and avoid conversion of made-up words
  2. add a flag for all make:* commands to prevent this auto fix.
  3. instead of changing the word automatically, add an extra step in cli to ask users if they want their new controller/model/... name to be changed or not... something like:
    Do you want to change "CookiesCOntroLLer" to "cooky"? (Y/n)

Reproduction repo

No response

ShahriarKh avatar Apr 12 '24 18:04 ShahriarKh

Don't try to switch to the fancy compromise library; which is an amazing lib.. but it gets this wrong too. I was about to post that this would be a great alternative, but it's not. Demo: https://codesandbox.io/p/sandbox/compromise-forked-h2vg55

kyr0 avatar Apr 12 '24 22:04 kyr0

Not sure what really the solution is, if most of the popular libs get it wrong.

But I agree, bypassing the transformation with a flag seems like a nice middle ground. Not in favor of a prompt.

thetutlage avatar Apr 22 '24 06:04 thetutlage

Or maybe some config in package.json or elsewhere:

"autoFixNames": {
  "controllers": "always",
  "models": "never",
  ...
}

This also introduces the possibility of letting devs choose their naming conventions. For example: "models":"PascalCase"

I know it makes it more complex to implement, but it has its use cases.

ShahriarKh avatar Apr 22 '24 07:04 ShahriarKh

Or maybe some config in package.json or elsewhere:

"autoFixNames": {
  "controllers": "always",
  "models": "never",
  ...
}

This also introduces the possibility of letting devs choose their naming conventions. For example: "models":"PascalCase"

I know it makes it more complex to implement, but it has its use cases.

People can already change all scaffolding option https://docs.adonisjs.com/guides/scaffolding

RomainLanz avatar Apr 22 '24 07:04 RomainLanz

Oh, so I think the flag is the way to go. The CLI should either use defined (or default) naming conventions and do the autofix, or skip them and use the provided name if a flag is present.

ShahriarKh avatar Apr 22 '24 07:04 ShahriarKh

The best option would probably be, to impement and release a decent pluralization lib based on wordnet dataset, or else. Idk if I'll find the time to do that, but that's basically the only accurate solution. Grammar rules won't ever catch all the fish there is. It could be fun to optimize this by computing a xor checksum on the diff of the dataset that works well by grammar rule computation (optimization on-disk index size), and have a lookup table for all else words that fail. Re-building the lib automatically when a new mistake is reported, for maintainers to quickly include fixes from upstream. Would be fun.. and a nice example for my brotli compress lib xD

kyr0 avatar Apr 23 '24 15:04 kyr0

Seems it was fix on pluralize github version not on the npm version according to this issue

rnwonder avatar Jun 19 '24 05:06 rnwonder

This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue

github-actions[bot] avatar Jan 13 '25 00:01 github-actions[bot]

Keep open

RomainLanz avatar Jan 13 '25 08:01 RomainLanz

This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue

github-actions[bot] avatar Feb 04 '25 00:02 github-actions[bot]

Oooooh, this is a tricky one.

dunhamjared avatar Feb 06 '25 00:02 dunhamjared

When I have some time (which might not be soon), I'll develop a new module using the Doctrine Inflector API to replace our current pluralization API. It'll be a framework-agnostic package under the BoringNode organisation.

RomainLanz avatar Feb 06 '25 07:02 RomainLanz

This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue

github-actions[bot] avatar Feb 28 '25 00:02 github-actions[bot]

This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue

github-actions[bot] avatar Mar 22 '25 00:03 github-actions[bot]