11# vue-modular/enforce-naming-convention  
22
3- Enforce consistent naming patterns for Vue components .
3+ Enforce consistent naming patterns for different file types based on  Vue 3 modular architecture .
44
55## Rule Details  
66
7- This rule enforces consistent naming conventions for Vue component ` name `  properties. It ensures that component names follow proper case conventions (PascalCase by default) and optionally validates that filenames match component names.
7+ This rule enforces consistent naming conventions for Vue component ` name `  properties and validates file naming patterns based on Vue 3 modular architecture guidelines. It ensures that different file types follow proper naming conventions:
8+ 
9+ -  ** Views**  → Always end with ` View.vue `  → ` LoginView.vue ` , ` UserListView.vue ` 
10+ -  ** Components**  → PascalCase, descriptive → ` UserTable.vue ` , ` LoginForm.vue ` 
11+ -  ** Stores**  → Use Pinia convention: ` useXxxStore.ts ` 
12+ -  ** Composables**  → Always start with ` useXxx.ts ` 
13+ -  ** Services**  → ` <domain>.api.ts `  for API clients (e.g., ` auth.api.ts ` )
814
915### Examples  
1016
@@ -18,10 +24,34 @@ export default {
1824``` 
1925
2026``` js 
21- //  Filename should match component name (if requireFileNameMatches: true) 
22- //  File: src/components/user-card.js 
27+ //  View files must end with 'View.vue' 
28+ //  File: src/views/Login.vue 
2329export  default  {
24-   name:  ' UserCard'  ,
30+   name:  ' Login'  ,
31+ }
32+ ``` 
33+ 
34+ ``` js 
35+ //  Store files must follow 'useXxxStore.ts' pattern
36+ //  File: src/stores/authStore.ts
37+ export  default  {
38+   //  store implementation
39+ }
40+ ``` 
41+ 
42+ ``` js 
43+ //  Composable files must start with 'use'
44+ //  File: src/composables/api.ts
45+ export  default  {
46+   //  composable implementation
47+ }
48+ ``` 
49+ 
50+ ``` js 
51+ //  Service files should follow '<domain>.api.ts' pattern
52+ //  File: src/services/authService.ts
53+ export  default  {
54+   //  service implementation
2555}
2656``` 
2757
@@ -35,17 +65,34 @@ export default {
3565``` 
3666
3767``` js 
38- //  Matching filename and component name 
39- //  File: src/components/UserCard.js 
68+ //  View files ending with 'View.vue' 
69+ //  File: src/views/LoginView.vue 
4070export  default  {
41-   name:  ' UserCard'  ,
71+   name:  ' LoginView'  ,
72+ }
73+ ``` 
74+ 
75+ ``` js 
76+ //  Proper store naming
77+ //  File: src/stores/useAuthStore.ts
78+ export  default  {
79+   //  store implementation
4280}
4381``` 
4482
4583``` js 
46- //  Component without explicit name (allowed by default)
84+ //  Proper composable naming
85+ //  File: src/composables/useApi.ts
4786export  default  {
48-   //  Component logic without name property
87+   //  composable implementation
88+ }
89+ ``` 
90+ 
91+ ``` js 
92+ //  Proper service naming
93+ //  File: src/services/auth.api.ts
94+ export  default  {
95+   //  service implementation
4996}
5097``` 
5198
@@ -55,28 +102,75 @@ export default {
55102{
56103  " vue-modular/enforce-naming-convention" :  [" error"  , {
57104    " style" :  " PascalCase"  ,
58-     " requireFileNameMatches" :  true 
105+     " requireFileNameMatches" :  true ,
106+     " enforceFileTypeConventions" :  true 
59107  }]
60108}
61109``` 
62110
63111### ` style `  (default: ` "PascalCase" ` ) 
64112
65- Defines the naming convention for component names:
113+ Defines the naming convention for component names (legacy mode only) :
66114
67115-  ` "PascalCase" `  - Component names should use PascalCase (e.g., ` UserCard ` , ` LoginForm ` )
68116-  ` "kebab-case" `  - Component names should use kebab-case (e.g., ` user-card ` , ` login-form ` )
69117
70118### ` requireFileNameMatches `  (default: ` true ` ) 
71119
72- When enabled, requires that the filename matches the component name exactly.
120+ When enabled in legacy mode , requires that the filename matches the component name exactly.
73121
74122-  ` true `  - Filename must match component name
75123-  ` false `  - No filename validation
76124
125+ ### ` enforceFileTypeConventions `  (default: ` true ` ) 
126+ 
127+ When enabled, enforces Vue 3 modular architecture naming conventions based on file type and location.
128+ 
129+ -  ` true `  - Enforce file type-specific naming conventions
130+ -  ` false `  - Use legacy component name validation only
131+ 
132+ ## File Type Detection  
133+ 
134+ The rule automatically detects file types based on directory structure and filename patterns:
135+ 
136+ ### Views  
137+ 
138+ -  ** Directory patterns** : ` /views/ ` , ` /view/ ` 
139+ -  ** File pattern** : ` *.vue ` 
140+ -  ** Convention** : Must end with ` View.vue ` 
141+ -  ** Examples** : ` LoginView.vue ` , ` UserListView.vue ` , ` DashboardView.vue ` 
142+ 
143+ ### Components  
144+ 
145+ -  ** Directory patterns** : ` /components/ ` , ` /component/ ` 
146+ -  ** File pattern** : ` *.vue ` 
147+ -  ** Convention** : PascalCase, descriptive names
148+ -  ** Examples** : ` UserTable.vue ` , ` LoginForm.vue ` , ` SearchInput.vue ` 
149+ 
150+ ### Stores  
151+ 
152+ -  ** Directory patterns** : ` /stores/ ` , ` /store/ ` 
153+ -  ** File pattern** : ` *.ts ` , ` *.js ` 
154+ -  ** Convention** : Must follow ` useXxxStore.ts `  pattern
155+ -  ** Examples** : ` useAuthStore.ts ` , ` useUserStore.ts ` , ` useSettingsStore.ts ` 
156+ 
157+ ### Composables  
158+ 
159+ -  ** Directory patterns** : ` /composables/ ` , ` /composable/ ` 
160+ -  ** File pattern** : ` *.ts ` , ` *.js ` 
161+ -  ** Convention** : Must start with ` use ` 
162+ -  ** Examples** : ` useApi.ts ` , ` useAuth.ts ` , ` useLocalStorage.ts ` 
163+ 
164+ ### Services  
165+ 
166+ -  ** Directory patterns** : ` /services/ ` , ` /service/ ` 
167+ -  ** File pattern** : ` *.ts ` , ` *.js ` 
168+ -  ** Convention** : Must follow ` <domain>.api.ts `  pattern
169+ -  ** Examples** : ` auth.api.ts ` , ` users.api.ts ` , ` notifications.api.ts ` 
170+ 
77171## Configuration Examples  
78172
79- ### Default Configuration  
173+ ### Default Configuration (Recommended)   
80174
81175``` js 
82176{
@@ -86,34 +180,65 @@ When enabled, requires that the filename matches the component name exactly.
86180
87181This enforces:
88182
89- -  PascalCase component names
183+ -  Vue 3 modular architecture naming conventions
184+ -  File type-specific validation
185+ -  PascalCase component names for Vue files
186+ -  Proper filename patterns for all file types
187+ 
188+ ### Legacy Mode  
189+ 
190+ ``` js 
191+ {
192+   " vue-modular/enforce-naming-convention" :  [" error"  , {
193+     " enforceFileTypeConventions" :  false ,
194+     " style" :  " PascalCase"  ,
195+     " requireFileNameMatches" :  true 
196+   }]
197+ }
198+ ``` 
199+ 
200+ This enforces:
201+ 
202+ -  PascalCase component names only
90203-  Filename must match component name
204+ -  No file type-specific validation
91205
92- ### Custom Style  
206+ ### Custom Style (Legacy Mode)   
93207
94208``` js 
95209{
96210  " vue-modular/enforce-naming-convention" :  [" error"  , {
211+     " enforceFileTypeConventions" :  false ,
97212    " style" :  " kebab-case" 
98213  }]
99214}
100215``` 
101216
102- ### Disable Filename Matching  
217+ ### File Type Conventions Only  
103218
104219``` js 
105220{
106221  " vue-modular/enforce-naming-convention" :  [" error"  , {
222+     " enforceFileTypeConventions" :  true ,
107223    " requireFileNameMatches" :  false 
108224  }]
109225}
110226``` 
111227
228+ ## Benefits  
229+ 
230+ -  ** Consistent codebase** : Enforces uniform naming across the entire project
231+ -  ** Clear file purpose** : File naming immediately indicates the file's role
232+ -  ** Better organization** : Supports Vue 3 modular architecture patterns
233+ -  ** Team alignment** : Ensures all developers follow the same conventions
234+ -  ** Easier navigation** : Predictable naming makes files easier to find
235+ 
112236## When Not To Use  
113237
114- -  If your project uses a different naming convention that doesn't follow standard Vue.js practices
115- -  If you have legacy components that can't be easily renamed
116- -  If your build process handles component name transformations automatically
238+ -  If your project uses a different architectural pattern
239+ -  If you have legacy files that can't be easily renamed
240+ -  If your build process handles name transformations automatically
241+ -  If your team prefers different naming conventions
117242
118243## Related Rules  
119244
@@ -123,4 +248,5 @@ This enforces:
123248## Further Reading  
124249
125250-  [ Vue.js Component Naming Best Practices] ( https://vuejs.org/style-guide/ ) 
126- -  [ JavaScript Naming Conventions] ( https://www.robinwieruch.de/javascript-naming-conventions ) 
251+ -  [ Vue 3 Modular Architecture Blueprint] ( ../vue3-project-modules-blueprint.md ) 
252+ -  [ Pinia Store Naming Conventions] ( https://pinia.vuejs.org/core-concepts/ ) 
0 commit comments