0
我想知道如何在提交之前讓我的git項目中更改的所有js文件運行esformatter。 如果這是不可能的,如何運行esformatter到所有js文件。Git和esformatter在反應原生項目中的使用
這是我的包json。我在devops中真的很新。任何意見是讚賞,但我真的很想在提交之前實現自動格式。非常感謝!
{
"name": "asdasda",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"precommit": "esformatter (to a changedfile using husky its possible?)"
},
"dependencies": {
"@remobile/react-native-splashscreen": "^1.0.4",
"babel-eslint": "^6.0.0",
"eslint": "^3.13.1",
"eslint-plugin-react": "^6.9.0",
"eslint-plugin-react-native": "^2.2.1",
"firebase": "^3.4.1",
"husky": "^0.12.0",
"moment": "^2.15.2",
"react": "15.3.1",
"react-native": "0.33.0"
},
"rnpm": {
"assets": [
"./assets"
]
},
"devDependencies": {
"esformatter-jsx": "^7.4.1"
},
"esformatter": {
"plugins": [
"esformatter-jsx"
],
// this is the section this plugin will use to store the settings for the jsx formatting
"jsx": {
// whether to recursively format jsx expressions with esformatter
// set this to false if you don't want JSXExpressions to be formatted recursively, like when using problematic plugins
"formatJSXExpressions": true,
// By default ObjectExpression and ArrayExpression in JSXExpressions are inlined,
// if false, the Expression might expand several lines
"JSXExpressionsSingleLine": true,
// by default is true if set to false it works the same as esformatter-jsx-ignore
"formatJSX": true,
// keep the node attributes on the same line as the open tag. Default is true.
// Setting this to false will put each one of the attributes on a single line
"attrsOnSameLineAsTag": true,
// how many attributes should the node have before having to put each
// attribute in a new line. Default 1
"maxAttrsOnTag": 1,
// if the attributes are going to be put each one on its own line, then keep the first
// on the same line as the open tag
"firstAttributeOnSameLine": false,
// default to one space. Make it empty if you don't like spaces between JSXExpressionContainers
"spaceInJSXExpressionContainers": " ",
// align the attributes with the first attribute (if the first attribute was kept on the same line as on the open tag)
"alignWithFirstAttribute": true,
"htmlOptions": { // same as the ones passed to js-beautifier.html
"brace_style": "collapse",
"indent_char": " ",
"indent_size": 2,
"max_preserve_newlines": 2,
"preserve_newlines": true
//wrap_line_length: 250
}
}
}
}
嗯,我實際上實施git掛鉤哈士奇https://github.com/typicode/husky woof!所以,我想知道如何在提交之前爲所有js更改的文件實施腳本 – arnoldssss
如何在提交中列出所有更改的文件並將esformatter應用於它們? – arnoldssss
這就是你如何列出al改變的文件:'git diff --name-only HEAD〜1 HEAD'。在shell腳本中使用stdout將它們傳遞給您的esformatter命令。 – Dani