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

107
Visualizações
Custom ESLint rule - Share data between scopes

I am writing an ESLint rule, and I have two scopes, one that "scans" the file and looks for export declarations, and the other scope runs when inside a specific file (index.ts).

I need to "collect" the result of the previous run and save it. Is there a best practice here for sharing data between 2 scopes?

Consider the code:

module.exports = {
'a-rule': {
  meta: {
   type: 'problem',
 },

create(context) {
  const filename = context.getFilename();
  
  return { 

    Program: (node) => {
      node.body.forEach(node => {
        if (node.type === 'ExportNamedDeclaration') {
          const absolutePath = path.resolve(filename);
          array.push(absolutePath);
        } else if (node.type === 'SomeOtherUseCase') {
          console.log(array); // empty
        }      
    }
  }

The code will run multiple times in a few different scopes so that that array will get re-instantiated. I found a solution to declare the array at the beginning of the rule file, but I wonder if there isn't a better way.

Thanks

about 4 years ago · Juan Pablo Isaza
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