国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

vscode代碼格式化和eslint的使用

2024-07-21 02:03:22
字體:
來源:轉載
供稿:網友

簡介

今天看著寫的代碼越來越多后,發現自己讀起都有點吃力了,哈哈,自己看著眼睛痛,就準備整頓一下,畢竟這個項目還要維護很久的,找解決方案和測試解決方案就用了一個半小時,嚴重開始懷疑自己的智商了。下面的目標讓代碼看起來很公正

代碼編輯器

vscode
version:版本 1.35.1 (1.35.1) 2019-06-12T14:19:05.197Z更新的

vscode代碼格式化

因為目前公司就我一個后端,項目也不大,所以就采用這種方案,簡單快捷粗暴。

一.點擊code->preferences->settings 點擊右上角{}
二.用戶自定義設置(/User/settings.json)
添加代碼

"editor.formatOnType": true,"editor.formatOnSave": true

ESLint配置

ESLint不僅有代碼規范而且還有一部分語法檢查的功能,ex:命令規范(駝峰) a==b警告提示a===b...
ESLint可以有效的規范代碼,以后還是會采用,培養自己的規范的編碼習慣
https://cn.eslint.org/

1.vscode安裝ESLint

這里以配置eslint-config-aribnb的例子
vscode在extensions中安裝ESLint

2.npm安裝

npm install -g eslint

3.創建.eslintrc文件

softwaredeMacBook-Pro:koa-pro software$ "eslint --init"? How would you like to configure ESLint? "Use a popular style guide"? Which style guide do you want to follow? "Airbnb" (https://github.com/airbnb/javascript)? Do you use React? "No"? What format do you want your config file to be in? "JSON"Checking peerDependencies of eslint-config-airbnb-base@latestThe config that you have selected requires the following dependencies:eslint-config-airbnb-base@latest eslint@^4.19.1 || ^5.3.0 eslint-plugin-import@^2.14.0? Would you like to install them now with npm? "Yes"Installing eslint-config-airbnb-base@latest, eslint@^4.19.1 || ^5.3.0, eslint-plugin-import@^2.14.0npm WARN koa-pro@1.0.0 No repository field.+ eslint@5.16.0+ eslint-plugin-import@2.17.3+ eslint-config-airbnb-base@13.1.0updated 3 packages and audited 7469 packages in 23.559sfound 370 vulnerabilities (1 low, 367 moderate, 2 high) run `npm audit fix` to fix them, or `npm audit` for detailsSuccessfully created .eslintrc.json file in /Users/software/workspace/Me/huafu/koa-pro

項目目錄下將會生成一個eslintrc.json的文件

{ "extends": "airbnb-base"}添加自己想要的設置,我這里node環境{"env": { "node": true, "es6": true }, "parserOptions": {#解決import export eslint報錯 "ecmaFeatures": {  "legacyDecorators": true } }, "extends": "airbnb-base"}

4.關聯eslint與vscode

1.code->preferences->settings 進入user的seetings
2.添加以下代碼

"eslint.autoFixOnSave": true,//保存自動修復eslint錯誤 "eslint.validate": [ "javascript", "javascriptreact", {  "language": "vue",  "autoFix": true } ], "eslint.options": {//指定eslint配置文件位置i "configFile": ".eslintrc.json" //指定項目根目錄中的eslint配置文件 }

這樣vscode和eslint關聯配置完成了,不出意外會報一大堆錯。good lucky

總結:

主要是卡在eslint.options上,沒看vscode的extensions的eslint的README,而去相信了百度,沒有添加eslint.options,那么一直都無法生效.學的教訓。

到此這篇關于vscode代碼格式化和eslint的使用的文章就介紹到這了,更多相關vscode代碼格式化內容請搜索武林網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持武林網!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南澳县| 乐业县| 穆棱市| 昌宁县| 曲周县| 长子县| 翼城县| 内乡县| 新竹市| 佛坪县| 平江县| 瑞昌市| 达孜县| 东乌| 霍邱县| 时尚| 壤塘县| 大化| 沾化县| 屯门区| 安达市| 修武县| 平塘县| 沙坪坝区| 五台县| 孙吴县| 刚察县| 和田市| 南部县| 乐陵市| 仙居县| 关岭| 汕尾市| 兴城市| 白水县| 桐庐县| 东平县| 芦溪县| 应城市| 郯城县| 正蓝旗|