Skip to content

Commit

Permalink
Swap out clearing cache on Program:exit
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Malton <sebastian@malton.name>
  • Loading branch information
Nokel81 committed Aug 22, 2022
1 parent 2e22613 commit 56019fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
13 changes: 9 additions & 4 deletions src/rules/no-cycle.js
Expand Up @@ -11,7 +11,6 @@ import docsUrl from '../docsUrl';

const traversed = new Set();

// todo: cache cycles / deep relationships for faster repeat evaluation
module.exports = {
meta: {
type: 'suggestion',
Expand Down Expand Up @@ -42,7 +41,6 @@ module.exports = {
},
})],
},
_traversed: traversed,
create: (context) => {
const myPath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
if (myPath === '<text>') return {}; // can't cycle-check a non-file
Expand Down Expand Up @@ -102,7 +100,7 @@ module.exports = {
// Ignore only type imports
!isOnlyImportingTypes,
);

/*
If cyclic dependency is allowed via dynamic import, skip checking if any module is imported dynamically
*/
Expand Down Expand Up @@ -139,7 +137,14 @@ module.exports = {
}
}

return moduleVisitor(checkSourceValue, context.options[0]);
return Object.assign(
moduleVisitor(checkSourceValue, context.options[0]),
{
'Program:exit': () => {
traversed.clear();
},
},
);
},
};

Expand Down
5 changes: 0 additions & 5 deletions tests/src/rules/no-cycle.js
Expand Up @@ -2,7 +2,6 @@ import { parsers, test as _test, testFilePath, testVersion as _testVersion } fro

import { RuleTester } from 'eslint';
import flatMap from 'array.prototype.flatmap';
import { beforeEach } from 'mocha';

const ruleTester = new RuleTester();
const rule = require('rules/no-cycle');
Expand All @@ -18,10 +17,6 @@ const testVersion = (specifier, t) => _testVersion(specifier, () => Object.assig

const testDialects = ['es6'];

beforeEach(() => {
rule._traversed.clear();
});

ruleTester.run('no-cycle', rule, {
valid: [].concat(
// this rule doesn't care if the cycle length is 0
Expand Down

0 comments on commit 56019fb

Please sign in to comment.