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

filename-case: pascalCase should allow stuff like FAQPage.js #2310

Open
mmkal opened this issue Apr 5, 2024 · 0 comments
Open

filename-case: pascalCase should allow stuff like FAQPage.js #2310

mmkal opened this issue Apr 5, 2024 · 0 comments

Comments

@mmkal
Copy link
Contributor

mmkal commented Apr 5, 2024

We have components called FAQPage.js, DIYWidget.js, etc. We're getting unicorn/filename-case errors on these, but I don't think we should.

I couldn't find an authoritative definition of what to do with acronyms-at-the-start-of-strings in pascal case online, or even an authoritative definition of pascal case generally. But I think it'd be better if this rule erred on the side of permissiveness, because changing the casing of a filename can be pretty disruptive, especially since Windows and Git track casing of filepaths differently.

So, given the general consensus on whether FAQPage is valid pascal case is that it's a matter of opinion, I think eslint-plugin-unicorn's opinion should be "yes" since that's a pretty legit component name.

If this would be wanted, maybe could be implemented with something along the lines of:

-const pascalCase = string => upperFirst(camelCase(string));
+const pascalCase = string => {
+  const camel = camelCase(string);
+  const upperCasePrefixLength = /^[A-Z]+/.exec(string)?.[0]?.length || 1
+  return camel.slice(0, upperCasePrefixLength).toUpperCase() + camel.slice(upperCasePrefixLength)
+}

Related: #2141 - but I consider that more controversial because it relates to camel case.

@mmkal mmkal changed the title filename-case: pascaleCase should allow stuff like FAQPage.js filename-case: pascalCase should allow stuff like FAQPage.js Apr 5, 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

No branches or pull requests

1 participant