Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Custom rule that requires type checking throwing "requires type checking" error #1522

Closed
T-Hugs opened this issue Aug 26, 2016 · 2 comments
Closed

Comments

@T-Hugs
Copy link

T-Hugs commented Aug 26, 2016

New to TSLint so let me know if I'm doing something wrong...

Bug Report

  • TSLint version: 3.15.1
  • TypeScript version: 2.0.0
  • Running TSLint via: CLI

with tslint.json configuration:

{
  "_extends": "tslint:latest",
  "rules": {
    "SetTimeoutString": true    
  },
  "rulesDirectory": [
    "C:/dev/seccheck/rules/"
  ]
}

SetTimeoutStringRule.ts:

import * as ts from "typescript";
import * as Lint from "tslint/lib/lint";

export class Rule extends Lint.Rules.TypedRule {
    public static FAILURE_STRING = "setTimeout forbidden with string as param1.";

    public applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] {
        return this.applyWithWalker(new NoSetTimeoutWithStringWalker(sourceFile, this.getOptions(), program));
    }
}

// The walker takes care of all the work.
class NoSetTimeoutWithStringWalker extends Lint.ProgramAwareRuleWalker {
    public visitCallExpression(node: ts.CallExpression) {
        // irrelevant implementation
    }
}

Actual behavior

Error: SetTimeoutString requires type checking
    at Rule.TypedRule.apply (C:\dev\seccheck\node_modules\tslint\lib\language\rule\typedRule.js:14:15)
    at Linter.lint (C:\Users\trgau\AppData\Roaming\npm\node_modules\tslint\lib\tslint.js:68:37)
    at processFile (C:\Users\trgau\AppData\Roaming\npm\node_modules\tslint\lib\tslint-cli.js:138:29)
    at C:\Users\trgau\AppData\Roaming\npm\node_modules\tslint\lib\tslint-cli.js:177:74
    at Array.forEach (native)
    at Object.<anonymous> (C:\Users\trgau\AppData\Roaming\npm\node_modules\tslint\lib\tslint-cli.js:177:41)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)

Expected behavior

No errors. I tried using built-in rules that require type checking, and they seem to work fine. In tslint.js, the following if-condition is failing:

if (this.program && rule instanceof typedRule_1.TypedRule)

Specifically rule instanceof typedRule_1.TypedRule.

@jkillian
Copy link
Contributor

Sorry for the delayed response @trevorsg - did you figure this out yet?

@T-Hugs
Copy link
Author

T-Hugs commented Sep 21, 2016

Hey @jkillian, haven't looked at it anymore. I am starting on a new project that will involve custom TSLint rules that use the type checker, so I will let you know if I run into a similar problem.

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

3 participants