插件之:TSLINT

概述

  • 现在开发后端主要的开发语言是Typescript,检查工具使用的是tslint。由于存在一些问题,tslint被弃用了,建议使用eslint。但是实际使用eslint的过程中,发现达不到之前使用tslint的效果。所有没有办法,还是一直使用tslint,但是每次需要手动开启。
  • 直到有一天,我再次安装插件的时候,发现了tslint有一个是新版本。全称是:ms-vscode.vscode-typescript-tslint-plugin,版本是1.3.3,是microsoft的官方版本插件。 这表示了众多使用tslint者的愿意。
❗IMPORTANT: TSLint has been deprecated in favor of ESLint.Please look into migrating your projects to ESLint.Adds tslint to VS Code using the TypeScript TSLint language service plugin.Please refer to the tslint documentation for how to configure the linting rules.

新tslint的插件使用

  • 在Vscode的插件管理,搜索tslint
  • 这个时候,会看到microsoft出品的tslint, 版本是1.3.3
  • 安装并启用
  • 和原来tslint配置一样,在工程的根目录创建tslint.json,我这里默认配置如下:
{"defaultSeverity": "error","extends": ["tslint:recommended"],"jsRules": {},"rules": {"no-namespace": false,"ordered-imports": false,"member-ordering": false,"object-literal-sort-keys": false,"trailing-comma": false,"no-var-requires": false,"no-empty": false,"interface-over-type-literal": false,"object-literal-shorthand": false,"no-empty-interface": false,"interface-name": false,"eofline": false,"variable-name":false,"max-classes-per-file":false,"quotemark": false,"callable-types":true,"no-console":true,"prefer-const":false,"no-string-literal":false,"forin": false,"radix": false,"curly": [true, "ignore-same-line"],"no-arg": true,"no-parameter-reassignment": true,"member-access": [true, "check-accessor", "check-constructor", "check-parameter-property"],"adjacent-overload-signatures": true,"label-position": false,"no-conditional-assignment": true,"no-construct": true,"no-duplicate-super": true,"no-duplicate-switch-case": true,"no-duplicate-variable": [true, "check-parameters"],"no-implicit-dependencies": [true, "dev"],"max-line-length": [true,{"limit": 160,"ignore-pattern": "^import |^export {(.*?)}","check-strings": false,"check-regex": true}],"typedef-whitespace":[true,{"parameter": "nospace" }]},"rulesDirectory": []
}
  • 然后就可以看到有相应的错误提示了。
  • 这个办法,有一个缺点,就是不能像之前那样,当tslint当一个命令来使用,统计对所有的源代码,都作代码检查。

请注意

  • 默认情况下,使用全局的版本的typescript, 不会加载tslint和自定义配置。
    要使用本地 TSLint 安装和工作区中的自定义规则启用,您必须:
    使用与 TSLint 一起安装的 TypeScript 工作区版本。
    通过运行 TSLint:Manage Workspace Library Execution 命令启用工作区库执行。

  • 配置使用参考:https://github.com/zdhsoft/typescript-tslint-plugin

  • 下面是一个tsconfig.json文件,参考xmcommon/tsconfig.json at master · zdhsoft/xmcommon (github.com)

{"compilerOptions": {/* Visit https://aka.ms/tsconfig.json to read more about this file */"plugins": [{// https://github.com/zdhsoft/typescript-tslint-plugin  这块的帮助,请这个说明"name": "typescript-tslint-plugin" ,"alwaysShowRuleFailuresAsWarnings": false,"ignoreDefinitionFiles": true,// "configFile": "../tslint.json","suppressWhileTypeErrorsPresent": false,"packageManager":"cnpm"}],/* Basic Options */// "incremental": true,                         /* Enable incremental compilation */"target": "ES2017",                                /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */"module": "commonjs",                           /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */// "lib": [],                                   /* Specify library files to be included in the compilation. */// "allowJs": true,                             /* Allow javascript files to be compiled. */// "checkJs": true,                             /* Report errors in .js files. */// "jsx": "preserve",                           /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */"declaration": true,                         /* Generates corresponding '.d.ts' file. */// "declarationMap": true,                      /* Generates a sourcemap for each corresponding '.d.ts' file. */// "sourceMap": true,                           /* Generates corresponding '.map' file. */// "outFile": "./",                             /* Concatenate and emit output to single file. */"outDir": "./dist",                              /* Redirect output structure to the directory. */// "rootDir": "./",                             /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */// "composite": true,                           /* Enable project compilation */// "tsBuildInfoFile": "./",                     /* Specify file to store incremental compilation information */// "removeComments": true,                      /* Do not emit comments to output. */// "noEmit": true,                              /* Do not emit outputs. */// "importHelpers": true,                       /* Import emit helpers from 'tslib'. */// "downlevelIteration": true,                  /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */// "isolatedModules": true,                     /* Transpile each file as a separate module (similar to 'ts.transpileModule'). *//* Strict Type-Checking Options */"strict": true,                                 /* Enable all strict type-checking options. */// "noImplicitAny": true,                       /* Raise error on expressions and declarations with an implied 'any' type. */// "strictNullChecks": true,                    /* Enable strict null checks. */// "strictFunctionTypes": true,                 /* Enable strict checking of function types. */// "strictBindCallApply": true,                 /* Enable strict 'bind', 'call', and 'apply' methods on functions. */// "strictPropertyInitialization": true,        /* Enable strict checking of property initialization in classes. */// "noImplicitThis": true,                      /* Raise error on 'this' expressions with an implied 'any' type. */// "alwaysStrict": true,                        /* Parse in strict mode and emit "use strict" for each source file. *//* Additional Checks */// "noUnusedLocals": true,                      /* Report errors on unused locals. */// "noUnusedParameters": true,                  /* Report errors on unused parameters. */// "noImplicitReturns": true,                   /* Report error when not all code paths in function return a value. */// "noFallthroughCasesInSwitch": true,          /* Report errors for fallthrough cases in switch statement. */// "noUncheckedIndexedAccess": true,            /* Include 'undefined' in index signature results */// "noPropertyAccessFromIndexSignature": true,  /* Require undeclared properties from index signatures to use element accesses. *//* Module Resolution Options */// "moduleResolution": "node",                  /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */// "baseUrl": "./",                             /* Base directory to resolve non-absolute module names. */// "paths": {},                                 /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */// "rootDirs": [],                              /* List of root folders whose combined content represents the structure of the project at runtime. */// "typeRoots": [],                             /* List of folders to include type definitions from. */// "types": [],                                 /* Type declaration files to be included in compilation. */// "allowSyntheticDefaultImports": true,        /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */"esModuleInterop": true,                        /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */// "preserveSymlinks": true,                    /* Do not resolve the real path of symlinks. */// "allowUmdGlobalAccess": true,                /* Allow accessing UMD globals from modules. *//* Source Map Options */// "sourceRoot": "./lib",                            /* Specify the location where debugger should locate TypeScript files instead of source locations. */// "mapRoot": "",                               /* Specify the location where debugger should locate map files instead of generated locations. */// "inlineSourceMap": true,                     /* Emit a single file with source maps instead of having a separate file. */// "inlineSources": true,                       /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. *//* Experimental Options */// "experimentalDecorators": true,              /* Enables experimental support for ES7 decorators. */// "emitDecoratorMetadata": true,               /* Enables experimental support for emitting type metadata for decorators. *//* Advanced Options */"skipLibCheck": true,                           /* Skip type checking of declaration files. */"forceConsistentCasingInFileNames": true        /* Disallow inconsistently-cased references to the same file. */}
}

vscode插件之:TSLINT相关推荐

  1. 用vscode编写静态页面_开发中实用的VSCode插件推荐

    本篇文章给大家介绍一下开发中实用的VSCode插件推荐.有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助. 工欲善其事必先利其器,以下是本人为前端开发收集的vscode插件,有需要的话赶 ...

  2. chrome vue.js插件文档_前端开发者必备的40个VSCode插件!

    前言:俗话说"君欲善其事,必先利其器."笔者也使用VScode开发有一段时间了,不得不说,VSCode是我目前用到的众多开发工具中最好使用的一款.当然这些功能大多得归功于VSCod ...

  3. VSCode插件之实时字数统计与选中词英汉互译

    VSCode插件之字数统计.翻译 hello world 初体验 环境条件: npm git 最新版的VS Code(我的是1.32.3,结果测试的时候说我版本太低,就升级到了1.33.0) 根据官网 ...

  4. 前端开发必备的VSCode插件

    本文总结了一下前端开发人员一些经常用的可以提高开发效率的VSCode插件,好的工具可以事半功倍.主要分为:基础通用篇,自由可选篇,框架工具篇,主题篇(按照我自己的想法分的) 基础通用篇 Chinese ...

  5. 微信读书vscode插件_快来!让这款 VSCode 插件吹爆你的彩虹屁!

    公众号关注 "GitHubDaily" 设为 "星标",每天带你逛 GitHub! 大家好,我是小 G.不知道你们是否还记得,在去年三月份的时候,曾因在微信群内 ...

  6. 玩转VSCode插件之Remote-SSH

    前言 每当更换电脑就要从新搭建一遍开发环境... 每当拉完最新代码程序在本地跑不起来的时候就要检查服务器和开发电脑的环境... 每当服务器上出Bug的时候就想如果可以能够调试服务器代码多好啊.. 你是 ...

  7. vscode 全项目替换_利用vscode插件提升前端国际化开发效率

    1. 起因 国际化是我们目前开发工作中非常重要的一环.对于老项目,我们可以通过便捷的方式对中文文案进行批量国际化:但是对于新增的功能或者模块开发,一般还是开发同学对文案逐个进行国际化.我自己的开发流程 ...

  8. editor 插入图片之后将光标放到右侧_通过vscode插件自动上传剪贴板图片至aws s3

    vscode是我日常所使用的编辑器,包括在写这篇文章的时候.在编辑markdown文档的时候,总会遇到插入图片的问题.所以我就想实现一个简单的vscode插件,在运行时,可以将剪贴板里的图片上传到aw ...

  9. vscode 在标签的src引入别名路径_从零开始 - VSCode 插件运行机制

    写这篇文章是因为最近一段时间的工作涉及到 Cloud Studio 插件这一块的内容,旧的插件系统在面向用户开放后暴露了安全性.扩展性等诸多问题.调研了几个不同架构下 IDE 的插件系统实现( The ...

  10. 一个统计编码时长的Vscode插件神器

    Vscode插件之推荐一个统计编码时长的插件神器 作者:坚果 公众号:"大前端之旅" 华为云享专家,InfoQ签约作者,阿里云专家博主,51CTO博客首席体验官,开源项目GVA成员 ...

最新文章

  1. Visual C++ 2010 简介
  2. Java线程面试题 Top 50(转)
  3. CTF---Web入门第十二题 程序逻辑问题
  4. 谷歌40人发表59页长文:为何真实场景中ML模型表现不好?
  5. 再见,Matplotlib!
  6. html文档定义层标记是,jsp练习题目201312
  7. Git—代码管理、提交及冲突解决流程的思考
  8. Spark报错:JDOFatalInternalException: Error creating transactional connection factory
  9. 赚小钱,靠学一门技术没问题,那想赚大钱该怎么做呢?
  10. bigdecimal如何做除法_bigdecimal类型除法问题
  11. 数字共享平台赋能船舶行业数字化转型——CSBC,搭建行业数字生态链
  12. 多项式秦九韶算法c语言
  13. 中关村-DIY之笔记本做wifi热点供手机无线上网
  14. 可能致癌的几种化妆品
  15. EH集团筹集逾500万瑞士法郎,用于推进其零排放燃料电池技术
  16. Python爬取煎蛋网图片
  17. Cannot find module lint-staged 解决办法
  18. Intellij IDEA中修改Maven项目的项目名称
  19. 修改新网域名DNS服务器到DNSPOD解析服务
  20. 2021年6月7日08点37分 渗透测试基础部分

热门文章

  1. 决策树—基本原理与实战
  2. Android小菜鸡2 个月的面试亲身经历告诉大家,如何进入 BAT 等大厂?
  3. InterValue项目周报:20190930-20191013
  4. [BZOJ4338][BJOI2015]糖果(扩展Lucas)
  5. 总结二十二:如何在公司建立成功的技术文化(2)
  6. 名企笔试真题精选(三)
  7. js 随笔 1-回炉重造
  8. matlab 控制投影仪 正弦光栅,一种基于投影仪散焦解相位的光栅投影三维快速测量方法...
  9. 计算机电缆yjv,电力电缆YJV3*95+2*50
  10. 国内快递或没有永久第一,但“印尼极兔”却试图搅局?