在git pre-commit期间忽略eslint错误

时间:2017-05-31 11:07:13

标签: javascript git eslint package.json pre-commit-hook

我想将eslint与git pre-commit挂钩一起使用,因此它可以自动修复错误(至少可以自动修复)并忽略其他错误,因此它不会阻止提交本身。

package.json中的代码:

"scripts": {
    "test-staged": "lint-staged"
},
"pre-commit": [
  "test-staged"
],
"lint-staged": {
  "*.{js,jsx}": [
    "eslint --config=config/.eslintrc --fix",
    "git add"
  ]
}

我怎样才能实现它?

1 个答案:

答案 0 :(得分:0)

好的,我认为让它起作用了:

"scripts": {
   "eslint-fix-force": "npm run eslint --fix || true",
   "test-staged": "lint-staged"
}

"lint-staged": {
  "*.{js,jsx}": [
    "eslint-fix-force",
    "git add"
  ]
}

您还需要lint-staged dependencies内的package.json from collections import Counter, defaultdict from itertools import groupby, chain dictionary = {'cat_1' : {'age' : 5, 'height' : 15}, 'cat_2' : {'age' : 1, 'height' : 7}, 'dog_1' : {'age' : 13, 'height' : 20}, 'dog_2' : {'age' : 9, 'height' : 18}} animals_grouped = groupby(sorted(dictionary.items(), key=lambda x: x[0].split('_')[0]), key=lambda x: x[0].split('_')[0]) animals_data_average = defaultdict(dict) for animal in animals_grouped: animal_data_list = list(chain.from_iterable(list(animal_data[1].items()) for animal_data in animal[1])) animal_key_counter = Counter([animal_data[0] for animal_data in animal_data_list]) for data_key in animal_key_counter: animals_data_average[animal[0]][data_key] = sum([animal_data[1] for animal_data in animal_data_list if animal_data[0] == data_key]) / animal_key_counter[data_key] print(dict(animals_data_average))