Skip to content

chore: fix scope test #410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2023
Merged
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
9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/await04-scope-output.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/i18n-test-scope-output.json

Large diffs are not rendered by default.

9,342 changes: 0 additions & 9,342 deletions tests/fixtures/parser/ast/issue325-eslint-plugin-svelte-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/issue338-eslint-plugin-svelte-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/reactive-with-var04-ts-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-$$props01-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-$$slots01-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-$$slots02-no-slot-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-$$slots03-named-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-$$slots04-named-scope-output.json

Large diffs are not rendered by default.

9,342 changes: 0 additions & 9,342 deletions tests/fixtures/parser/ast/ts-await-non-promise01-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-each01-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-event01-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-event02-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-event03-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-event04-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-event05-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-event06-scope-output.json

Large diffs are not rendered by default.

9,342 changes: 0 additions & 9,342 deletions tests/fixtures/parser/ast/ts-issue226-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-let/ts-let01-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-newline-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-not-reactive01-scope-output.json

Large diffs are not rendered by default.

9,342 changes: 0 additions & 9,342 deletions tests/fixtures/parser/ast/ts-promise01-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-promise02-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-reactive01-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-reactive02-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-reactive03-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-reactive04-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-reactive05-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-reactive06-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-scope-issue01-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-shorthand-attr01-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-store01-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-store02-scope-output.json

Large diffs are not rendered by default.

9,318 changes: 0 additions & 9,318 deletions tests/fixtures/parser/ast/ts-store03-scope-output.json

Large diffs are not rendered by default.

9,366 changes: 0 additions & 9,366 deletions tests/fixtures/parser/ast/ts-use01-scope-output.json

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion tests/src/parser/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { Reference, Scope, ScopeManager, Variable } from "eslint-scope";
import type * as TSESScopes from "@typescript-eslint/scope-manager";
import type { SvelteNode } from "../../../src/ast";
import type { StyleContext } from "../../../src";
import { TS_GLOBALS } from "./ts-vars";

const AST_FIXTURE_ROOT = path.resolve(__dirname, "../../fixtures/parser/ast");
const BASIC_PARSER_OPTIONS: Linter.ParserOptions = {
Expand Down Expand Up @@ -290,9 +291,14 @@ export function styleContextToJson(styleContext: StyleContext): string {
}

function normalizeScope(scope: Scope | TSESScopes.Scope): any {
let variables = scope.variables as TSESScopes.Variable[];
if (scope.type === "global") {
// Exclude well-known variables as they do not need to be tested.
variables = variables.filter((v) => !TS_GLOBALS.includes(v.name));
}
return {
type: scope.type,
variables: scope.variables.map(normalizeVar),
variables: variables.map(normalizeVar),
references: scope.references.map(normalizeReference),
childScopes: scope.childScopes.map(normalizeScope),
through: scope.through.map(normalizeReference),
Expand Down
13 changes: 13 additions & 0 deletions tests/src/parser/ts-vars.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as parser from "@typescript-eslint/parser";
import * as scope from "@typescript-eslint/scope-manager";

const result = parser.parseForESLint("", { lib: ["lib", "esnext", "dom"] });
const scopeManager =
result.scopeManager ??
scope.analyze(result.ast as any, {
lib: ["lib", "esnext", "dom"],
});

export const TS_GLOBALS = scopeManager
.globalScope!.variables.map((v) => v.name)
.sort();