Questions tagged [tslint]

tslint is a static analysis linter for TypeScript.

tslint is a linter for the language, similar to jslint.

Use this tag on questions about:

  • installation
  • command-line options
  • default/built-in rules
  • rule flags
  • Custom formatters
  • creation of custom rules

Github home of tslint
NPM home of tslint

1054 questions
28
votes
1 answer

How to config VSCode's Organize Imports order?

I want to config Organize Imports's order. Right now, it moves node_modules related import statement at the very top, and local ts file at very bottom: Normal: import myFunction from './myFunction'; import fs from…
Joseph
  • 3,974
  • 7
  • 34
  • 67
28
votes
4 answers

What is the preferred declaration convention for objects or arrays: const or let?

I'm not asking what's technically possible; I know you can do const a = []; const b = {}; a.push['sup']; b.test = 'earth'; What I'm wondering is whether there's any convention for preferring let over const when it comes to arrays and objects that…
redOctober13
  • 3,662
  • 6
  • 34
  • 61
28
votes
3 answers

What to include in configuration of tslint.json?

I don't know which rule should be included in tslint.json. Can anyone show me the common or standard use of tslint.json? How to write a tslint.json file?
Ng2-Fun
  • 3,307
  • 9
  • 27
  • 47
27
votes
3 answers

TSLint not working in VS Code

I added TSLint to my React/TypeScript project using the tslint VSCode extension. I also installed both typescript and tslint globally according to TSLint docs npm install -g tslint typescript This is my tslint.json file: { "extends":…
blankface
  • 5,757
  • 19
  • 67
  • 114
27
votes
1 answer

Why is tslint:recommended not allowing modules?

We are using typescript v2.3.2 and TSLint v4.5.1 with VS Code to create a SPA. Codebase is growing and we need to modularize it someway. I tried to do the modularization using typescript modules but found the following lint error when transpiling…
Diego Gago
  • 299
  • 1
  • 3
  • 10
27
votes
4 answers

TSLint get rid of missing-whitespace

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…
ThinkBonobo
  • 15,487
  • 9
  • 65
  • 80
24
votes
2 answers

TSLint marks body-parser as deprecated

I have the Typescript code below: import * as express from 'express'; import * as bodyParser from 'body-parser'; ... const app: express.Application = express(); app.use(bodyParser.json()); In VSCode the bodyParser on the last line is marked with…
Halt
  • 2,924
  • 4
  • 22
  • 26
24
votes
2 answers

Preventing conflict between Prettier (code formatter) and ESLint/TSLint

I am working on an Angular project in VS Code, using the "Prettier" plugin for code formatting, and the ESLint/TSLint plugins for standards enforcement. I know this isn't an "error" but I strongly prefer clean builds and like to remove warnings…
Todd Davis
  • 5,855
  • 10
  • 53
  • 89
24
votes
2 answers

How to avoid VsCode Prettier to break chain functions in new lines.?

I'm working with VSCode, Prettier and TSLint. When I do have chained functions call with more than 2 calls like let m = moment().startOf("day").subtract(30, "days"); Prettier breaks into let m = moment() .startOf("day") .subtract(30,…
Daniel Santos
  • 14,328
  • 21
  • 91
  • 174
22
votes
1 answer

Angular-CLI Serve with Lint Watch

Is there any way to run ng lint while watching for file changes during ng serve? To encourage best practices according to the Angular 2 Style Guide our CI tool runs ng lint during the build process and it isn't always a developers first thought to…
Brian Anderson
  • 307
  • 3
  • 11
21
votes
3 answers

tslint - Missing trailing comma (trailing-comma) on the last line

I cannot figure out why my tslint even want to see the trailing comma on the end of the last line in the objects? How can I set the ignore rule for the last line of the objects for example? Thanks. Exemple: props = { prop1: 21, // good …
Max Travis
  • 1,228
  • 4
  • 18
  • 41
21
votes
2 answers

Space Indentation Expected in ng lint

I keep getting error "space indentation expected" while running ng lint. It is a quite amount of lines that having the same issue in my application. How can I solve this warning? Is anyone having face the similar issue ?
user3086452
  • 291
  • 1
  • 3
  • 6
21
votes
2 answers

TSLint - Preventing error: The key is not sorted alphabetically

I'm doing a test app with Ionic2 / Cordova / Typescript / Angular. I'm using tslint 5.6.0. I'm using the following module: https://www.npmjs.com/package/tslint Focusing on just one file... when linting the following file: import { NgModule,…
davidesp
  • 3,743
  • 10
  • 39
  • 77
21
votes
1 answer

What is "no-string-literal" rule in tslint?

The description found here is very short: Disallows object access via string literals. Is there any further documentation or example?
user2227400
20
votes
1 answer

Disable strictTemplates per file not entirely

I have a large project with many files. Now I want to use strictTemplates, so I added the following lines in: tsconfig.json ... "angularCompilerOptions": { "fullTemplateTypeCheck": true, "strictTemplates": true ...…