add eslint-scope

This commit is contained in:
Toru Nagashima 2018-02-17 15:35:03 +09:00
parent 423ace8fe7
commit 77cbc856a7
No known key found for this signature in database
GPG Key ID: 8E7D8A6911CA8C30
4 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,41 @@
import * as eslint from "eslint";
import * as estree from "estree";
import * as escope from "eslint-scope";
declare const program: estree.Program;
declare const scope: escope.Scope;
declare const variable: escope.Variable;
declare const reference: escope.Reference;
const manager1: escope.ScopeManager = escope.analyze(
program,
{
directive: false,
ecmaVersion: 2018,
fallback(node) {
return Object.keys(node);
},
ignoreEval: true,
impliedStrict: true,
nodejsScope: true,
optimistic: true,
sourceType: "module"
}
);
const manager2: escope.ScopeManager = escope.analyze(
program,
{
ecmaVersion: 5,
ignoreEval: false,
impliedStrict: false,
nodejsScope: false,
optimistic: false,
sourceType: "script"
}
);
const manager3: escope.ScopeManager = escope.analyze(program);
const managerInterface: eslint.Scope.ScopeManager = manager1;
const scopeInterface: eslint.Scope.Scope = scope;
const variableInterface: eslint.Scope.Variable = variable;
const referenceInterface: eslint.Scope.Reference = reference;

64
types/eslint-scope/index.d.ts vendored Normal file
View File

@ -0,0 +1,64 @@
// Type definitions for eslint-scope 3.7
// Project: http://github.com/eslint/eslint-scope
// Definitions by: Toru Nagashima <https://github.com/mysticatea>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import * as eslint from "eslint";
import * as estree from "estree";
export const version: string;
export class ScopeManager implements eslint.Scope.ScopeManager {
scopes: Scope[];
globalScope: Scope;
acquire(node: {}, inner?: boolean): Scope | null;
getDeclaredVariables(node: {}): Variable[];
}
export class Scope implements eslint.Scope.Scope {
type: "block" | "catch" | "class" | "for" | "function" | "function-expression-name" | "global" | "module" | "switch" | "with" | "TDZ";
isStrict: boolean;
upper: Scope | null;
childScopes: Scope[];
variableScope: Scope;
block: estree.Node;
variables: Variable[];
set: Map<string, Variable>;
references: Reference[];
through: Reference[];
functionExpressionScope: boolean;
}
export class Variable implements eslint.Scope.Variable {
name: string;
identifiers: estree.Identifier[];
references: Reference[];
defs: eslint.Scope.Definition[];
}
export class Reference implements eslint.Scope.Reference {
identifier: estree.Identifier;
from: Scope;
resolved: Variable | null;
writeExpr: estree.Node | null;
init: boolean;
isWrite(): boolean;
isRead(): boolean;
isWriteOnly(): boolean;
isReadOnly(): boolean;
isReadWrite(): boolean;
}
export interface AnalysisOptions {
optimistic?: boolean;
directive?: boolean;
ignoreEval?: boolean;
nodejsScope?: boolean;
impliedStrict?: boolean;
fallback?: string | ((node: {}) => string[]);
sourceType?: "script" | "module";
ecmaVersion?: number;
}
export function analyze(ast: {}, options?: AnalysisOptions): ScopeManager;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"eslint-scope-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }