1
- import { Rule , Tree , SchematicContext } from '@angular-devkit/schematics' ;
1
+ import { Rule , Tree , SchematicContext } from '@angular-devkit/schematics' ;
2
2
3
3
export function checkRuleExists ( rules : object , context : SchematicContext ) {
4
4
if ( ! rules [ 'rules' ] ) {
@@ -17,35 +17,43 @@ export function checkRuleExists(rules: object, context: SchematicContext) {
17
17
}
18
18
19
19
if ( ! rules [ 'rules' ] [ 'nx-enforce-module-boundaries' ] [ 1 ] [ 'depConstraints' ] ) {
20
- context . logger . info ( 'tslint.json: nx-enforce-module-boundaries.1.depConstraints expected.' ) ;
20
+ context . logger . info (
21
+ 'tslint.json: nx-enforce-module-boundaries.1.depConstraints expected.'
22
+ ) ;
21
23
return false ;
22
24
}
23
25
24
- if ( ! Array . isArray ( rules [ 'rules' ] [ 'nx-enforce-module-boundaries' ] [ 1 ] [ 'depConstraints' ] ) ) {
25
- context . logger . info ( 'tslint.json: nx-enforce-module-boundaries.1.depConstraints expected to be an array.' ) ;
26
+ if (
27
+ ! Array . isArray (
28
+ rules [ 'rules' ] [ 'nx-enforce-module-boundaries' ] [ 1 ] [ 'depConstraints' ]
29
+ )
30
+ ) {
31
+ context . logger . info (
32
+ 'tslint.json: nx-enforce-module-boundaries.1.depConstraints expected to be an array.'
33
+ ) ;
26
34
return false ;
27
35
}
28
36
29
37
return true ;
30
38
}
31
39
32
-
33
40
export function addDomainToLintingRules ( domainName : string ) : Rule {
34
41
return ( host : Tree , context : SchematicContext ) => {
35
42
const text = host . read ( 'tslint.json' ) . toString ( ) ;
36
43
const rules = JSON . parse ( text ) ;
37
44
38
45
if ( ! checkRuleExists ( rules , context ) ) return ;
39
46
40
- const depConst = rules [ 'rules' ] [ 'nx-enforce-module-boundaries' ] [ 1 ] [ 'depConstraints' ] ;
47
+ const depConst =
48
+ rules [ 'rules' ] [ 'nx-enforce-module-boundaries' ] [ 1 ] [ 'depConstraints' ] ;
41
49
depConst . push ( {
42
- ' sourceTag' : `domain:${ domainName } ` ,
43
- ' onlyDependOnLibsWithTags' : [ `domain:${ domainName } ` , 'domain:shared' ]
50
+ sourceTag : `domain:${ domainName } ` ,
51
+ onlyDependOnLibsWithTags : [ `domain:${ domainName } ` , 'domain:shared' ]
44
52
} ) ;
45
53
46
54
const newText = JSON . stringify ( rules , undefined , 2 ) ;
47
55
host . overwrite ( 'tslint.json' , newText ) ;
48
- }
56
+ } ;
49
57
}
50
58
51
59
export function initLintingRules ( ) : Rule {
@@ -55,15 +63,19 @@ export function initLintingRules(): Rule {
55
63
56
64
if ( ! checkRuleExists ( rules , context ) ) return ;
57
65
58
- const depConst = rules [ 'rules' ] [ 'nx-enforce-module-boundaries' ] [ 1 ] [ 'depConstraints' ] as Array < object > ;
66
+ const depConst = rules [ 'rules' ] [ 'nx-enforce-module-boundaries' ] [ 1 ] [
67
+ 'depConstraints'
68
+ ] as Array < object > ;
59
69
60
- const jokerIndex = depConst . findIndex ( entry =>
61
- entry [ 'sourceTag' ]
62
- && entry [ 'sourceTag' ] === '*'
63
- && entry [ 'onlyDependOnLibsWithTags' ]
64
- && Array . isArray ( entry [ 'onlyDependOnLibsWithTags' ] )
65
- && entry [ 'onlyDependOnLibsWithTags' ] . length > 0
66
- && entry [ 'onlyDependOnLibsWithTags' ] [ 0 ] === '*' ) ;
70
+ const jokerIndex = depConst . findIndex (
71
+ entry =>
72
+ entry [ 'sourceTag' ] &&
73
+ entry [ 'sourceTag' ] === '*' &&
74
+ entry [ 'onlyDependOnLibsWithTags' ] &&
75
+ Array . isArray ( entry [ 'onlyDependOnLibsWithTags' ] ) &&
76
+ entry [ 'onlyDependOnLibsWithTags' ] . length > 0 &&
77
+ entry [ 'onlyDependOnLibsWithTags' ] [ 0 ] === '*'
78
+ ) ;
67
79
68
80
if ( jokerIndex !== - 1 ) {
69
81
depConst . splice ( jokerIndex , 1 ) ;
@@ -90,31 +102,31 @@ export function initLintingRules(): Rule {
90
102
} ) ;
91
103
92
104
depConst . push ( {
93
- ' sourceTag' : 'type:api' ,
94
- ' onlyDependOnLibsWithTags' : [ 'type:ui' , 'type:domain-logic' , 'type:util' ]
105
+ sourceTag : 'type:api' ,
106
+ onlyDependOnLibsWithTags : [ 'type:ui' , 'type:domain-logic' , 'type:util' ]
95
107
} ) ;
96
108
97
109
depConst . push ( {
98
- ' sourceTag' : 'type:feature' ,
99
- ' onlyDependOnLibsWithTags' : [ 'type:ui' , 'type:domain-logic' , 'type:util' ]
110
+ sourceTag : 'type:feature' ,
111
+ onlyDependOnLibsWithTags : [ 'type:ui' , 'type:domain-logic' , 'type:util' ]
100
112
} ) ;
101
113
102
114
depConst . push ( {
103
- ' sourceTag' : 'type:ui' ,
104
- ' onlyDependOnLibsWithTags' : [ 'type:domain-logic' , 'type:util' ]
115
+ sourceTag : 'type:ui' ,
116
+ onlyDependOnLibsWithTags : [ 'type:domain-logic' , 'type:util' ]
105
117
} ) ;
106
118
107
119
depConst . push ( {
108
- ' sourceTag' : 'domain-logic' ,
109
- ' onlyDependOnLibsWithTags' : [ 'type:util' ]
120
+ sourceTag : 'domain-logic' ,
121
+ onlyDependOnLibsWithTags : [ 'type:util' ]
110
122
} ) ;
111
123
112
124
depConst . push ( {
113
- ' sourceTag' : 'domain:shared' ,
114
- ' onlyDependOnLibsWithTags' : [ 'domain:shared' ]
125
+ sourceTag : 'domain:shared' ,
126
+ onlyDependOnLibsWithTags : [ 'domain:shared' ]
115
127
} ) ;
116
128
117
129
const newText = JSON . stringify ( rules , undefined , 2 ) ;
118
130
host . overwrite ( 'tslint.json' , newText ) ;
119
- }
131
+ } ;
120
132
}
0 commit comments