-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
Add option to automatically handle React projects in filename-case
rule
#203
Comments
I suggest |
@zeorin Options should be in camelcase. How about |
Ah, I was confused, I thought you were suggesting a new rule name, rather than a new option name (which is indeed a better idea). Thinking about this a little more, what happens when there are components that start with a lowercase letter? Higher order components do this quite frequently, and whilst most probably don't contain any JSX, we cannot rule that out. Yet it is also a convention. The term In addition, there might be situations where JSX files have a filename case convention that's different to the rest of the project, but not PascalCase. How about a new option called
If we also add a new behavior option,
|
Do you have any examples? It would enforce kebabCase (
That doesn't handle the case of JSX files that are not components. Most projects have those, like |
I was under the impression that I think, at heart, there are slightly different rules being discussed. The idea of switching filename case on extension sounds useful. The idea of detecting JSX usage and switching filename case also sounds useful. Even if they inherently overlap in purpose, it wouldn't be bad to have the chance to choose which of the two fits your project best. |
That's project-specific. If I'm writing HoCs for a project I might use
I'm assuming this rule doesn't actually inspect the contents of a file for JSX usage, instead simply matching on the file extension; so I assume you meant I assumed that "unicorn/filename-case": ["error", {"case": "kebabCase", "jsxCase": "pascalCase"}] +FooWidget/index.jsx
-foo-widget/index.jsx If so, it makes sense to add that behaviour to the +foo-bar/index.js
-fooBar/index.js While we're at it we could extend the rule to check the case of any arbitrary file extension, but ESLint's built-in overrides mechanism can achieve the same thing, see my comment on the original issue. |
Just to be clear. This will detect actual JSX usage in a file. Not the |
Ah, in that case this is indeed better than using the overrides. I'd still assume In the case of HoCs (that don't start with a capital letter) that follow a different file naming convention and may contain JSX, I feel that either they ought to be in a special directory that can then be catered for using ESLint overrides, or using ESLint configuration comments. Same goes for custom hooks. |
Is there a way this rule could apply to directories as well? I like getting this linting across my project to have kebab case but some pascalCase leaks in occasionally from directory names. |
Our rules allow for both pascal and kebab, but what we want is actually a mix of the two, ie. It'd be nice to not have to capitalize Our particular situation could also probably be solved by allowing regex, as mentioned in #343. |
Whats about this, is there a workaround? |
If easy, I'd extend the request to support Svelte components (example Svelte project using XO) and Vue (documentation). These might be easier to detect since they have a custom extension, although custom extensions require extra config normally. |
Not sure when / what that changed in eslint-plugin-unicorn, but the following is working well for me now and solves the issues outlined in my previous comment.
|
This should support and apply multiple cases by extension: 'unicorn/filename-case': [
'error',
{
cases: {
kebabCase: {
extension: '.js'
},
pascalCase: {
extension: '.jsx'
}
}
}
] |
The convention for React components is to use pascal case (
FooBar.js
). We could detect files using JSX and enforce pascal case and ignore the chosen case, but it's also common to have anindex.js
,routes.js
orapp-routes.js
that has JSX in them, but are not components. So my proposal would be to add an option that, when enabled, would enforce eitherpascalCase
(FooBar.js
) orkebabCase
(app-routes.js
) for files with JSX. I think it would be safe to have it on by default. The option could be calledreact
(Suggestions for a better option name welcome!).The text was updated successfully, but these errors were encountered: