.gitignore 規(guī)則
忽略上傳到 git 的文件
-
#
代表注釋 - 匹配模式前
/
代表項目根目錄 - 匹配模式最后加
/
代表是目錄链快,如果文件和文件夾名字相同時候有用 - 匹配模式前加
!
代表取反 -
*
代表任意個字符 -
机断?
匹配任意一個字符 -
**
匹配多級目錄
.npmignore
忽略上傳到 npm 的文件
規(guī)則和 .gitignore
類似。
如果項目里面沒有 .npmignore
文件边翼,則會讀取 .gitignore
.editorconfig
代碼風(fēng)格的配置,為了讓項目在不同的編輯器、IDE 中代碼風(fēng)格一樣枝秤。
eslint
規(guī)范 JavaScript 書寫規(guī)范,讓代碼風(fēng)格統(tǒng)一慷嗜。
//全局安裝 eslint
npm intall -g eslint
//初始化一個 eslintrc
eslint --init
eslintrc
的配置例子
module.exports = {
"env": {
"node": true,
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
};
自動化檢查 eslint
在
package.json
中添加自定義script
指令
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"fix": "eslint --fix .",
"lint": "eslint ."
},
使用
pre-commit
工具淀弹,在git commit
之前檢測eslint
,檢測不通過則commit
失敗
安裝 pre-commit
npm install pre-commit --save-dev
在 package.json
中添加配置項
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"fix": "eslint --fix .",
"lint": "eslint ."
},
"pre-commit": [
"fix",
"lint"
],
這樣庆械,如果 eslint
檢測不能通過薇溃,就會 commit
失敗
.eslintignore
忽略進(jìn)行
eslint
檢查的文件,規(guī)則和.gitignore
類似缭乘。