eslint-plugin-filenames
eslint-plugin-filenames copied to clipboard
Add match-exported = [parent folder]-[filename] pattern
This is a great plugin for code reviewers! I mean how often does one forget to check the file name in Github?
I'm getting this error and was curious if there was a way to get around it:
design-system-react/components/accordion/panel.jsx
8:1 error Filename 'panel' must match the exported and transformed name 'accordion-panel' filenames/match-exported
design-system-react/components/alert/container.jsx
6:1 error Filename 'container' must match the exported and transformed name 'alert-container' filenames/match-exported
The pattern is [parent folder]-[filename]
in kabob case. I don't mind PR'ing this if it's a simple pattern to match. I'd imagine the regex would go back before the last slash in the path and add that to a hyphen and the filename.
In my case, sometimes I also have a grandparent folder, i.e.: src/components/base/card/header.js
, where we expect the component to be default exported as BaseCardHeader
.
What changes should I do to accomplish this?
As an alternative you can use https://github.com/Igorkowalski94/eslint-plugin-project-structure has the same capabilities + force only folders/files, has a built-in case for name, regex support, ability to inherit the name from the parent (the child inherits the name of the folder in which it is located), folder recursion (You can nest a given folder structure recursively).