I've been a long time user of Standard, and now that I'm working on a new project, I've been asked to start writing semicolons.
I'm trying to use both xo, Babel and React, but I keep getting an error when I try to lint my code:
document is not defined. no-undef
I've tried adding an env
option to the xo
field in my package.json file, but no success.
My xo
config:
"xo": {
"esnext": true,
"extends": "xo-react",
"space": true,
"rules": {
"react/jsx-space-before-closing": 0
}
}
I've been a long time user of Standard, and now that I'm working on a new project, I've been asked to start writing semicolons.
I'm trying to use both xo, Babel and React, but I keep getting an error when I try to lint my code:
document is not defined. no-undef
I've tried adding an env
option to the xo
field in my package.json file, but no success.
My xo
config:
"xo": {
"esnext": true,
"extends": "xo-react",
"space": true,
"rules": {
"react/jsx-space-before-closing": 0
}
}
Share
Improve this question
asked Oct 4, 2016 at 6:58
Jonathan OhayonJonathan Ohayon
1113 bronze badges
2 Answers
Reset to default 6It is cumbersome to specify linting options such as /** global document **/
and edit a configuration file every time you use a global.
This error can be suppressed by using --env=browser
option:
xo --env=browser [<file|glob> ...]
Note: Same problem es with Node.js, where the linter will plain that require
and friends are not defined. The switch has to change to --env=node
in that case.
However, XO defaults the env
to node
, therefore this will not be a problem in most cases. You will need multiple environments if your project contains both client and server files. in that case, --env
switch can be set multiple times:
xo --env=browser --env=node [<file|glob> ...]
You have to define globals in ESLint. There are two ways to acplish this, firstly as a ment in your code:
/* global document */
Or you can configure in configuration file like so:
{
"globals": {
"var1": true,
"var2": false
}
}
See the ESLint docs for more