现在没有前后端分离的开发模式都不好意思跟同行交流。前后端分离的好处这里就不再赘述了。

本司开发的系统是基于Angular(ng zorro),TypeScript,后台采用Spring Boot。写前端本人独爱vs code,配合vs code的一些插件,写代码简直那个爽(丝滑般的感觉)。

vs code保存自动格式化代码及eslint/tslint修复,是不是能找到宇宙最强大,最好用的IDE Visual Studio的感觉?

下面我分享一下我的vs code配置。

一、vs code版本Version: 1.45.0 (user setup)

二、安装插件

需要安装一下插件:

ESLint
TSLint
Prettier - Code formatter
Manta's Stylus Supremacy
language-stylus
Vetur

三、配置prettier

Prettier是一个能够完全统一你和同事代码风格的利器,并且统一的代码风格能保证代码的可读性。

在项目根目录增加文件.prettierrc

{

"printWidth": 120,

"semi": false,

"singleQuote": true

}

四、配置tsconfig

tsconfig.json:

{

"compileOnSave": false,

"compilerOptions": {

// "baseUrl": "./",

// 添加路径相关

"baseUrl": "src",

"paths": {

"@app/*": ["app/*"]

},

"outDir": "./dist/out-tsc",

"sourceMap": true,

"declaration": false,

"downlevelIteration": true,

"experimentalDecorators": true,

"module": "esnext",

"moduleResolution": "node",

"importHelpers": true,

"target": "es2015",

"lib": [

"es2018",

"dom"

]

},

"angularCompilerOptions": {

"fullTemplateTypeCheck": true,

"strictInjectionParameters": true

}

}

五、配置tslint

因为使用是typescript,所以我当然要用tslint。

添加文件tslint.json:

{

"extends": "tslint:recommended",

"rules": {

"array-type": false,

"arrow-parens": false,

"deprecation": {

"severity": "warning"

},

"component-class-suffix": true,

"contextual-lifecycle": true,

"directive-class-suffix": true,

"directive-selector": [

true,

"attribute",

"app",

"camelCase"

],

"component-selector": [

true,

"element",

"app",

"kebab-case"

],

"import-blacklist": [

true,

"rxjs/Rx"

],

"interface-name": false,

"max-classes-per-file": false,

"max-line-length": [

true,

140

],

"member-access": false,

"member-ordering": [

true,

{

"order": [

"static-field",

"instance-field",

"static-method",

"instance-method"

]

}

],

"no-consecutive-blank-lines": false,

"no-console": [

true,

"debug",

"info",

"time",

"timeEnd",

"trace"

],

"no-empty": false,

"no-inferrable-types": [

true,

"ignore-params"

],

"no-non-null-assertion": false,

"no-redundant-jsdoc": true,

"no-switch-case-fall-through": true,

"no-use-before-declare": true,

"no-var-requires": false,

"object-literal-key-quotes": [

true,

"as-needed"

],

"object-literal-sort-keys": false,

"ordered-imports": false,

"quotemark": [

true,

"single"

],

"trailing-comma": false,

"no-conflicting-lifecycle": true,

"no-host-metadata-property": true,

"no-input-rename": true,

"no-inputs-metadata-property": true,

"no-output-native": true,

"no-output-on-prefix": true,

"no-output-rename": true,

"no-outputs-metadata-property": true,

"template-banana-in-box": true,

"template-no-negated-async": true,

"use-lifecycle-interface": true,

"use-pipe-transform-interface": true

},

"rulesDirectory": [

"codelyzer"

]

}

vs全局设置

快捷键:ctrl+,

然后点右上角进入settings.json文本编辑模式

settings.json

{

"editor.wordWrap": "on",

"update.enableWindowsBackgroundUpdates": false,

"update.mode": "none",

"update.showReleaseNotes": false,

"window.zoomLevel": 0,

"typescript.updateImportsOnFileMove.enabled": "always",

"explorer.confirmDelete": false,

// #值设置为true时,每次保存的时候自动格式化;值设置为false时,代码格式化请按shift+alt+F

"editor.formatOnSave": true,

//设置tab的缩进为2

"editor.tabSize": 2,

// #每次保存的时候将代码按eslint和tslint格式进行修复

"editor.codeActionsOnSave": {

"source.fixAll.eslint": true,

"eslint.autoFixOnSave": false,

"source.fixAll.tslint": true

},

"eslint.run": "onSave",

//  #让prettier使用eslint的代码格式进行校验

// vscode 更新后已经统一使用editor.codeActionsOnsave

//  #代码结尾加分号为好

"prettier.semi": true,

//  #使用带引号替代双引号

"prettier.singleQuote": true,

"prettier.tabWidth": 4,

//  #让函数(名)和后面的括号之间加个空格

"javascript.format.insertSpaceBeforeFunctionParenthesis": true,

// #这个按用户自身习惯选择

"vetur.format.defaultFormatter.html": "js-beautify-html",

// #让vue中的js按"prettier"格式进行格式化

"vetur.format.defaultFormatter.js": "prettier",

"vetur.format.defaultFormatterOptions": {

"js-beautify-html": {

// #vue组件中html代码格式化样式

"wrap_attributes": "force-aligned", //也可以设置为“auto”,效果会不一样

"wrap_line_length": 200,

"end_with_newline": false,

"semi": false,

"singleQuote": true

},

"prettier": {

"semi": false,

"singleQuote": true

}

},

"[jsonc]": {

"editor.defaultFormatter": "esbenp.prettier-vscode"

},

// 格式化stylus, 需安装Manta's Stylus Supremacy插件

"stylusSupremacy.insertColons": false, // 是否插入冒号

"stylusSupremacy.insertSemicolons": false, // 是否插入分号

"stylusSupremacy.insertBraces": false, // 是否插入大括号

"stylusSupremacy.insertNewLineAroundImports": false, // import之后是否换行

"stylusSupremacy.insertNewLineAroundBlocks": false,

"prettier.useTabs": true,

"files.autoSave": "off",

"[javascript]": {

"editor.defaultFormatter": "esbenp.prettier-vscode"

},

"[json]": {

"editor.defaultFormatter": "esbenp.prettier-vscode"

},

"diffEditor.ignoreTrimWhitespace": false,

"[html]": {

"editor.defaultFormatter": "esbenp.prettier-vscode"

}, // 两个选择器中是否换行

//在vue文件里设置html关联

"emmet.syntaxProfiles": {

"vue-html": "html",

"vue": "html"

},

"explorer.confirmDragAndDrop": false,

"terminal.integrated.rendererType": "dom",

"files.associations": {

"*.ejs": "html",

"*.vue": "html"

},

"emmet.triggerExpansionOnTab": true,

"emmet.includeLanguages": {

"vue-html": "html",

"vue": "html"

},

"editor.accessibilitySupport": "on",

"[typescript]": {

"editor.defaultFormatter": "esbenp.prettier-vscode"

}

}

六、最后效果

保存代码自动修复并格式代码,也不用每次想格式化代码要手动按

shift+alt+f

转载:https://www.lanhusoft.com/Article/762.html

vs code保存自动格式化代码及eslint/tslint修复-太爽(丝滑般的感觉)相关推荐

  1. pycharm 保存自动格式化代码

    文章目录 pycharm 保存自动格式化代码 安装 file watcher 安装blank 监听保存 watcher 完成 pycharm 保存自动格式化代码 pycharm + black + f ...

  2. vsCode的setting.json保存自动格式化代码html不换行

    我的配置项如下: {"workbench.editor.enablePreview": false, //打开文件不覆盖"editor.minimap.enabled&q ...

  3. vsCode 设置vue 保存自动格式化代码

    setting {// vscode默认启用了根据文件类型自动设置tabsize的选项"editor.detectIndentation": false,// 重新设定tabsiz ...

  4. idea保存自动格式化代码

    自动格式化 上网一搜发现好多人都搜这个,别问我为啥搜这个.然后用什么插件像google-java-format之类的,还有人说不能弄,还有好多各种奇怪方式.奇怪啊idea使用人数这么多的编译器竟然没有 ...

  5. vscode 保存自动格式化代码

    settings.json文件内容 {"workbench.editor.enablePreview": false, //打开文件不覆盖"search.followSy ...

  6. vscode自动格式化不符合eslint_VsCode(Visual Studio Code)格式化代码符合EsLint

    利用Visual Studio Code ESlint插件,实现自动格式化代码 步骤一:安装ESlint插件=>点击Extensions或者Ctrl+Shift+X=>搜索ESlint=& ...

  7. 【22新版VSCode】配置自动格式化代码(保存文件自动格式化代码和tab自动格式化代码)

    做html开发时,使用快捷键alt+shift+f格式化代码并不是很方便. 想配置自动格式化代码,发现新版本vs code配置方法有点不一样.记录一下. 问题描述a 22年新版vs code配置&qu ...

  8. 初用VScode并配置,自定义代码片段(快捷键),自动格式化代码快捷键,保存格式化代码快捷键

    一.VScode 介绍.下载.安装. 一个运行于 Mac OS X.Windows和 Linux 之上的,针对于编写现代 Web 和云应用的跨平台源代码编辑器. 免费,可以直接去微软官网去下载.htt ...

  9. vscode如何设置自动保存时自动格式化代码

    Vscode 快速格式化代码: shift+alt+f 也可以设置 当我们 保存页面的时候自动格式化代码: 1)文件 ------.>[首选项]---------->[设置]: 2)搜索e ...

最新文章

  1. 三菱plc232数据线驱动下载_三菱PLC与西门子PLC有什么区别?
  2. Linux的默认给home分配多少,Linux 分配/home的磁盘空间给根目录
  3. java编译POSTGRESQL_Java连接PostgreSQL数据库(安装环境 + 简易测试代码)
  4. 自建比赛服务器,《三国杀》怎么自己创建比赛?自建赛事规则介绍
  5. Objective-C 中自动生成 setter getter 方法
  6. 删数问题(信息学奥赛一本通-T1321)
  7. 《mysql必知必会》学习_第八章_20180730_欢
  8. VAE-变分自编码器-Auto-Encoding Variational Bayes-详细推导
  9. Hexo 搭建个人博客(九)NexT 主题进阶配置
  10. java.lang.SecurityException: com.example.rxtest was not granted this permission: android.permission
  11. 精心分享8个让人大开眼界的软件和网站,极大提高办公效率
  12. Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To
  13. 知识点滴 - 我们的太阳系
  14. JVM,堆,栈,方法区之间的关系
  15. 基于 Selenium 掘金自动签到、抽奖的定时任务
  16. Kotlin 之 协程(四)协程并发
  17. Python爬取网易云音乐播放地址
  18. js逆向JSVMP篇新版某乎_x-zes-96算法还原
  19. 虚拟环境内使用pip安装torch内存爆掉
  20. c++小游戏之文字版MC

热门文章

  1. 用MapReduce对招聘数据处理分析+可视化
  2. springboot返回按照首字母分组排序数据
  3. 纳米二氧化硅行业调研报告 - 市场现状分析与发展前景预测
  4. C++ 保留一位小数
  5. adrv9003/ADRV9001/ADRV9002 FPGA驱动开发(硬件开发)
  6. 管理本地linux用户、组以及管理用户密码的小练习
  7. 【JS函数】JS函数之高阶函数、组合函数、函数柯里化
  8. React项目中应用TypeScript
  9. QWidget: Must construct a QApplication before a QWidget 请按任意键继续. . .
  10. 彻底解决:Apache启动问题—(OS 10022)提供了一个无效的参数。