Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tools/eslint-rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {
RULE_NAME as consistentCallbackTypeName,
rule as consistentCallbackType,
} from './rules/consistent-callback-type';
import {
RULE_NAME as baseHookNoForbiddenRuntimeName,
rule as baseHookNoForbiddenRuntime,
} from './rules/base-hook-no-forbidden-runtime';

/**
* Import your custom workspace rules at the top of this file.
Expand Down Expand Up @@ -32,6 +36,7 @@ module.exports = {
*/
rules: {
[consistentCallbackTypeName]: consistentCallbackType,
[baseHookNoForbiddenRuntimeName]: baseHookNoForbiddenRuntime,
[noRestrictedGlobalsName]: noRestrictedGlobals,
[noMissingJsxPragmaName]: noMissingJsxPragma,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Placeholder so the tsconfig has an actual file to anchor the project.
// RuleTester test cases reference filenames inside this directory but their
// content comes from the inline `code` field.
export const dummy = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Placeholder anchor for typed RuleTester cases. The actual code being linted
// comes from each test's inline `code` field; this file just needs to exist so
// that the fixture tsconfig's Program contains the filename used by tests.
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { useB } from './b';
import { runHeavy } from 'heavy-runtime';

export function useA(): number {
runHeavy();
return useB() + 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useA } from './a';

export function useB(): number {
// Keep the static import cycle while avoiding direct execution recursion.
return (useA as unknown as () => number).length;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Cyclic graph where `a` imports a forbidden runtime and `b` reaches it only transitively.
export { useA } from './a';
export { useB } from './b';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { useB } from './b';

export function useA(): number {
return useB() + 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useA } from './a';

export function useB(): number {
// Pretend lazy ref to break true cycle at runtime; the static graph is cyclic.
return (useA as unknown as () => number).length;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Cyclic re-export — exercises the cycle-safety of the transitive walk.
export { useA } from './a';
export { useB } from './b';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function runHeavy(): { tag: 'heavy' } {
return { tag: 'heavy' };
}

export type HeavyOptions = { kind: 'heavy' };
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function runLight(_opts?: { mode: 'light' }): void {
/* noop */
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { runHeavy } from 'heavy-runtime';

export type HeavyType = { tag: 'heavy' };

export function useHeavy(): HeavyType {
return runHeavy();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { HeavyType } from './heavy';

export { useHeavy } from './heavy';
export { useLight } from './light';
export type { LightOptions } from './light';
// Re-export of a type-only thing from the heavy module — must not count as a runtime reach.
export type { HeavyType } from './heavy';

export type HeavyWrapper = { tag: 'heavy-wrapper'; inner: HeavyType };
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { runLight } from 'light-helper';

export type LightOptions = { mode: 'light' };

export function useLight(opts?: LightOptions): void {
runLight(opts);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "node",
"lib": ["ES2022", "DOM"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"watched-pkg": ["./stubs/watched-pkg/index.ts"],
"watched-pkg/*": ["./stubs/watched-pkg/*"],
"heavy-runtime": ["./stubs/heavy-runtime/index.ts"],
"light-helper": ["./stubs/light-helper/index.ts"],
"cyclic-pkg": ["./stubs/cyclic-pkg/index.ts"],
"cyclic-heavy-pkg": ["./stubs/cyclic-heavy-pkg/index.ts"]
}
},
"include": ["src/**/*.ts", "src/**/*.tsx", "stubs/**/*.ts"]
}
Loading
Loading