Skip to content

Commit

Permalink
revert(#111): remove scc (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW authored Jul 23, 2024
1 parent 38aa4cb commit 0307ff2
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 307 deletions.
7 changes: 7 additions & 0 deletions .changeset/hungry-clocks-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"eslint-plugin-import-x": patch
---

Reverts #111. The introduction of SCC causes extra overhead that overcomes the early return it introduced.

A new `no-cycle-next` rule is being implemented using the graph. It won't be backward compatible with the current rule `no-cycle`. The current `no-cycle` rule will become `no-cycle-legacy` in the next major version.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"eslint": "^8.56.0 || ^9.0.0-0"
},
"dependencies": {
"@rtsao/scc": "^1.1.0",
"@typescript-eslint/utils": "^7.4.0",
"debug": "^4.3.4",
"doctrine": "^3.0.0",
Expand Down
15 changes: 0 additions & 15 deletions src/rules/no-cycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import type { DeclarationMetadata, ModuleOptions } from '../utils'
import {
ExportMap,
StronglyConnectedComponents,
isExternalModule,
createRule,
moduleVisitor,
Expand Down Expand Up @@ -89,8 +88,6 @@ export = createRule<[Options?], MessageId>({
isExternalModule(name, resolve(name, context)!, context)
: () => false

const scc = StronglyConnectedComponents.get(filename, context)

return {
...moduleVisitor(function checkSourceValue(sourceNode, importer) {
if (ignoreModule(sourceNode.value)) {
Expand Down Expand Up @@ -130,18 +127,6 @@ export = createRule<[Options?], MessageId>({
return // no-self-import territory
}

/* If we're in the same Strongly Connected Component,
* Then there exists a path from each node in the SCC to every other node in the SCC,
* Then there exists at least one path from them to us and from us to them,
* Then we have a cycle between us.
*/
if (scc) {
const hasDependencyCycle = scc[filename] === scc[imported.path]
if (!hasDependencyCycle) {
return
}
}

const untraversed: Traverser[] = [{ mget: () => imported, route: [] }]

function detectCycle({ mget, route }: Traverser) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/export-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ export function recursivePatternCapture(
* don't hold full context object in memory, just grab what we need.
* also calculate a cacheKey, where parts of the cacheKey hash are memoized
*/
export function childContext(
function childContext(
path: string,
context: RuleContext | ChildContext,
): ChildContext {
Expand Down
1 change: 0 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export * from './pkg-dir'
export * from './pkg-up'
export * from './read-pkg-up'
export * from './resolve'
export * from './scc'
export * from './static-require'
export * from './unambiguous'
export * from './visit'
91 changes: 0 additions & 91 deletions src/utils/scc.ts

This file was deleted.

193 changes: 0 additions & 193 deletions test/utils/scc.spec.ts

This file was deleted.

5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1886,11 +1886,6 @@
dependencies:
"@xml-tools/parser" "^1.0.11"

"@rtsao/scc@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@rtsao/scc/-/scc-1.1.0.tgz#927dd2fae9bc3361403ac2c7a00c32ddce9ad7e8"
integrity sha512-zt6OdqaDoOnJ1ZYsCYGt9YmWzDXl4vQdKTyJev62gFhRGKdx7mcT54V9KIjg+d2wi9EXsPvAPKe7i7WjfVWB8g==

"@sinclair/typebox@^0.27.8":
version "0.27.8"
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
Expand Down

0 comments on commit 0307ff2

Please sign in to comment.