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

Support for ComponentName/ComponentName.tsx #59

Open
dutzi opened this issue Aug 22, 2021 · 4 comments
Open

Support for ComponentName/ComponentName.tsx #59

dutzi opened this issue Aug 22, 2021 · 4 comments

Comments

@dutzi
Copy link

dutzi commented Aug 22, 2021

I don’t know how to call this requirement, but in a lot of React projects you’ll see the following pattern:

Within the folder: ./src/components/ComponentName you’ll find: ComponentName.tsx and ComponentName.module.scss.

So the containing folder’s name is the name of the files within it.

I suggest the following syntax:

ls:
    src/components/PascalCase:$1
        $1.tsx
        $1.module.scss

Hope this is clear enough, and that I haven’t missed this option somehow.

@jfairley
Copy link

jfairley commented Apr 6, 2023

I could also envision something akin to:

ls:
  src/components:
    .dir: PascalCase

    "*":
      .tsx: dir
      .module.scss: dir

... dir or something similar: match-dir, dir-match, parent, match-parent...

@jfairley
Copy link

jfairley commented Apr 6, 2023

On more thought, I do like the pattern matching idea.

I actually have a pattern in my codebase where the file root matches a directory that isn't the immediate parent.

I'll pull from regex and use parens to represent the match groups. I envision the references would be localized to the file path in question.

ls:
  src/components:
    (*):
      .dir: PascalCase
      .module.scss: $1
      .tsx: $1

      __tests__:
        .spec.tsx: $1

Repository owner deleted a comment from Igorkowalski94 Oct 2, 2023
@kopach
Copy link

kopach commented Mar 13, 2024

Found alternative with eslint, until this is resolved - https://www.npmjs.com/package/eslint-plugin-check-file with filename-naming-convention rule.
Something like this will throw en error if there is no folder with exactly the same name for file (except if file is in hooks directory or file is index). Plus this ensures, that component file name is in PascalCase

      "rules": {
        "check-file/filename-naming-convention": [
          "error",
          {
            "**/!(hooks)/!(index).*": "<1>",
            "**/**/!(hooks)/!(index).*": "PASCAL_CASE"
          },
          { "ignoreMiddleExtensions": true }
        ]
      }

It's also possible to customize error message to make it more readable
https://github.com/DukeLuo/eslint-plugin-check-file/blob/main/docs/rules/filename-naming-convention.md#errormessage

@loeffel-io
Copy link
Owner

fyi: i will definitely support this in the future

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

4 participants