Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda