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

Cannot run custom typed rules in the CLI #1637

Closed
JoshuaKGoldberg opened this issue Oct 16, 2016 · 2 comments
Closed

Cannot run custom typed rules in the CLI #1637

JoshuaKGoldberg opened this issue Oct 16, 2016 · 2 comments

Comments

@JoshuaKGoldberg
Copy link
Contributor

Bug Report

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

tslint.json

test.json:

{
    "rules": {
        "my-typed-rule": true
    }
}

Expected behavior

tslint --project test.json --type-check true --rules-dir src/rules

> (tslint output from my-custom-rule)

Actual behavior

tslint --project test.json --type-check true --rules-dir src/rules

Error: my-custom-rule requires type checking
    at Rule.TypedRule.apply (C:\Code\tslint-test\node_modules\tslint\lib\language\rule\typedRule.js:15:15)
    at Linter.lint (C:\Users\jogol\AppData\Roaming\npm\node_modules\tslint\lib\tslint.js:69:37)
    at processFile (C:\Users\jogol\AppData\Roaming\npm\node_modules\tslint\lib\tslint-cli.js:138:29)
    at C:\Users\jogol\AppData\Roaming\npm\node_modules\tslint\lib\tslint-cli.js:177:74
    at Array.forEach (native)
    at Object.<anonymous> (C:\Users\jogol\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)
@JoshuaKGoldberg
Copy link
Contributor Author

JoshuaKGoldberg commented Oct 16, 2016

I think the issue causing this is in tslintMulti.ts, where it checks if a rule is a TypedRule:

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

In my call stack the TypedRule can be the one defined in C:\Code\tslint-test\node_modules\tslint or C:\Users\jogol\AppData\Roaming\npm\node_modules\tslint.

A couple solution proposals:

  • Make an isTypedRule equivalent in the class (I think preferable, for future compability)
  • Check the constructor.name (I think less preferable)

@JoshuaKGoldberg
Copy link
Contributor Author

Works for me!

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