Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions docs/front_code_validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,25 +222,24 @@ Extra package to add:

`yarn add --dev globals`

The scope of the `lint` and `format` commands must be narrowed to the front directories only, `assets` plus the JS files at the
root, which gives:
The scope of the `lint` and `format` commands must be narrowed to the only directory holding front code, `assets`, which gives:

```json
"scripts": {
"lint": "eslint assets \"*.{js,mjs}\" --fix --cache",
"lint:check": "eslint assets \"*.{js,mjs}\"",
"lint:baseline": "rm -f eslint-suppressions.json && eslint assets \"*.{js,mjs}\" --suppress-all",
"format": "prettier --write assets \"*.{js,mjs}\"",
"format:check": "prettier --check assets \"*.{js,mjs}\""
"lint": "eslint assets --fix --cache",
"lint:check": "eslint assets",
"lint:baseline": "rm -f eslint-suppressions.json && eslint assets --suppress-all",
"format": "prettier --write assets",
"format:check": "prettier --check assets"
}
```

A project never validates `vendor/`: a bundle validates its own front code from its own repository.

**Specific use of globals in the context of using FOSJsRoutingBundle**

Impact on the ESLint config: the front code runs in the browser while the config files run under Node, and Twig injects globals
that must be declared, otherwise `no-undef` reports them.
Impact on the ESLint config: the front code runs in the browser, and Twig injects globals that must be declared, otherwise
`no-undef` reports them.

```mjs
import globals from "globals"
Expand All @@ -255,9 +254,14 @@ import globals from "globals"
},
},
},
```

The root config files (`vite.config.mjs`, `phpstorm.config.js`) stay out of that scope, so there is nothing to declare for Node.
Widening the scope to them means adding their globals too, as they don't run in the browser:

```mjs
{
// Config files run under Node: `vite.config.js` reads `__dirname`.
// Config files run under Node: `vite.config.mjs` reads `__dirname`.
name: "app/globals-node",
files: ["**/*.config.{js,mjs}"],
languageOptions: { globals: { ...globals.node } },
Expand Down
Loading