@@ -8,9 +8,20 @@ import { errMsgs } from '../../lib/rules/no-banned-usages'
8
8
import { getRuleTester } from '../testUtil'
9
9
10
10
getRuleTester ( ) . run ( 'no-banned-usages' , rules [ 'no-banned-usages' ] , {
11
- valid : [ "vscode.commands.executeCommand('foo', 'aws.foo', true, 42)" ] ,
11
+ valid : [
12
+ // setContext
13
+ "vscode.commands.executeCommand('foo', 'aws.foo', true, 42)" ,
14
+ // globalState
15
+ 'globals.globalState' ,
16
+ 'await globals.globalState.update("foo", 42)' ,
17
+ 'globals.globalState.get("foo")' ,
18
+ 'globalState.get("foo")' ,
19
+ ] ,
12
20
13
21
invalid : [
22
+ //
23
+ // setContext
24
+ //
14
25
{
15
26
code : "async function test() { await vscode.commands.executeCommand('setContext', key, val) }" ,
16
27
errors : [ errMsgs . setContext ] ,
@@ -35,5 +46,31 @@ getRuleTester().run('no-banned-usages', rules['no-banned-usages'], {
35
46
code : "const x = vscode.commands.executeCommand('setContext', key, val).catch(e => { return e })" ,
36
47
errors : [ errMsgs . setContext ] ,
37
48
} ,
49
+
50
+ //
51
+ // globalState
52
+ //
53
+ {
54
+ code : 'const memento = globals.context.globalState' ,
55
+ errors : [ errMsgs . globalState ] ,
56
+ } ,
57
+ {
58
+ code : 'const val = globals.context.globalState.get("foo")' ,
59
+ errors : [ errMsgs . globalState ] ,
60
+ } ,
61
+ {
62
+ code : 'const val = extContext.globalState.get("foo")' ,
63
+ errors : [ errMsgs . globalState ] ,
64
+ } ,
65
+ {
66
+ code : 'return this.openState(targetContext.globalState, key)' ,
67
+ errors : [ errMsgs . globalState ] ,
68
+ } ,
69
+
70
+ // TODO: prevent assignment of GlobalState to Memento.
71
+ // {
72
+ // code: 'const state: vscode.Memento = globals.globalState',
73
+ // errors: [errMsgs.globalState],
74
+ // },
38
75
] ,
39
76
} )
0 commit comments