Skip to content

Instantly share code, notes, and snippets.

@colestrode
Last active May 20, 2018 20:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colestrode/c01e17583d91a3b7496627e0e90c3ea3 to your computer and use it in GitHub Desktop.
Save colestrode/c01e17583d91a3b7496627e0e90c3ea3 to your computer and use it in GitHub Desktop.
Lint on commit, audit on push
#!/bin/bash
# This will automatically run npm audit fix on your branch and commit the changes with a commit message that includes the current branch name
# It will not run on develop or master branches
# You can skip it on other branches with the --no-verify command line option: git push origin branch --no-verify
BRANCH=`git rev-parse --abbrev-ref HEAD`
MESSAGE="$BRANCH npm audit fix"
if [[ $BRANCH = 'master' ]] || [[ $BRANCH = 'develop' ]] ; then
echo 'skipping audit on '$BRANCH' branch'
exit 0
fi
npm audit fix
git add package.json package-lock.json
git commit -m "$MESSAGE"
{
"name": "audit-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"lint": "eslint . --fix",
"precommit": "lint-staged",
"prepush": "./audit.sh"
},
"repository": {
"type": "git",
"url": "git+https://github.com/colestrode/audit-test.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/colestrode/audit-test/issues"
},
"homepage": "https://github.com/colestrode/audit-test#readme",
"dependencies": {
"lodash": "^4.17.10"
},
"devDependencies": {
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-standard": "^3.1.0",
"husky": "^0.14.3",
"lint-staged": "^7.1.1"
},
"lint-staged": {
"**/*.js": [
"npm run lint",
"git add"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment