File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,5 +28,65 @@ export default wdioEslint.config([
2828 '@typescript-eslint/no-require-imports' : 'off' ,
2929 '@typescript-eslint/no-explicit-any' : 'off'
3030 }
31+ } ,
32+ {
33+ files : [ 'src/**/*.ts' ] ,
34+ plugins : {
35+ local : {
36+ rules : {
37+ 'enforce-options-list' : {
38+ create ( context ) {
39+ const fileName = context . filename || context . getFilename ( )
40+ const isConstantsFile = fileName . endsWith ( 'src/constants.ts' )
41+ const definedOptions = new Set ( )
42+ let listNode = null
43+ const listElements = new Set ( )
44+
45+ return {
46+ VariableDeclarator ( node ) {
47+ if ( node . id . type === 'Identifier' ) {
48+ if ( node . id . name . includes ( 'DEFAULT_OPTIONS' ) ) {
49+ if ( isConstantsFile ) {
50+ definedOptions . add ( node . id . name )
51+ } else {
52+ context . report ( {
53+ node : node . id ,
54+ message : `Option '${ node . id . name } ' must be included in 'src/constants.ts#defaultOptionsList', so it can be globally overridden.`
55+ } )
56+ }
57+ }
58+ if ( isConstantsFile && node . id . name === 'defaultOptionsList' && node . init && node . init . type === 'ArrayExpression' ) {
59+ listNode = node
60+ node . init . elements . forEach ( el => {
61+ if ( el && el . type === 'Identifier' ) {
62+ listElements . add ( el . name )
63+ }
64+ } )
65+ }
66+ }
67+ } ,
68+ 'Program:exit' ( ) {
69+ if ( ! listNode ) {
70+ return
71+ }
72+
73+ definedOptions . forEach ( opt => {
74+ if ( ! listElements . has ( opt ) ) {
75+ context . report ( {
76+ node : listNode ,
77+ message : `Option '${ opt } ' must be included in 'defaultOptionsList', so it can be globally overridden in 'src/constants.ts'.`
78+ } )
79+ }
80+ } )
81+ }
82+ }
83+ }
84+ }
85+ }
86+ }
87+ } ,
88+ rules : {
89+ 'local/enforce-options-list' : 'error'
90+ }
3191 }
3292] )
You can’t perform that action at this time.
0 commit comments