2017-01-19 6 views
0

コミットする前に私のgitプロジェクトで変更されたすべてのjsファイルに対してesformatterを実行する方法を知りたかったのです。 これが不可能な場合は、すべてのjsファイルに対してesformatterを実行する方法です。ネイティブプロジェクトを反応させてesformatterを使うと、

これは私のパッケージjsonです。私はdevopで本当に新しいです。どんなアドバイスも感謝していますが、実際にコミットする前に自動化されたフォーマットを達成したいと思います。どうもありがとう!

{ 
     "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 
     } 
     } 
    } 
    } 

答えて

1

事前コミットGit Hookはあなたが探しているものです。私はこれをテストしていませんが、私はあなたのようなものが必要だと思う:まあ、私は実際にハスキーhttps://github.com/typicode/husky横糸でGitのフックを実装しています

#!/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 
+0

を!だから、コミットする前にすべてのjs変更されたファイルのスクリプトを実装する方法を知りたい – arnoldssss

+0

変更されたすべてのファイルをコミットして一覧表示するにはどうすればよいですか? – arnoldssss

+0

これは、変更されたファイルをリストする方法です: 'git diff --name-only HEAD〜1 HEAD'。シェルスクリプトでstdoutを使用して、それらをesformatterコマンドに渡します。 – Dani

関連する問題