Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!