Tslint: Error: no-for-in-array requires type checking

Created on 29 Jul 2016  ·  18Comments  ·  Source: palantir/tslint

Bug Report

  • TSLint version: 3.14.0
  • TypeScript version: 2.0.0
  • Running TSLint via: Node.js API

    TypeScript code being linted

with tslint.json configuration:

{
    "linterOptions": {
        "typeCheck": true
    },
    "rules": {
        "no-for-in-array": true
    }
}

Actual behavior

Error: no-for-in-array requires type checking
at Rule.TypedRule.apply (...\node_modules\tslint\lib\language\rule\typedRule.js:14:15)
at Linter.lint (...\node_modules\tslint\lib\tslint.js:65:37)
...

Expected behavior

No errors

Question

Most helpful comment

@adidahiya What is the point that you do not make this API public?
I guess it will be very useful to set all TSLint settings via tslint.json.

All 18 comments

linterOptions in tslint.json is actually a private API. If using the CLI, you must use the --type-check flag. If using the Node.js APIs, you'll need to follow a pattern similar to src/test.ts.

This is ugly and must be public

Well, it's not a documented API... how did you discover it? We reserve the right to experiment with APIs in our project before committing to them...

Reading code of sample configurations, and reading code is the best documentation in most javascript projects. Developers update documentation very slow, released features may be documented after long time, some projects does not provide documentation about Node API use totally prefer to offer only CLI use, that is ugly.

Many build tools plugins use Node.JS api, and it's functionality must not differ from CLI, because CLI does not provide ability to control process of output etc.
For example: https://github.com/panuhorsmalahti/gulp-tslint/blob/master/index.js

reading code is the best documentation in most javascript projects

Sure, that's partially true -- that's why I pointed out src/test.ts in my comment above.


I agree that the Node.js API is useful and should be documented. We _do_ have documentation for parts that are well-supported, including type checking, right here in the README. Also, being a typescript project, we naturally have documentation in the form of typings declaration files published in the NPM package.

Sure, the GH pages site is a little behind compared to the README -- we're working on improving that. But I might suggest a slightly different tone for your form of contribution here -- you will probably experience more success by, say, sending a documentation PR before calling a project "ugly".

The GH pages site is now updated with the latest rule metadata from the most recent release. (I realize this is a little tangential to the issue at hand though.)

Currently, tslint.json files _only specify how individual files should be linted_ and _do not specify overarching linter options_. Allowing tslint.json files to specify overarching options is a bit of a paradigm change, and that's why we're experimenting with some new setups internally before changing any public-facing API.

Just ran into that error after attempting to enable no-for-in-array in a tslint.json, and this GH issue was the only Google result that popped up. Can the error message at least point to documentation?

As a side note, is there documentation on enabling it for the Gulp runner?

Not sure with regards to the Gulp runner. We need to update the docs site to make it more clear which rules require typechecking and what that means

Can u plz tell me how would I deal with this issue on an IDE like webstorm?

Could you plz make linterOptions typecheck public or something?

Actually, I think making type checking a rule would be more useful and accessible.

Any updates?

@StevenTheEVILZ just disable the rule in your tslint.json. The Webstorm plugin needs to be updated to support the new type checking APIs -- that's external to this repo. This needs to happen regardless of linterOptions in tslint.json being public (I assume they're using the Node.js APIs, not the CLI, in the plugin).

@adidahiya I've already fixed the problem by using the tslint js lib. BTW they are using the cli and capturing its output.

@adidahiya What is the point that you do not make this API public?
I guess it will be very useful to set all TSLint settings via tslint.json.

I'm using create-react-app with react-scripts-ts and keep getting Warning: The 'no-use-before-declare' rule requires type information. because there's no way for me to specify command line parameters. I don't really understand what is the reasoning for not being able to specify all options in tslint.json.

As of #3322, typeCheck has been deprecated. Closing this issue for housekeeping.

Was this page helpful?
0 / 5 - 0 ratings