TSLint get rid of missing-whitespace
Asked Answered
V

4

27

I've been trying to scour the internet to solve this but to no avail. Perhaps you can help me. I am getting tslint 'missing whitespace' warnings that say something like:

WARNING in ./src/app/content/content.controller.ts [4, 13]: missing whitespace [5, 21]: missing whitespace

I want to get rid of the warning

Here's an example of the code.... basically anywhere I have a colon for declaring type is where the error is happening. I don't want to put a space between it so I'd like the linter to not bug me about it...

export class ContentCtrl {
filters:IFilter[];
selectedFilters:IFilter[];
filterToAdd:IFilter;

/** @ngInject */
constructor(private $log:angular.ILogService,
            private $timeout:any,
            private toastr:any,
            private filterService:FilterService) {
    const self = this;

I looked through the tslint.json file and could not figure out how to get rid of it.

I saw a promising property that said: "typedef-whitespace"

I changed it to the following but, alas, to no-avail:

"typedef-whitespace": [true,
        {
            "callSignature": "noSpace",
            "catchClause": "noSpace",
            "indexSignature": "noSpace",
            "parameter": "noSpace"
        }
    ],

How do I get rid of the 'missing whitespace' error?

Vatican answered 18/2, 2016 at 18:3 Comment(0)
D
39

This error message comes from the whitespace rule. I believe the rule wants you to add a space either before or after (not sure which) the colon in type declarations. However, if you don't like this, you can disable the rule completely, or remove the check-type option from your tslint.json file.

Dedededen answered 18/2, 2016 at 21:48 Comment(3)
Removing check-type did the job. Cheers!Vatican
add space before colon : Use code format. In IntelliJ use ctrl + alt + LFitz
I added this line "whitespace": false, to my tslint.json, but unlike other entries, it appears to have no effect in turned off validation for this rule. What am I missing?Diapedesis
G
14

You should search whitespace in tslint.json,and replace all result whith false.

And you questions can set like there:

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

set it ,if you write private nima:string, : with no space will no err.


other,

if you set one-line 's metadata to false,the class can follow no space.

if yout set no-trailing-whitespace to false, the line can use tab.

——end

Grimes answered 18/2, 2016 at 18:3 Comment(1)
Welcome to Stack Overflow, Yue Ming. Please don't use Chinese characters here. This is an English-only website. We would appreciate if you could edit your post to avoid encoding issues in Western countries... Thanks! ;)Galitea
C
2

What TSLint seems to be complaining about are the class property declarations, so maybe try adding this extra rule to "typedef-whitespace":

"property-declaration": "nospace",

You can find more about that rule here.

Consultation answered 18/2, 2016 at 19:47 Comment(1)
It's a good idea but it didn't work in my case. Thanks though!Vatican
S
0

This lint error message prompts that you need to give a space between particular characters in your code. For example, ERROR: 58:18 whitespace missing whitespace means, In line 58, you need to provide space after the 18th position in your code snippet.

Sunwise answered 26/9, 2022 at 10:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.