sindresorhus / eslint-plugin-unicorn

More than 100 powerful ESLint rules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

mmkal opened this issue · comments

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.