Tslint: strange behavior when installing via [email protected], e.g. whitespace "check-separator" in JSDoc

Created on 27 Sep 2017  ยท  25Comments  ยท  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.7.0
  • __TypeScript version__: 2.3.4
  • __Running TSLint via__: (pick one) CLI / Node.js API / VSCode / grunt-tslint / Atom / Visual Studio / etc
    Using ng lint

TypeScript code being linted

class TsLintBug {

  /**
   * Adds x and y.
   */
  public add = (x: number, y: number): number => {
    return x + y;
  };

  /**
   * Subtracts y from x.
   * @returns {number}
   */
  public subtract = (x: number, y: number): number => {
    return x + y;
  };

}

with tslint.json configuration:

    "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type"
    ],

Actual behavior

ERROR: C:/src/.../TsLintBug.ts[10, 3]: missing whitespace

The linter wants the jsdoc comment start to be modified from /** to /* *. Which fixes the issue, but breaks the jsdoc.

Other workaround which "fix" this tslint error:

  1. Removing the trailing ; on the add method.
  2. Removing the @returns line in the second jsdoc.

Note that if you put a @returns line on the first jsdoc, and remove it from the second jsdoc, the error goes away.

Removing the "check-separator" line from tslint.json also makes the error go away (took me a while to figure that one out).

Expected behavior

No tslint errors.

External

Most helpful comment

I was able to reproduce this issue with a slightly different file in my project.
```.{typescript}
class TsLintBug {
public subtract(x: number, y: number): number;

/**

  • Subtracts y from x.
  • @param foo bar
  • @returns {number}
    */
    public subtract(x: number, y: number): number {
    return x + y;
    }
    }
    ```
    One of the differences between yarn and npm is the version of tsutils that was installed. yarn 1.1.0 is currently installing 2.8.2, whereas npm installs 2.11.1 (both satisfy tslint's requirement of "^2.8.1"). When I upgraded to [email protected] I saw this false positive go away. Unfortunately I can't reproduce from a clean repo, only in my rather large project, but I hope this helps someone.

All 25 comments

I tried to reproduce this with [email protected] and 2.5.2
I didn't see any error

Can you reproduce this without any third party tool, i.e. running tslint -c tslint.json tslintbug.ts directly from command line?

I have the same issue after purging my node_modules and reinstalling this afternoon. Removing check-separator let the lint pass, not ideal though.

tslint 5.6.0
typescript 2.3.4

Edit:

As mentioned below, if I force yarn to be v1.0.2 and reinstall my node_modules then linting completes with no errors.

https://github.com/palantir/tslint/issues/3244#issuecomment-332142831 indicates that there might be a problem when using yarn 1.1.0
Can you confirm that you used yarn to install tslint?

Yes - I did use yarn to install tslint. I will try to reproduce using both npm and yarn, with no 3rd party tools.

I had the same issue using yarn 1.1.0 but not with yarn 1.0.2 ... This seems to be a yarn issue.

Given the following files:

tslint.json

{
  "rules": {
    "whitespace": [
      true,
      "check-separator"
    ]
  } 
}

bug.ts

class TsLintBug {

  /**
   * Adds x and y.
   */
  public add = (x: number, y: number): number => {
    return x + y;
  };

  /**
   * Subtracts y from x.
   * @returns {number}
   */
  public subtract = (x: number, y: number): number => {
    return x + y;
  };

}

Then I can not reproduce with either npm 5.4.2 or yarn 1.1.0:

$ rm -rf package.json package-lock.json yarn.lock node_modules/ && npm --version && npm install typescript tslint && npm list && ./node_modules/.bin/tslint --config tslint.json bug.ts && echo "tslint success !"5.4.2
npm WARN saveError ENOENT: no such file or directory, open '/tmp/q/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/tmp/q/package.json'
npm WARN q No description
npm WARN q No repository field.
npm WARN q No README data
npm WARN q No license field.

+ [email protected]
+ [email protected]
added 31 packages in 1.87s
/tmp/q
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected] deduped
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected] deduped
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected] deduped
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected] deduped
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚ โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ””โ”€โ”€ [email protected] deduped
โ””โ”€โ”€ [email protected]

tslint success !
$ rm -rf package.json package-lock.json yarn.lock node_modules/ && yarn add typescript tslint && ./node_modules/.bin/tslint --config tslint.json bug.ts && echo "tslint success !"
yarn add v1.1.0
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 31 new dependencies.
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ”œโ”€ [email protected]
โ””โ”€ [email protected]
Done in 2.06s.
tslint success !

I was able to reproduce this issue with a slightly different file in my project.
```.{typescript}
class TsLintBug {
public subtract(x: number, y: number): number;

/**

  • Subtracts y from x.
  • @param foo bar
  • @returns {number}
    */
    public subtract(x: number, y: number): number {
    return x + y;
    }
    }
    ```
    One of the differences between yarn and npm is the version of tsutils that was installed. yarn 1.1.0 is currently installing 2.8.2, whereas npm installs 2.11.1 (both satisfy tslint's requirement of "^2.8.1"). When I upgraded to [email protected] I saw this false positive go away. Unfortunately I can't reproduce from a clean repo, only in my rather large project, but I hope this helps someone.

In my case I was also able to get rid of the error by upgrading my deps. I tried to isolate which one made a difference but was unable to. If somebody want to get to the bottom of this, i could provide before/after yarn.lock files...

If this is really related to the version of tsutils it should be fixed once #3258 lands.

That's still very strange. I didn't make any changes in tsutils that are related to those failures.
Maybe there's also a difference in the installed version of typescript?

I tried forcing my project's version of typescript, tsutils and tslint in a clean project, but still didn't observe the bug. When the bug occurred in my project, utils.forEachTokenWithTrivia was yielding an identifier token for foo (in @param foo), but when I upgraded tsutils it simply skipped that range. I can only guess that this occurs with a specific configuration of packages. I tried isolating them in my project's lockfile, but I have multiple versions of some of the dependencies tslint requires, so it doesn't seem likely I'll discover the magic combination. Based on what fixed my issue it would be reasonable to close this issue when tsutils is upgraded.

utils.forEachTokenWithTrivia was yielding an identifier token for foo (in @param foo)

I already thought that something like this would be the case. I'm puzzled why that could happen. The function excludes everything related to JSDoc.
It's only possible if something messes with the ts.SyntaxKind enum...

Anyways, thanks @nikklassen for digging into this. Let's hope this is fixed with the next release of tslint.

In my project I could make the following observations:

  • tsutils not as direct dependency & typescript 2.4.2
    -> error
  • tsutils 2.11.2 as dependency & typescript 2.4.2
    -> no error
  • tsutils not as direct dependency & typescript >= 2.5.0
    -> no error

In all cases yarn gets tsutils 2.11.2.

BUT the error seems only to occur if I've got a dependency that again has a dependency on typescript. In my case this was compodoc.

Are there multiple different versions of typescript installed? I'd need to know which package uses which version of typescript.

yarn list v1.1.0
โ”œโ”€ @compodoc/[email protected]
โ”‚ โ””โ”€ [email protected]
โ”œโ”€ @compodoc/[email protected]
โ”‚ โ””โ”€ [email protected]
โ””โ”€ [email protected]

But tsutils also installs its own typescript in version 2.5.2, though it is only a devDependency.

I was unable to create a minimal repro. I only got the faulty install on the first attempt. After that yarn had some even weirder bugs.
But someone else already reproduced the problem. See https://github.com/hexa00/repro-tslint-yarn
Here's the issue in the yarn issue tracker: https://github.com/yarnpkg/yarn/issues/4539

Can someone on this thread verify that it works with [email protected]?

I can confirm the issue I was seeing that was present with [email protected] is no longer happening with [email protected]

Great. Let's close this.
If someone still has similar issues, please leave a comment or open a new issue.

Hi,

I am getting this issue now.

yarn -v       
1.3.2

and

"devDependencies": {
    "tslint": "^5.9.1",
    "tslint-eslint-rules": "^4.1.1",
    "typescript": "^2.6.1"
},

code where error shows:

/**
 * @param {FilterOptions} options   "here i got issue"
 * @return {PropertyDecorator}
 * @constructor
 */
export function Filter(options: FilterOptions): PropertyDecorator;

One thing to note is that is was happening only in the exported functions. Other private functions in module (not exported) did not have it.

Is there any deps I could force here. Error start to appear after I moved to yarn, with [email protected] was not a problem.

thanks in advance

David

This has just started to happen to us as well with yarn 1.3.2, in our case I am highly suspicious it might be related with the fact we have started to import a private package with tslint rules into the project. Downgrading to 1.0.1 fixes it, but not to 1.2.1.

I upgraded to latest typescript today to 3.4, and this started happening to me as well. i'm on yarn 1.15.2

ok, resolved it. I did yarn cache clean, and re-installed, and it is working now.

This happen to me.

Tried to isolate my project from a monorepo (using lerna) and install via npm. Error still persist.
Both npm and yarn install tsutils 2.29.0.

import { FormGroup, ValidationErrors } from '@angular/forms';

/**
 * @example
    ^... missing whitespace
 * const formGroup = this.formBuilder.group({
 *  field1: '',
 *  field2: '',
 * }, {
 *  validators: [testValue]
 * })
 */
export function testValue(formGroup: FormGroup): ValidationErrors | null {
 ...
 return null;
}

Once I remove import statement, no error reported.

Following is my current setup.

yarn -v
1.16.0

package.json

{
  "devDependencies": {
    "tslint": "~5.16.0",
    "typescript": "~3.4.5"
  }
}

๐Ÿค– Beep boop! ๐Ÿ‘‰ TSLint is deprecated ๐Ÿ‘ˆ and you should switch to typescript-eslint! ๐Ÿค–

๐Ÿ”’ This issue is being locked to prevent further unnecessary discussions. Thank you! ๐Ÿ‘‹

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rajinder-yadav picture rajinder-yadav  ยท  3Comments

CSchulz picture CSchulz  ยท  3Comments

adidahiya picture adidahiya  ยท  3Comments

SwintDC picture SwintDC  ยท  3Comments

zewa666 picture zewa666  ยท  3Comments