File tree Expand file tree Collapse file tree 5 files changed +23
-11
lines changed
graphiql-toolkit/src/storage
graphiql/src/components/__tests__ Expand file tree Collapse file tree 5 files changed +23
-11
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @graphiql/toolkit " : patch
3
+ ---
4
+
5
+ prefer ` localStorage ` over ` window.localStorage `
Original file line number Diff line number Diff line change @@ -133,7 +133,14 @@ module.exports = {
133
133
'no-octal-escape' : 'error' ,
134
134
'no-param-reassign' : 'error' ,
135
135
'no-proto' : 'error' ,
136
- 'no-restricted-properties' : 'off' ,
136
+ 'no-restricted-properties' : [
137
+ 'error' ,
138
+ {
139
+ object : 'window' ,
140
+ property : 'localStorage' ,
141
+ message : 'Use `localStorage` instead' ,
142
+ } ,
143
+ ] ,
137
144
'no-return-assign' : 'error' ,
138
145
'no-return-await' : 'error' ,
139
146
'no-script-url' : 'error' ,
Original file line number Diff line number Diff line change @@ -64,13 +64,13 @@ export class StorageAPI {
64
64
this . storage = null ;
65
65
} else {
66
66
this . storage = {
67
- getItem : window . localStorage . getItem . bind ( window . localStorage ) ,
68
- setItem : window . localStorage . setItem . bind ( window . localStorage ) ,
69
- removeItem : window . localStorage . removeItem . bind ( window . localStorage ) ,
67
+ getItem : localStorage . getItem . bind ( localStorage ) ,
68
+ setItem : localStorage . setItem . bind ( localStorage ) ,
69
+ removeItem : localStorage . removeItem . bind ( localStorage ) ,
70
70
71
71
get length ( ) {
72
72
let keys = 0 ;
73
- for ( const key in window . localStorage ) {
73
+ for ( const key in localStorage ) {
74
74
if ( key . indexOf ( `${ STORAGE_NAMESPACE } :` ) === 0 ) {
75
75
keys += 1 ;
76
76
}
@@ -80,9 +80,9 @@ export class StorageAPI {
80
80
81
81
clear ( ) {
82
82
// We only want to clear the namespaced items
83
- for ( const key in window . localStorage ) {
83
+ for ( const key in localStorage ) {
84
84
if ( key . indexOf ( `${ STORAGE_NAMESPACE } :` ) === 0 ) {
85
- window . localStorage . removeItem ( key ) ;
85
+ localStorage . removeItem ( key ) ;
86
86
}
87
87
}
88
88
} ,
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ export function createLocalStorage({
25
25
removeItem : key => localStorage . removeItem ( getStorageKey ( key ) ) ,
26
26
get length ( ) {
27
27
let keys = 0 ;
28
- for ( const key in window . localStorage ) {
28
+ for ( const key in localStorage ) {
29
29
if ( key . indexOf ( storageKeyPrefix ) === 0 ) {
30
30
keys += 1 ;
31
31
}
@@ -35,9 +35,9 @@ export function createLocalStorage({
35
35
36
36
clear ( ) {
37
37
// We only want to clear the namespaced items
38
- for ( const key in window . localStorage ) {
38
+ for ( const key in localStorage ) {
39
39
if ( key . indexOf ( storageKeyPrefix ) === 0 ) {
40
- window . localStorage . removeItem ( key ) ;
40
+ localStorage . removeItem ( key ) ;
41
41
}
42
42
}
43
43
} ,
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ const simpleIntrospection = {
29
29
} ;
30
30
31
31
beforeEach ( ( ) => {
32
- window . localStorage . clear ( ) ;
32
+ localStorage . clear ( ) ;
33
33
} ) ;
34
34
35
35
describe ( 'GraphiQL' , ( ) => {
You can’t perform that action at this time.
0 commit comments