File tree 2 files changed +97
-4
lines changed 2 files changed +97
-4
lines changed Original file line number Diff line number Diff line change @@ -38,22 +38,29 @@ function get(pathOrCzConfig, defaultConfig) {
38
38
}
39
39
40
40
// Converts the `scopes` and `scopeOverrides` into `scope-enum` rule.
41
- if ( typeof czConfig . scopes !== 'undefined' || typeof czConfig . scopeOverrides !== 'undefined' ) {
41
+ const hasScopeEnum = Object . prototype . hasOwnProperty . call ( config . rules , 'scope-enum' ) ;
42
+
43
+ if (
44
+ hasScopeEnum &&
45
+ ( typeof czConfig . scopes !== 'undefined' || typeof czConfig . scopeOverrides !== 'undefined' )
46
+ ) {
42
47
config . rules [ 'scope-enum' ] [ 2 ] = Scopes . get ( czConfig ) ;
43
48
}
44
49
45
50
// Removes empty `scope-enum` rule.
46
- if ( ! config . rules [ 'scope-enum' ] [ 2 ] . length ) {
51
+ if ( hasScopeEnum && ! config . rules [ 'scope-enum' ] [ 2 ] . length ) {
47
52
delete config . rules [ 'scope-enum' ] ;
48
53
}
49
54
50
55
// Converts the `types` into `type-enum` rule.
51
- if ( typeof czConfig . types !== 'undefined' ) {
56
+ const hasTypeEnum = Object . prototype . hasOwnProperty . call ( config . rules , 'type-enum' ) ;
57
+
58
+ if ( hasTypeEnum && typeof czConfig . types !== 'undefined' ) {
52
59
config . rules [ 'type-enum' ] [ 2 ] = Types . get ( czConfig ) ;
53
60
}
54
61
55
62
// Removes empty `type-enum` rule.
56
- if ( ! config . rules [ 'type-enum' ] [ 2 ] . length ) {
63
+ if ( hasTypeEnum && ! config . rules [ 'type-enum' ] [ 2 ] . length ) {
57
64
delete config . rules [ 'type-enum' ] ;
58
65
}
59
66
Original file line number Diff line number Diff line change @@ -173,5 +173,91 @@ describe('config', function () {
173
173
assert . deepStrictEqual ( Config . get ( configPath , defaultConfig ) , expected ) ;
174
174
}
175
175
) ;
176
+
177
+ it ( 'should ignore `scopes` and `scopeOverrides` when commitlint config has no `scope-enum` rule' ,
178
+ function ( ) {
179
+ const configPath = path . join ( __dirname , 'fixtures/.cz-config.js' ) ;
180
+
181
+ const defaultConfig = {
182
+ rules : {
183
+ 'body-leading-blank' : [
184
+ 2 ,
185
+ 'always' ,
186
+ ] ,
187
+ 'type-enum' : [
188
+ 1 ,
189
+ 'never' ,
190
+ [
191
+ 'type-3' ,
192
+ 'type-4' ,
193
+ ] ,
194
+ ] ,
195
+ } ,
196
+ } ;
197
+
198
+ const expected = {
199
+ rules : {
200
+ 'body-leading-blank' : [
201
+ 2 ,
202
+ 'always' ,
203
+ ] ,
204
+ 'type-enum' : [
205
+ 1 ,
206
+ 'never' ,
207
+ [
208
+ 'type-1' ,
209
+ 'type-2' ,
210
+ ] ,
211
+ ] ,
212
+ }
213
+ } ;
214
+
215
+ assert . deepStrictEqual ( Config . get ( configPath , defaultConfig ) , expected ) ;
216
+ }
217
+ ) ;
218
+
219
+ it ( 'should ignore `types` when commitlint config has no `type-enum` rule' ,
220
+ function ( ) {
221
+ const configPath = path . join ( __dirname , 'fixtures/.cz-config.js' ) ;
222
+
223
+ const defaultConfig = {
224
+ rules : {
225
+ 'body-leading-blank' : [
226
+ 2 ,
227
+ 'always' ,
228
+ ] ,
229
+ 'scope-enum' : [
230
+ 1 ,
231
+ 'never' ,
232
+ [
233
+ 'scope-4' ,
234
+ 'scope-5' ,
235
+ 'scope-6' ,
236
+ ] ,
237
+ ] ,
238
+ } ,
239
+ } ;
240
+
241
+ const expected = {
242
+ rules : {
243
+ 'body-leading-blank' : [
244
+ 2 ,
245
+ 'always' ,
246
+ ] ,
247
+ 'scope-enum' : [
248
+ 1 ,
249
+ 'never' ,
250
+ [
251
+ 'scope-1' ,
252
+ 'scope-2' ,
253
+ 'scope-3' ,
254
+ ] ,
255
+ ] ,
256
+ }
257
+ } ;
258
+
259
+ assert . deepStrictEqual ( Config . get ( configPath , defaultConfig ) , expected ) ;
260
+ }
261
+ ) ;
176
262
} ) ;
177
263
} ) ;
You can’t perform that action at this time.
0 commit comments