Skip to content

Latest commit

 

History

History
90 lines (61 loc) · 2.51 KB

README.md

File metadata and controls

90 lines (61 loc) · 2.51 KB

编程风格

Style Guide

目的

写出合理的、易于阅读和维护的代码。因为代码是给人看的。

不整洁的代码给人的感觉如下图:

Chaos Cabel

整洁的代码看这里

常见规则

  • 避免使用 var, 尽可能使用 const
  • 如果无法使用 const, 使用 let
  • 尽可能使用对象简写形式
  • 字符串使用单引号或反引号
  • 使用 ... 拷贝数组
  • 立即执行函数使用箭头函数的形式

Airbnb 中文版

EditorConfig

EditorConfig

EditorConfig 帮助开发人员在不同的编辑器和 IDE 中保持一致的编码风格。

比如:vue/.editorconfig

# http://editorconfig.org

root = true

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

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false

ESLint

ESLint 是一个语法规则和代码风格的检查工具,可以用来保证写出语法正确、风格统一的代码。

首先,安装ESLint。

$ npm install eslint --save-dev

然后,初始化配置文件:

$ ./node_modules/.bin/eslint --init

现在就可以检查,当前项目的代码是否符合预设的规则。

$ ./node_modules/.bin/eslint yourfile.js

代码质量

wtfm

检验代码质量的唯一标准:脏口次数/每分钟

参考文献