-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
61 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# WordPress globals usage (wp-globals-usage) | ||
|
||
To enable the use of feature flags in Gutenberg some globals are used, such as `IS_GUTENBERG_PLUGIN` and `SCRIPT_DEBUG`. | ||
|
||
There are a few rules around using this constant: | ||
|
||
- Only access the globals via `globalThis`, e.g. `globalThis.IS_GUTENBERG_PLUGIN`. This allows the variables to be replaced compile time. | ||
- The globals should only be used as a conditional test (negation is allowed). | ||
|
||
## Rule details | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
if ( IS_GUTENBERG_PLUGIN ) { | ||
// implement feature here. | ||
} | ||
``` | ||
|
||
```js | ||
if ( window[ 'IS_GUTENBERG_PLUGIN' ] ) { | ||
// implement feature here. | ||
} | ||
``` | ||
|
||
```js | ||
if ( globalThis.IS_GUTENBERG_PLUGIN == 1 ) { | ||
// implement feature here. | ||
} | ||
``` | ||
|
||
```js | ||
if ( globalThis.IS_GUTENBERG_PLUGIN === true ) { | ||
// implement feature here. | ||
} | ||
``` | ||
|
||
```js | ||
if ( true || globalThis.IS_GUTENBERG_PLUGIN ) { | ||
// implement feature here. | ||
} | ||
``` | ||
|
||
```js | ||
const isMyFeatureActive = globalThis.IS_GUTENBERG_PLUGIN; | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
if ( globalThis.IS_GUTENBERG_PLUGIN ) { | ||
// implement feature here. | ||
} | ||
``` | ||
|
||
```js | ||
if ( ! globalThis.IS_GUTENBERG_PLUGIN ) { | ||
return; | ||
} | ||
``` |