tslint

How to exclude a folder from tslint?

Deadly 提交于 2019-12-01 03:49:19
I like to exclude the test folder form linting with tslint in vscode. So I have placed an exclude into my tslint.json config file. Unfortunately the exclude statement is not working. Does any one know how to set the exclude up? { "exclude": "tests/**/*.ts", "rulesDirectory": ["node_modules/tslint-microsoft-contrib"], "rules": { "export-name": true, ... } } Latest update: this can now be set in in tslint.json (the following configuration works with tslint 5.11) { "linterOptions": { "exclude": [ "bin", "build", "config", "coverage", "node_modules" ] } } MBushveld It seems that this is an open

How do I get tslint to watch for changes in a specific folder?

落爺英雄遲暮 提交于 2019-12-01 02:00:21
问题 I am using webpack 2, and it will tell me if there are compile issues with my typescript code. However, I have not figured out a way to run tslint through it and have it run with every change detected by webpack when its running in dev-server mode. I have tried getting tslint-loader working, but for each file in my project it simply tells me: /src/main.tsNo valid rules have been specified I am using it as such: rules: [ { test: /\.ts$/, enforce: 'pre', loader: 'tslint-loader', options: {

How to exclude a folder from tslint?

拟墨画扇 提交于 2019-12-01 01:32:24
问题 I like to exclude the test folder form linting with tslint in vscode. So I have placed an exclude into my tslint.json config file. Unfortunately the exclude statement is not working. Does any one know how to set the exclude up? { "exclude": "tests/**/*.ts", "rulesDirectory": ["node_modules/tslint-microsoft-contrib"], "rules": { "export-name": true, ... } } 回答1: Latest update: this can now be set in in tslint.json (the following configuration works with tslint 5.11) { "linterOptions": {

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

三世轮回 提交于 2019-11-30 20:07:19
问题 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 will have their internals modified. If you see an object declared with const , do you assume the intention was for the object to be immutable, and would you have preferred to see let instead, or, since some linters (like tslint) have a problem with

How to rewrite code to avoid TSLint “object access via string literals”

我的未来我决定 提交于 2019-11-30 11:14:38
问题 I'm pretty new to TypeScript and I would like to know if there exists a good way to rewrite code to avoid TSLint error "object access via string literals is disallowed" in the following code interface ECType { name: string; type: string; elementType?: string; } export var fields: { [structName: string]: Array<ECType>; } = { }; class ECStruct1 { foo: string; bar: number; baz: boolean; qux: number; quux: number; corge: ECStruct2[]; grault: ECStruct2; constructor() { ... } } fields['ECStruct1']

How to lint entire folder using tslint

梦想与她 提交于 2019-11-30 10:53:39
问题 Is that possible to lint entire folder using tslint? Using eslint it is possible to do eslint ./src to validate whole folder. When i try to do the same for tslint - i am getting an error Error: EISDIR: illegal operation on a directory . In their examples on the site - they show how to validate single file, which is not the case usually. Is that possible to validate my project without extra things like gulp-tslint , just from the command line? 回答1: You can use a glob to lint multiple files.

How to lint for Typescript compilation issues?

风流意气都作罢 提交于 2019-11-30 09:12:32
问题 Take the following Typescript arrow function: /** * Returns a probably unique component name. * * @param baseName a suggested name to make unique. * @returns a probably unique name. */ export const getUniqueComponentName = ( baseName ): string => { return baseName + Math.round(Math.random() * 10000000) } When Typescript is configured in tsconfig.json as such: "noImplicitAny": true, This correctly results in a compilation error: [ts] Parameter 'baseName' implicitly has an 'any' type. Visual

Why is tslint:recommended not allowing modules?

给你一囗甜甜゛ 提交于 2019-11-30 08:10:44
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 the app. [tslint] 'namespace' and 'module' are disallowed (no-namespace) I'm using this configuration for the linter: { "extends": "tslint:recommended", "rules": { "no-var-requires": false, "no-console": ["error", false], "max-line-length": [false] } } The recommended rules file at line 89 shows this rule: "no-namespace": true, I wonder if there is

Subscribe is deprecated: Use an observer instead of an error callback

被刻印的时光 ゝ 提交于 2019-11-30 06:05:57
When I run the linter it says: subscribe is deprecated: Use an observer instead of an error callback Code (from an angular 7 app with angular-cli): this.userService.updateUser(data).pipe( tap(() => {bla bla bla}) ).subscribe( this.handleUpdateResponse.bind(this), this.handleError.bind(this) ); Don't know exactly what should I use and how... Thanks! martin subscribe isn't deprecated, only the variant you're using is deprecated. In the future, subscribe will only take one argument: either the next handler (a function) or an observer object. So in your case you should use: .subscribe({ next: this

What could this be about? [TsLint Error: “Promises must be handled appropriately”]

最后都变了- 提交于 2019-11-30 05:38:24
I'm doing some basic asynchronous operations using async/await in TypeScript but TSLint is throwing mysterious error messages for these two functions below. Has anyone encountered these errors before? On the error output the governing rule is not mentioned, so I don't understand what's causing these. Any ideas would be greatly appreciated. The main request: import * as rp from 'request-promise' export function getRequest(address: rp.Options): rp.RequestPromise { return rp(address) } Exported async function: export async function getStatus(message: Message) { try { const res = await getRequest