Skip to content

Commit

Permalink
Merge pull request #162 from frontEnd-fucker/feature-filename-check
Browse files Browse the repository at this point in the history
support filename check
  • Loading branch information
alan2207 committed May 23, 2024
2 parents d8cb1f3 + 0ec4251 commit e8181b4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
'generators/*',
],
extends: ['eslint:recommended'],
plugins: ['check-file'],
overrides: [
{
files: ['**/*.ts', '**/*.tsx'],
Expand Down Expand Up @@ -125,6 +126,27 @@ module.exports = {
'@typescript-eslint/no-empty-function': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
'check-file/filename-naming-convention': [
'error',
{
'**/*.{ts,tsx}': 'KEBAB_CASE',
},
{
ignoreMiddleExtensions: true,
},
],
},
},
{
plugins: ['check-file'],
files: ['src/**/!(__tests__)/*'],
rules: {
'check-file/folder-naming-convention': [
'error',
{
'**/*': 'KEBAB_CASE',
},
],
},
},
],
Expand Down
26 changes: 26 additions & 0 deletions docs/project-standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,29 @@ For TypeScript (`tsconfig.json`) projects:
```

It is also possible to define multiple paths for various folders(such as `@components`, `@hooks`, etc.), but using `@/*` works very well because it is short enough so there is no need to configure multiple paths and it differs from other dependency modules so there is no confusion in what comes from `node_modules` and what is our source folder. That means that anything in the `src` folder can be accessed via `@`, e.g some file that lives in `src/components/my-component` can be accessed using `@/components/my-component` instead of `../../../components/my-component`.

#### File naming conventions

We can also enforce the file naming conventions and folder naming conventions in the project. For example, you can enforce that all files should be named in `kebab-case`. This can help you to keep your codebase consistent and easier to navigate.

To enforce this, you can use ESLint:

```js
'check-file/filename-naming-convention': [
'error',
{
'**/*.{ts,tsx}': 'KEBAB_CASE',
},
{
// ignore the middle extensions of the filename to support filename like bable.config.js or smoke.spec.ts
ignoreMiddleExtensions: true,
},
],
'check-file/folder-naming-convention': [
'error',
{
// all folders within src (except __tests__)should be named in kebab-case
'src/**/!(__tests__)': 'KEBAB_CASE',
},
],
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"clsx": "^2.1.1",
"dayjs": "^1.11.11",
"dompurify": "^3.1.1",
"eslint-plugin-check-file": "^2.8.0",
"lucide-react": "^0.378.0",
"marked": "^12.0.2",
"nanoid": "^5.0.7",
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4886,6 +4886,14 @@ eslint-module-utils@^2.7.4, eslint-module-utils@^2.8.0:
dependencies:
debug "^3.2.7"

eslint-plugin-check-file@^2.8.0:
version "2.8.0"
resolved "https://registry.npmmirror.com/eslint-plugin-check-file/-/eslint-plugin-check-file-2.8.0.tgz#6f93f28b25376ca9a7b0d741ca56a726d59f8db7"
integrity sha512-FvvafMTam2WJYH9uj+FuMxQ1y+7jY3Z6P9T4j2214cH0FBxNzTcmeCiGTj1Lxp3mI6kbbgsXvmgewvf+llKYyw==
dependencies:
is-glob "^4.0.3"
micromatch "^4.0.5"

eslint-plugin-import@^2.29.1:
version "2.29.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.29.1.tgz#d45b37b5ef5901d639c15270d74d46d161150643"
Expand Down

0 comments on commit e8181b4

Please sign in to comment.