title: Custom ESLint rule - Share data between scopes
body: <p>I am writing an ESLint rule, and I have two scopes, one that &quot;scans&quot; the file and looks for export declarations, and the other scope runs when inside a specific file (index.ts).</p>
  <p>I need to &quot;collect&quot; the result of the previous run and save it. Is there a best practice here for sharing data between 2 scopes?</p>
  <p>Consider the code:</p>
  <pre><code>module.exports = {
  'a-rule': {
    meta: {
     type: 'problem',
   },
  
  create(context) {
    const filename = context.getFilename();
    
    return { 
  
      Program: (node) =&gt; {
        node.body.forEach(node =&gt; {
          if (node.type === 'ExportNamedDeclaration') {
            const absolutePath = path.resolve(filename);
            array.push(absolutePath);
          } else if (node.type === 'SomeOtherUseCase') {
            console.log(array); // empty
          }      
      }
    }
  </code></pre>
  <p>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.</p>
  <p>Thanks</p>