Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Support for typed rules? #294

Closed
JoshuaKGoldberg opened this issue Oct 19, 2016 · 5 comments
Closed

Support for typed rules? #294

JoshuaKGoldberg opened this issue Oct 19, 2016 · 5 comments
Milestone

Comments

@JoshuaKGoldberg
Copy link

Does tslint-microsoft-contrib have support for the new type checker rules? If not, how difficult would it be to add it in?

@HamletDRC HamletDRC added this to the None milestone Oct 20, 2016
@HamletDRC
Copy link
Member

Yes, it is already supported.

See: https://github.com/palantir/tslint/blob/master/src/rules/noForInArrayRule.ts

You need to get the Program object in your rule and then the TypeChecker object in your walker.

@JoshuaKGoldberg
Copy link
Author

Sorry, I was a little vague in the issue - does tslint-microsoft-contrib support having typed rules? Is there documentation for adding a typed rule here?

@HamletDRC
Copy link
Member

There is no documentation, but I think you just do exactly what noForInArrayRule is doing. You can use that rule as a template. Basically, having a typed rule gives you access to the TypeChecker object. YOu can see the API in typescript.d.ts:

interface TypeChecker {
    getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
    getDeclaredTypeOfSymbol(symbol: Symbol): Type;
    getPropertiesOfType(type: Type): Symbol[];
    getPropertyOfType(type: Type, propertyName: string): Symbol;
    getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
    getIndexTypeOfType(type: Type, kind: IndexKind): Type;
    getBaseTypes(type: InterfaceType): ObjectType[];
    getReturnTypeOfSignature(signature: Signature): Type;
    getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
    getSymbolAtLocation(node: Node): Symbol;
    getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): Symbol[];
    getShorthandAssignmentValueSymbol(location: Node): Symbol;
    getExportSpecifierLocalTargetSymbol(location: ExportSpecifier): Symbol;
    getTypeAtLocation(node: Node): Type;
    typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
    symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string;
    getSymbolDisplayBuilder(): SymbolDisplayBuilder;
    getFullyQualifiedName(symbol: Symbol): string;
    getAugmentedPropertiesOfType(type: Type): Symbol[];
    getRootSymbols(symbol: Symbol): Symbol[];
    getContextualType(node: Expression): Type;
    getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[]): Signature;
    getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature;
    isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
    isUndefinedSymbol(symbol: Symbol): boolean;
    isArgumentsSymbol(symbol: Symbol): boolean;
    isUnknownSymbol(symbol: Symbol): boolean;
    getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
    isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
    getAliasedSymbol(symbol: Symbol): Symbol;
    getExportsOfModule(moduleSymbol: Symbol): Symbol[];
    getJsxElementAttributesType(elementNode: JsxOpeningLikeElement): Type;
    getJsxIntrinsicTagNames(): Symbol[];
    isOptionalParameter(node: ParameterDeclaration): boolean;
}

@HamletDRC
Copy link
Member

There are a whole bunch of rules that we should convert to use this instead of what we do today.

@JoshuaKGoldberg
Copy link
Author

Thanks - I am actually familiar with the new APIs; I'd asked here because I sent in a couple PRs to main tslint for issues that were filed under tslint-microsoft-contrib.

palantir/tslint#1632
palantir/tslint#1644

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants