Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed May 13, 2024
1 parent f23d993 commit 79351b3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 61 deletions.
61 changes: 0 additions & 61 deletions packages/eslint-plugin/docs/rules/is-gutenberg-plugin.md

This file was deleted.

60 changes: 60 additions & 0 deletions packages/eslint-plugin/docs/rules/wp-globals-usage.md
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;
}
```

0 comments on commit 79351b3

Please sign in to comment.