tslint

Angular2 - HTTP RequestOptions HEADERS

半城伤御伤魂 提交于 2019-12-31 10:56:42
问题 I currently have an issue with tslint and was hoping someone could point me in the right direction. I'm trying to send an HTTP GET request using HTTP provided by the Angular2 framework. With this request, I must specify the content-type and the bearer authentication token. Example of my code: let headers = new Headers(); let authToken = this._user.getUser().JWT; headers.append('Content-Type', 'application/json'); headers.append('Authorization', `Bearer ${authToken}`); let options = new

Setup TSLint in Visual Studio 2015

帅比萌擦擦* 提交于 2019-12-30 07:56:31
问题 I develop with Typescript in Visual Studio 2013 and always have my error list open on the bottom. TSLint tells me when my code is messy/incorrect as i'm writing it. I don't think I had to do anything other than install the Web Essentials plugin. I recently installed Visual Studio 2015 and can't, for the life of me, get TSLint to work as it did in Visual Studio 2013. Am I missing something obvious? 回答1: Looks like the easiest way now is to download Web Analyzer by Mads Kristensen from the

How to run tslint continuously with webpack or vs code during development

时光总嘲笑我的痴心妄想 提交于 2019-12-25 08:49:22
问题 When I was using gulp in an Angular 1.x project, I can use gulp to watch files changes and run eslint continuously. In my Angular 2 project, I am using webpack and vs code, how do I make tslint continuously running? I tried this but it doesn't work: "watch:lint": "npm run tslint \"src/**/*.ts\" -- --watch", I haven't tried integrating tslint with vs code. Can vs code give me constant feedback on the files that I am working on with tslint? Any info is appreciated. 回答1: That's probably not

pre-commit hook with lint

大兔子大兔子 提交于 2019-12-24 13:30:34
问题 I'm trying to add precommit-hook to my project, this is my script section on package.json: "scripts": { ... "lint": "npm run lint:sass && npm run lint:js", "lint:js": "ng lint", "lint:sass": "sass-lint src/**/*.scss -v -q" }... "pre-commit": [ "lint" ], If I only execute this line: npm run lint:sass && npm run lint:js Everything works great, but when I'm trying to add precommit my terminal just freeze on: git commit -m "Testing" running lint... 来源: https://stackoverflow.com/questions/47761550

TSLint Error “Expected a 'for-of' loop instead of a 'for' loop with this simple iteration”

人盡茶涼 提交于 2019-12-24 11:16:52
问题 I have a for loop to get an ID from the DB: for(var i = 0; i < data.GetContractId.length; i++) { if (data.GetContractId[i].ContractId) { this.contractExists = true; } } Now I get the following TSLint-Error: Expected a 'for-of' loop instead of a 'for' loop with this simple iteration I'm not sure how to use it in this instance, can anyone help? 回答1: TSLint see that you could use for-of instead of for-loop it's just enhanced and more cleaner for (let contract of data.GetContractId) { if

Force to store getter result in variable if it is used inside of the loop

孤人 提交于 2019-12-24 03:37:08
问题 Consider following class class Smth { get functionWithSomeVeryUniqueName() { // Some heavy calculations are here return obj => obj; // Actually uses some vars from closure calculated above } } I want to have a tslint error on any access to getter inside of the loop. I. e. any of following lines should be considered bad: for (var x of a) smth.functionWithSomeVeryUniqueName(x); a.forEach(x => smth.functionWithSomeVeryUniqueName(x)) a.map(x => smth.functionWithSomeVeryUniqueName(x)) for (var q=0

TSLint: Unused var keyword

六眼飞鱼酱① 提交于 2019-12-24 03:26:29
问题 I've configured TSLint for my TypeScript project and I don't know what does the warning forbidden var keyword mean. Here is a minimal example, which results in the TSLint warning: var x: number = 1; Thank you. Edit: I'm using the sample tslint.json. 回答1: It means you are not allowed to declare using var syntax var = 1; It's an Ecmascript 6 rule, it's purpose would be to ensure you don't accidentally re-declare the same variable twice in the same scope, giving it another meaning

How to ignore *.d.ts files when using tslint?

╄→尐↘猪︶ㄣ 提交于 2019-12-24 01:55:21
问题 I want to add tslint to my workflow. I installed it via: npm install tslint tslint-config-ms-recommended --save-dev And my tslint.json looks like: { "extends": "tslint-config-ms-recommended" } Yet when I run: ./node_modules/.bin/tslint src/**/*.ts it also checks a lot of definitely typed files, e.g.: src/interfaces/highland.d.ts[621, 1]: space indentation expected src/interfaces/highland.d.ts[622, 1]: space indentation expected src/interfaces/highland.d.ts[635, 1]: space indentation expected

AppInjector get is deprecated, use Type<T> or InjectionToken<T>

蓝咒 提交于 2019-12-24 00:42:56
问题 I am trying to get rid of this tslint warning: WARNING: get is deprecated: from v4.0.0 use Type or InjectionToken The way I have my code setup is like this: app.injector.ts import { Injector } from '@angular/core'; export let AppInjector: Injector; export function setAppInjector(injector: Injector) { if (AppInjector) { // Should not happen console.error('Error: AppInjector was already set'); } else { AppInjector = injector; } } app.module.ts ... import { setAppInjector } from './app-injector'

Error: Cannot find module 'tslint/lib/lint' when trying to extend tslint-microsoft-contrib

孤街醉人 提交于 2019-12-23 20:00:25
问题 This is our environment > \node_modules\.bin\tslint --version 4.0.1 > npm install --save-dev tslint-microsoft-contrib `-- tslint-microsoft-contrib@2.0.13 This is our tslint.json configuration. { "extends": [ "./node_modules/tslint-microsoft-contrib/tslint.json" ] } This is what happens when we run our local tslint with that configuration. > node_modules\.bin\tslint --config .\tslint.json --project .\tsconfig.json module.js:471 throw err; ^ Error: Cannot find module 'tslint/lib/lint' at