需求

自动格式化需求 多行回车 合并一行,去分号 最后一个逗号,自动删除,符合eslint

结果

虽然能用了,但是 百度好几个方案,也不知道哪个对哪个,太忙没时间弄了。

配置文件记录

eslint 得装

vetur 得装

prettier 得装

Beautify v1.5.0 得装 这个很重要

装了一个 cnpm install prettier-eslint --save-dev

"devDependencies": {
"prettier-eslint": "^13.0.0",

.jsbeautifyrc

unformatted 我家了个script 要不和eslint冲突

{
"brace_style": "none,preserve-inline",
"indent_size": 2,
"indent_char": " ",
"jslint_happy": false,
"unformatted": [
"script"
],
"css": {
"indent_size": 2
},
"wrap_attributes": "force-aligned",
"wrap_line_length": 120,
"semi": false,
"singleQuote": true,
"end_with_newline": false
}

.babelrc

{
"presets": [
"@vue/app"
]
}

.editorconfig

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

.eslintrc.js

module.exports = {
root: true,
'extends': [
'plugin:vue/essential',
'@vue/standard'
],
plugins: [
// 注意这里不能配置 html 选项,为什么?https://eslint.vuejs.org/user-guide/#why-doesn-t-it-work-on-vue-files
'vue',
],
rules: {
// allow async-await
'generator-star-spacing': 'off',
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'vue/no-parsing-error': [2, {
'x-invalid-end-tag': false
}],
'no-undef': 'off',
'camelcase': 'off',
'no-unused-vars': 'off' // 变量没使用 不报错
},
parserOptions: {
parser: 'babel-eslint'
}
}

.prettierrc

{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"singleQuote": false,
"semi": true,
"trailingComma": "none",
"bracketSpacing": true,
"parser": "vue-eslint-parser"
}

settings.json

{
"pasteImage.path": "${currentFileNameWithoutExt}_Images/",
"update.mode": "manual",
"extensions.autoUpdate": false,
"extensions.autoCheckUpdates": false,
"editor.formatOnSave": true, // 这个保存时候进行格式化
"editor.codeActionsOnSave": {
// 保存时候 eslint修复
"source.fixAll.eslint": true
},
"eslint.alwaysShowStatus": true,
"editor.fontSize": 22,
"editor.fontFamily": "Consolas, 'Courier New', monospace",
"editor.fontLigatures": false,
"editor.fontWeight": "400",
"editor.lineHeight": 28,
"editor.letterSpacing": 0,
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation": true,
"editor.wordWrap": "off",
"editor.renderLineHighlight": "gutter",
"editor.roundedSelection": true,
"editor.renderControlCharacters": true,
"editor.renderIndentGuides": true,
"editor.dragAndDrop": false,
"editor.minimap.enabled": false,
"editor.minimap.showSlider": "mouseover",
"editor.minimap.renderCharacters": true,
"editor.minimap.maxColumn": 200,
"editor.quickSuggestions": {
"strings": true
},
"editor.suggestSelection": "first",
"window.titleBarStyle": "native",
"window.menuBarVisibility": "visible",
"window.title": "${rootName} - ${dirty}${activeEditorLong}",
"workbench.colorTheme": "Spacegray Eighties Dark",
"workbench.iconTheme": "material-icon-theme",
"workbench.startupEditor": "welcomePage",
"workbench.activityBar.visible": true,
"workbench.editor.enablePreview": true,
"workbench.editor.tabSizing": "fit",
"workbench.editor.wrapTabs": false,
"workbench.editor.decorations.colors": true,
"workbench.editor.decorations.badges": true,
"workbench.tree.renderIndentGuides": "none",
"workbench.colorCustomizations": {
// "statusBar.background": "#333333",
// "statusBar.foreground": "#adadad",
"terminal.background": "#000000",
"terminal.foreground": "#FFFFFF"
},
"breadcrumbs.enabled": true,
"breadcrumbs.symbolPath": "off",
"explorer.openEditors.visible": 0,
"explorer.compactFolders": false,
"files.encoding": "utf8",
"files.eol": "\r\n",
"files.hotExit": "onExit",
"files.autoSave": "off",
"emmet.includeLanguages": {
"javascript": "javascriptreact"
},
//javascript
// "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"js/ts.implicitProjectConfig.experimentalDecorators": true,
//git
"git.path": "D:\\Git\\bin\\git.exe",
"git.enableSmartCommit": false,
//terminal
//"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe",
//"terminal.integrated.shell.windows": "D:\\Git\\git-bash.exe",
"terminal.explorerKind": "integrated",
//eslint
"eslint.format.enable": false,
"eslint.validate": [
"javascript",
"javascriptreact",
"vue",
"typescript",
"typescriptreact"
],
//bookmarks
// "bookmarks.saveBookmarksInProject": true,
"javascript.format.insertSpaceBeforeFunctionParenthesis": true, // 让函数名和后面的括号之间加个空格
"javascript.format.insertSpaceAfterCommaDelimiter": true, // 逗号后面有空格
"javascript.format.insertSpaceBeforeAndAfterBinaryOperators": true, // 运算符前后有空格
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, // 大括号前面插空格
"javascript.format.insertSpaceAfterKeywordsInControlFlowStatements": true, // 关键字后面加空格
"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true, // 匿名函数后面加空格
"beautify.language": {
"js": {
"type": [
"javascript",
"json"
],
"filename": [
".jshintrc",
".jsbeautify"
]
},
"css": [
"css",
"scss"
],
"html": [
"htm",
"html",
"vue"//在这里加上vue
]
},
"vetur.format.enable": false, // 不允许它格式化代码
"vetur.validation.template": false, // 不允许它做代码检测
"vetur.validation.script": false,
"vetur.validation.style": false,
"vetur.format.options.tabSize": 2, // 每个缩进级别的空格数,由所有格式化程序继承
"vetur.format.scriptInitialIndent": false, // js部分是否有初始缩进
//vetur
"vetur.format.defaultFormatter.js": "vscode-typescript",
"vetur.format.defaultFormatter.html": "js-beautify-html",
"vetur.format.defaultFormatterOptions": {
"js-beautify-html": {
// - auto: 仅在超出行长度时才对属性进行换行
// - force: 对除第一个属性外的其他每个属性进行换行
// - force-aligned: 对除第一个属性外的其他每个属性进行换行,并保持对齐
// - force-expand-multiline: 对每个属性进行换行
// - aligned-multiple: 当超出折行长度时,将属性进行垂直对齐
"wrap_attributes": "force-aligned", // 属性折行对齐方式
"wrap_line_length": 120, // 设置一行多少字符换行
"semi": false, // 是否在每行末尾添加分号
"singleQuote": true, // 使用单引号
"end_with_newline": false
},
"prettier": {
//设置分号
"semi": false,
//双引号变成单引号
"singleQuote": true,
//禁止随时添加逗号,这个很重要。找了好久
"trailingComma": "none"
}
},
//liveServer
"liveServer.settings.donotVerifyTags": true,
//alias-skip
"alias-skip.mappings": {
"@": "/src",
"_c": "/src/components"
},
// "[vue]": {
// "editor.defaultFormatter": "esbenp.prettier-vscode"
// },
"[markdown]": {
"editor.minimap.enabled": true,
"editor.wordWrap": "on",
"editor.quickSuggestions": false,
"editor.formatOnSave": false
},
"[jsonc]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[html]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"scf.python3.path": "",
"scf.python2.path": "",
"tabnine.experimentalAutoImports": true,
"javascript.format.enable": true, // 20211102bug 发现js格式化不起错用,这个是false 并且[javascript] 需要注释掉
"javascript.format.insertSpaceAfterConstructor": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
"javascript.format.insertSpaceAfterSemicolonInForStatements": true,
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": false,
"javascript.format.placeOpenBraceOnNewLineForFunctions": false,
"liveServer.settings.donotShowInfoMsg": true,
"[typescriptreact]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"vue-helper.alias": {
"_c": "src/components/",
"@": "src/"
},
"commentTranslate.source": "Baidu",
"commentTranslate.targetLanguage": "zh-CN",
"easy-translator.dictionary": [
"YouDao",
"Bing",
"Google",
"Linguee"
],
"vue-helper.componentPrefix": {
"alias": "@",
"path": "src"
},
"vue-helper.componentPath": [
"./*",
"./components/*"
],
"php.validate.executablePath": "D:/phpstudy_pro/Extensions/php/php5.6.9nts/php.exe",
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"javascript.updateImportsOnFileMove.enabled": "always",
"[vue]": {
// "editor.defaultFormatter": "dbaeumer.vscode-eslint"
"editor.defaultFormatter": "HookyQR.beautify"
},
// "vetur.validation.template": false,
"git.confirmSync": false,
"intelephense.diagnostics.languageConstraints": false,
"files.exclude": {
"**/.git": false
},
"files.associations": {
"*.vue": "vue"
},
"prettier.semi": false //去掉代码结尾的分号
}

vscode 格式化 vue 等文件的 配置 eslint vetur prettier Beautify的更多相关文章

  1. vscode格式化Vue出现的问题:单引号变双引号 格式化去掉分号

    学习vue框架时,发现在使用vscode格式化vue代码时,出现单引号变成了双引号问题(导致和EsLint要求不一致),从而导致报错!!!!好坑啊!!! 解决方法如下 在文件根目录下创建 .prett ...

  2. 解决vscode格式化vue文件出现的问题

    遇到的问题 使用vscode开发vue项目的时候,格式化vue文件,与自己配置的eslint标准会有冲突. 引号问题:单引号变双引号 分号问题:行末是否加分号.自动加/减分号 当然还会有其他个性化冲突 ...

  3. VScode格式化vue文件

    使用vscode编写vue文件的时候, 发现不能格式化,手动格式化代码,太费劲, 还有可能会出错, 不格式化,有的时候代码编写的时候, 没有很好的管理格式,不美观. 但是我们是可以修改让VScode可 ...

  4. 使用vscode开发vue cli 3项目,配置eslint以及prettier

    初始化项目时选择eslint-config-standard作为代码检测规范,vscode安装ESLint和Prettier - Code formatter两个插件,并进行如下配置 { " ...

  5. vscode格式化Vue出现的问题

    一.VSCode中使用vetur插件格式化vue文件时,js代码会自动加上冒号和分号 本来就是简写比较方便舒服,结果一个格式化回到解放前 最后找到问题原因: 首先,vetur默认设置是这个样的.也就是 ...

  6. 基于VSCode的vue单文件组件模板设置---一次设置,可爽终生

    第一步: 第二步: 第三步: 打开vue.json文件后,如果是初次设置,应该如下图所示,绿色注释部分不用管,注意那两个白色大括号 第四步:在大括号内全部粘贴如下代码,保存即可完成vue模板的设置 & ...

  7. Vue3+TypeScript 项目中,配置 ESLint 和 Prettier

    接上篇:从0搭建vite-vue3-ts项目框架:配置less+svg+pinia+vant+axios 文档同步项目gitee:https://gitee.com/lixin_ajax/vue3-v ...

  8. vscode 和 atom 全局安装和配置 eslint 像 webstorm 等 ide 一样使用 standard标准 来检查项目

    首先你要安装了 nodejs ,然后在终端命令行输入下面的这堆 npm install eslint eslint-plugin-standard eslint-config-standard esl ...

  9. Vscode 格式化vue Template代码段

    1.安装 vetur 2.在User Setting中增加设置: "vetur.format.defaultFormatter.html": "js-beautify-h ...

  10. vscode 格式化vue代码单引号变双引号

    首选项->设置.输入框输入vetur vscode中设置 "vetur.format.defaultFormatterOptions": { "prettier&q ...

随机推荐

  1. parser.add_argument()用法——命令行选项、参数和子命令解析器

    argparse是一个Python模块:命令行选项.参数和子命令解析器.通过使用这种方法,可以在使用 1.argparse简介: argparse 模块是 Python 内置的一个用于命令项选项与参数 ...

  2. C++ CryptoPP使用AES加解密

    Crypto++ (CryptoPP) 是一个用于密码学和加密的 C++ 库.它是一个开源项目,提供了大量的密码学算法和功能,包括对称加密.非对称加密.哈希函数.消息认证码 (MAC).数字签名等.C ...

  3. 2.1 C++ STL 数组向量容器

    Vector容器是C++ STL中的一个动态数组容器,可以在运行时动态地增加或减少其大小,存储相同数据类型的元素,提供了快速的随机访问和在末尾插入或删除元素的功能. 该容器可以方便.灵活地代替数组,容 ...

  4. C++ STL 标准模板库(容器总结)算法

    C++ 标准模板库STL,是一个使用模板技术实现的通用程序库,该库由容器container,算法algorithm,迭代器iterator,容器和算法之间通过迭代器进行无缝连接,其中所包含的数据结构都 ...

  5. 基于.NET三维控件的个性化管道软件开发

    1 简介 管道广泛用于化工.工厂.建筑.市政等方面,关系到国计民生.虽然管道设计软件种类繁多,有的也非常强大(然而也非常昂贵),但也并不能完全满足个性化需要. 如何快速开发一款满足自己需求的三维管道设 ...

  6. 目录:CH57x/CH58x/CH59x/CH32V208低功耗蓝牙应用

    外设相关: CH59x 系统16位PWM使用 - 小舟从此逝_1 - 博客园 (cnblogs.com) CH59X/CH58X/CH57X PWM使用 - 小舟从此逝_1 - 博客园 (cnblog ...

  7. 探索C语言的内存魔法:动态内存管理解析

    欢迎大家来到贝蒂大讲堂 养成好习惯,先赞后看哦~ 所属专栏:C语言学习 贝蒂的主页:Betty's blog 1. 静态开辟内存 通过前面的学习,我们已经掌握了两种开辟内存的方法,分别是: #incl ...

  8. 山东职业竞赛wp2023(arm、cpython)

    pwn2 return2libc,白给 from evilblade import * context(os='linux', arch='amd64') context(os='linux', ar ...

  9. JS 可选链操作符?. 空值合并运算符?? 详解,更精简的安全取值与默认值设置小技巧

    壹 ❀ 引 说来也比较惭愧,可选链操作符?.在公司项目中使用特别频繁,而我在之前一直以为是类似奇技淫巧的写法,所以也没去查阅相关文档,直到在学习typescript时碰巧看到了可选链操作符与空值合并操 ...

  10. NC19885 [AHOI2009]CHESS 中国象棋

    题目链接 题目 题目描述 在N行M列的棋盘上,放若干个炮可以是0个,使得没有任何一个炮可以攻击另一个炮. 请问有多少种放置方法,中国像棋中炮的行走方式大家应该很清楚吧.一个炮要能攻击另一个炮他们必须要 ...