john-book
  • 测试
    • vue单元测试
  • 介绍
  • 设计模式
    • 单例模式
  • 个人收藏
    • 房价未来趋势
  • TodoList
  • TaskList
  • 前端架构设计
  • 时间管理
    • 2019前端自检与思考
  • 前端技术点
    • 异步编程和同步编程
    • 继承实现的几种方式
    • Http请求
    • 前端CI/CD持续集成持续交付
    • Promise
    • 其他工具
    • iphonex以及适配
    • 前端骨架屏方案
    • nginx
      • nginx配置upstream负载均衡
      • nginx配置gzip压缩
      • nginx转发配置
    • ajax
    • Dom&BOM
    • flexible
    • jsonp
    • 跨域
    • nunjucks
    • 水平垂直居中
    • 原型和原型链
    • 本地存储方式
    • 无头浏览器
    • chrome插件开发
    • webpack
      • DllPlugin
      • webpack升级
    • 宏任务微任务
    • 页面加载流程
    • http请求流程
    • 图形绘制技术
    • 节流和防抖
    • webpack单页面改多页面
    • redis安装使用
    • git
      • gitignore的使用
  • 算法
  • 前端资料
    • 开源技术库
    • 资料&文档
      • 信息流页面闪开总结
    • 每日收藏
  • 工具
    • UML图
    • Markdown
    • 测试工具
    • 产品工具
  • 站点博客
    • 站点集锦
  • 框架&库
    • React
    • Vue
    • vue3.0
  • 性能优化
    • 性能优化原则和方法
    • Http协议
      • Http Request Header
      • Http Response Header
  • LowCode
    • landingpage
    • landingpage自动化部署
    • landingpage相关
  • 加密
  • 腾讯云服务器
  • 微信公众号开发
  • 微信小程序
    • 小程序埋点统计
    • app分享小程序绑定
  • 数据库
    • 数据库实时抽取
  • 效率
    • 快速生成层级结构图
    • vscode插件vue模版
    • vscode文件头部注释插件
    • 快速生成项目目录结构树
    • vscode格式化配置
    • 前端组件化
  • 前端工作
  • 可视化
    • 页面可视化搭建
  • 前端规范
    • Javascript规范
    • git提交规范
    • eslint三大通用规范
Powered by GitBook
On this page
  • 安装vscode插件
  • 用户设置/工作区设置
  • 项目文件配置
  • .editorconfig
  • .eslintrc.js
  • .eslintignore.js

Was this helpful?

  1. 效率

vscode格式化配置

Previous快速生成项目目录结构树Next前端组件化

Last updated 6 years ago

Was this helpful?

安装vscode插件

  • Eslint

  • Prettier

  • Vetur

主要采用eslint搭配prettier规范的方式。

用户设置/工作区设置

用户设置和工作区设置区别详见:

code/文件-->首选项-->设置-->setting.json-->编辑(用户设置)

{
    "fileheader.configObj": {
        "createFileTime":true,
        "timeNoDetail":false,
        "autoAdd":true,
        "autoAlready":true,
        "annotationStr": {"head":"/*","middle":" * @","end":" */","use":true},
        "headInsertLine": {"php": 2}},
        "fileheader.cursorMode": {"description":"","param ":"","return":""},
        "fileheader.customMade": {
            "Description":"",//文件内容描述"
            Author":"(name)",//编辑人(此处设置自己的姓名)
            "Email":"name@163.com",//此处设置自己的邮箱信息
            "Date":"Do not edit",//时间
            "LastEditTime":"Do not edit",
            "LastEditors":"name"//此处设置自己的姓名
        },

        //添加vue支持,代码错误实时提示"
        eslint.validate": [
            "javascript",
            "javascriptreact",
            {"language":"html","autoFix":true},
            {"language":"vue","autoFix":true}
        ],
        // 开启 vscode 文件路径导航
        "breadcrumbs.enabled":true,

        //开启eslint支持,格式化eslint
        "prettier.eslintIntegration":true,

        //ctrl+s保存时自动修正格式错误的js代码
        "eslint.autoFixOnSave":true,

        //保存时自动格式化
        "editor.formatOnSave":true,

        //tab索引为2个空格
        "editor.tabSize": 2,

        //强制单引号
        "prettier.singleQuote":true,

        //声明结尾使用分号(默认true)
        "prettier.semi": false,

        // vetur 的自定义设置
        "vetur.format.defaultFormatterOptions": 
        {
            "prettier": {
                "singleQuote":true
                "semi": false,
            }
        },

        // js默认偏移一个indent应为true
        "vetur.format.scriptInitialIndent":false,

        // style默认偏移一个indent应为true
        "vetur.format.styleInitialIndent":false,

        //只有一个参数的箭头函数的参数是否带圆括号(默认avoid)
        "prettier.arrowParens":"avoid",

        //多行JSX中的>放置在最后一行的结尾,而不是另起一行(默认false)
        "prettier.jsxBracketSameLine":false
}

项目文件配置

.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

// http://eslint.org/docs/user-guide/configuring

module.exports = {
  root: true,
  parser: 'babel-eslint',
  parserOptions: {
    sourceType: 'module'
  },
  env: {
    browser: false,
    node: true,
    es6: true
  },
  // https://github.com/standard/standard/blob/master/docs/RULES-en.md
  extends: 'standard',
  // required to lint *.vue files
  plugins: [
    'vue',
    'html'
  ],
  // add your custom rules here
  'rules': {
     // allow paren-less arrow functions
    'arrow-parens': 0,
    'no-extra-semi': 0, //不允许出现不必要的分号
    'space-before-function-paren': 0 //
    // allow async-await
    'generator-star-spacing': 'off',
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
  },
  //全局变量,暂不使用
  globals: {
    //App: true,
    //Page: true,
    //getApp: true,
    //getPage: true
  }
}

.eslintignore.js

build/*.js
config/*.js

eslint配置文档参考:

(.eslintrc.js配置规则详细说明 )

,

https://www.cntofu.com/book/98/md/定制化/用户和工作空间.md
https://www.jianshu.com/p/25706af1f6a7
https://cloud.tencent.com/developer/doc/1078
https://segmentfault.com/a/1190000008742240
https://blog.csdn.net/userkang/article/details/84305689
https://eslint.org/docs/user-guide/configuring
https://segmentfault.com/a/1190000014785115?utm_source=index-hottest
https://www.jb51.net/article/135191.htm