Skip to content

Commit

Permalink
add option to skip scc
Browse files Browse the repository at this point in the history
  • Loading branch information
soryy708 committed Aug 26, 2024
1 parent 626b91b commit 0bf41c2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/rules/no-cycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ module.exports = {
type: 'boolean',
default: false,
},
disableScc: {
description: 'When true, don\'t calculate a strongly-connected-components graph. SCC is used to reduce the time-complexity of cycle detection, but adds overhead.',
type: 'boolean',
default: false,
},
})],
},

Expand All @@ -63,7 +68,7 @@ module.exports = {
context,
);

const scc = StronglyConnectedComponentsBuilder.get(myPath, context);
const scc = options.disableScc ? {} : StronglyConnectedComponentsBuilder.get(myPath, context);

function checkSourceValue(sourceNode, importer) {
if (ignoreModule(sourceNode.value)) {
Expand Down
28 changes: 27 additions & 1 deletion tests/src/rules/no-cycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const testVersion = (specifier, t) => _testVersion(specifier, () => Object.assig

const testDialects = ['es6'];

ruleTester.run('no-cycle', rule, {
const cases = {
valid: [].concat(
// this rule doesn't care if the cycle length is 0
test({ code: 'import foo from "./foo.js"' }),
Expand Down Expand Up @@ -290,4 +290,30 @@ ruleTester.run('no-cycle', rule, {
],
}),
),
};

ruleTester.run('no-cycle', rule, {
valid: flatMap(cases.valid, (testCase) => [
testCase,
{
...testCase,
code: `${testCase.code} // disableScc=true`,
options: [{
...testCase.options && testCase.options[0] || {},
disableScc: true,
}],
},
]),

invalid: flatMap(cases.invalid, (testCase) => [
testCase,
{
...testCase,
code: `${testCase.code} // disableScc=true`,
options: [{
...testCase.options && testCase.options[0] || {},
disableScc: true,
}],
},
]),
});

0 comments on commit 0bf41c2

Please sign in to comment.