eslint 不检测解构变量
eslint doesnt detect deconstruct variables
我有以下代码:
for ([uri, { socket, settings }] of map) {
// parse websocket urls
let url1 = new url.URL(ws.url);
let url2 = new url.URL(uri);
// override http(s) with ws(s)
url2.protocol = url1.protocol;
console.log(`Bridge "%s" <-> ${socket}://${host}:${port}`, url2);
bridge(url2, settings, socket);
}
解构变量,但是eslint没有检测到变量:
/home/.../handler.js
81:11 error 'uri' is not defined no-undef
81:18 error 'socket' is not defined no-undef
81:26 error 'settings' is not defined no-undef
85:32 error 'uri' is not defined no-undef
90:40 error 'socket' is not defined no-undef
90:52 error 'host' is not defined no-undef
90:60 error 'port' is not defined no-undef
92:22 error 'settings' is not defined no-undef
92:32 error 'socket' is not defined no-undef
✖ 9 problems (9 errors, 0 warnings)
我如何告诉 linter 它很好并且变量检测正确?
.eslintrc.json
{
"env": {
"node": true,
"commonjs": true,
"es2021": true
},
"parserOptions": {
"ecmaVersion": 12
},
"ignorePatterns": [
"node_modules"
],
"extends": [
"eslint:recommended"
],
"rules": {
"semi": [
"error",
"always"
],
"quotes": [
"error",
"double",
{
"avoidEscape": true, // Does not work https://eslint.org/docs/rules/quotes#avoidescape
"allowTemplateLiterals": true
}
]
}
}
for of 循环需要const,for(const
const map = [
[
"uri",
{
socket: "",
settings: ''
},
],
];
for (const [uri, { socket, settings }] of map) {
console.log(uri, socket, settings);
}
我有以下代码:
for ([uri, { socket, settings }] of map) {
// parse websocket urls
let url1 = new url.URL(ws.url);
let url2 = new url.URL(uri);
// override http(s) with ws(s)
url2.protocol = url1.protocol;
console.log(`Bridge "%s" <-> ${socket}://${host}:${port}`, url2);
bridge(url2, settings, socket);
}
解构变量,但是eslint没有检测到变量:
/home/.../handler.js
81:11 error 'uri' is not defined no-undef
81:18 error 'socket' is not defined no-undef
81:26 error 'settings' is not defined no-undef
85:32 error 'uri' is not defined no-undef
90:40 error 'socket' is not defined no-undef
90:52 error 'host' is not defined no-undef
90:60 error 'port' is not defined no-undef
92:22 error 'settings' is not defined no-undef
92:32 error 'socket' is not defined no-undef
✖ 9 problems (9 errors, 0 warnings)
我如何告诉 linter 它很好并且变量检测正确?
.eslintrc.json
{
"env": {
"node": true,
"commonjs": true,
"es2021": true
},
"parserOptions": {
"ecmaVersion": 12
},
"ignorePatterns": [
"node_modules"
],
"extends": [
"eslint:recommended"
],
"rules": {
"semi": [
"error",
"always"
],
"quotes": [
"error",
"double",
{
"avoidEscape": true, // Does not work https://eslint.org/docs/rules/quotes#avoidescape
"allowTemplateLiterals": true
}
]
}
}
for of 循环需要const,for(const
const map = [
[
"uri",
{
socket: "",
settings: ''
},
],
];
for (const [uri, { socket, settings }] of map) {
console.log(uri, socket, settings);
}