Javascript Git和esformatter在react原生项目中的使用
在提交之前,我想知道如何让在git项目中更改的所有js文件都运行esformatter。 如果不可能,请说明如何对所有js文件运行esformatter 这是我的json包。我真的是德沃斯的新手。任何建议都很感激,但我真的很想在提交前实现自动格式。非常感谢Javascript Git和esformatter在react原生项目中的使用,javascript,git,react-native,Javascript,Git,React Native,在提交之前,我想知道如何让在git项目中更改的所有js文件都运行esformatter。 如果不可能,请说明如何对所有js文件运行esformatter 这是我的json包。我真的是德沃斯的新手。任何建议都很感激,但我真的很想在提交前实现自动格式。非常感谢 { "name": "asdasda", "version": "0.0.1", "private": true, "scripts": { "start": "node nod
{
"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
}
}
}
}
预提交是您需要的。我还没有测试过这个,但我认为你需要这样的东西:
#!/usr/bin/env bash
EXIT_CODE=0
ESFORMATTER_ERRORS=$( esformatter src/**/*.js | tee )
if [[ $ESFORMATTER_ERRORS ]]; then
echo "$ESFORMATTER_ERRORS"
EXIT_CODE=1
fi
exit $EXIT_CODE
我实际上是在用husky woof实现git钩子!因此,我想知道如何在提交之前为所有js更改的文件实现脚本我如何在提交中列出所有更改的文件并对其应用esformatter?这就是列出所有更改的文件的方式:git diff-name only HEAD~1 HEAD。在shell脚本中使用stdout将它们传递给esformatter命令。该命令提供上次推送中最后修改的文件?我需要那些我正在修改的未跟踪文件,这意味着要提交的更改:以及不准备提交的更改:所有这些都是js格式的文件