Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
eslint doesnt detect deconstruct variables

I have the following code:

    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);

    }

which deconstruct variables, but eslint does not detect the variables:

/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)

How can i tell the linter that its fine and the variables are detect properly?

.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
            }
        ]
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

for of loop requires const, for(const

const map = [
  [
    "uri",
    {
      socket: "",
      settings: ''
    },
  ],
];

for (const [uri, { socket, settings }] of map) {
    console.log(uri, socket, settings);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda