crutch12

branch-name-lint

Aug 2nd, 2021 (edited)
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 1) install package:
  2. // $ npm i -D branch-name-lint
  3.  
  4.  
  5. // 2) create file branchNameLint.js
  6. // eslint-disable-next-line @typescript-eslint/no-var-requires
  7. const branchNameLint = require('branch-name-lint');
  8.  
  9. // See: https://github.com/barzik/branch-name-lint#options
  10. const options = {
  11.   prefixes: ['feature', 'hotfix', 'release'],
  12.   suggestions: {
  13.     features: 'feature',
  14.     feat: 'feature',
  15.     fix: 'hotfix',
  16.     releases: 'release',
  17.   },
  18.   banned: ['wip', 'bugfix'],
  19.   skip: [],
  20.   disallowed: ['staging'],
  21.   separator: '/',
  22.   msgBranchBanned: 'Branches with the name "%s" are not allowed.',
  23.   msgBranchDisallowed: 'Pushing to "%s" is not allowed, use git-flow.',
  24.   msgPrefixNotAllowed: 'Branch prefix "%s" is not allowed.',
  25.   msgPrefixSuggestion: 'Instead of "%s" try "%s".',
  26.   msgseparatorRequired: 'Branch "%s" must contain a separator "%s".',
  27.   msgDoesNotMatchRegex: 'Branch "%s" does not match the allowed pattern: "%s"',
  28. };
  29.  
  30. const answer = new branchNameLint(options).doValidation();
  31.  
  32. if (answer === 1) {
  33.   process.exit(1);
  34. }
  35.  
  36.  
  37. // 3) add package.json hook
  38. "husky": {
  39.   "hooks": {
  40.     "pre-push": "node branchNameLint"
  41.   }
  42. }
Add Comment
Please, Sign In to add comment