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

no-unnecessary-type-assertion always errors #200

Closed
noseglid opened this issue Sep 21, 2017 · 8 comments
Closed

no-unnecessary-type-assertion always errors #200

noseglid opened this issue Sep 21, 2017 · 8 comments
Labels

Comments

@noseglid
Copy link

It seems like this rule (when enabled) always errors for any type assertion. Unnecessary or not:

screen shot 2017-09-21 at 08 57 23

This is not a problem when running tslint from terminal - which is odd because I can't see that anything special is med on a per-rule basis in this package.

@Xapphire13
Copy link
Contributor

Does it occur when you have "use local TSLint" turned on (assuming you have TSLint installed locally)? Or, what version of TSLint are you using on the command line?

@noseglid
Copy link
Author

I have Try using the local tslint package (if exists) enabled.
TSlint on command line:

./node_modules/.bin/tslint --version
5.7.0

(installed via yarn add tslint).

@Xapphire13
Copy link
Contributor

The version of TSLint shipped with linter-tslint is currently 5.5.0 if i recall correctly. Could you downgrade to that and run again in command line?

@noseglid
Copy link
Author

noseglid commented Sep 21, 2017

The command line don't complain with 5.5.0, but this plugin does.

I removed a semicolon too to make sure that the file was linted properly, and it was.

I'm invoking tslint as ./node_modules/.bin/tslint --project tsconfig.json

where tsconfig.json:

{
  "compileOnSave": true,
  "compilerOptions": {
    "module": "es6",
    "target": "es2017",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "baseUrl": "src",
    "sourceMap": true,
    "outDir": "ts-build",
    "jsx": "preserve",
    "strict": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "allowJs": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules"
  ],
  "files": [
    "./node_modules/@types/node/index.d.ts"
  ]
}

@noseglid
Copy link
Author

noseglid commented Sep 22, 2017

I've done some more digging here. I've verified that:

  • the error actually do come from the linter.
  • It is using the correct linter (e.g. the one in my node_modules).

I've written a small testscript to lint my files with the library rather than the cli:

"use strict";
var { Linter, Configuration } = require("tslint");

const program = Linter.createProgram("tsconfig.json");
const files = Linter.getFileNames(program);

const results = files.map(file => {
  console.log("Linting", file);
  const fileContents = program.getSourceFile(file).getFullText();
  const configuration = Configuration.findConfiguration("tslint.json", "./src").results;
  var options = {
      fix: false,
      formatter: "json"
  };
  const linter = new Linter(options, program);
  linter.lint(file, fileContents, configuration);
  return linter.getResult();
});


console.log(results.filter(r => r.errorCount > 0));

Which works correctly (it does not complain about the type assertion, but do complain if I put in a legitimate lint error; a missing semicolon). Any idea on how I can continue debug this?

@Xapphire13
Copy link
Contributor

Are you saying that the bug does reproduce with the script you posted?

the error actually do come from the linter.

What steps did you take to verify this?

@noseglid
Copy link
Author

Sorry for being unclear. My script does not give the no-unnecessary-type-assertion. I did this to rule out the chance that there might be a discrepancy between using the CLI and using the library.

I can see lintResult includes the error.

Another thing I noticed is that I get the following error once for each Atom window:
screen shot 2017-09-22 at 09 45 47

I have strict enabled in my tsconfig.json which implies strictNullChecks.

@Arcanemagus
Copy link
Member

Fixed by #202 (see #202 (comment)).

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

No branches or pull requests

3 participants