File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ module.exports = {
4747 "too-many-spaces" : [ RuleConfigSeverity . Error , "always" ] ,
4848 "commit-hash-alone" : [ RuleConfigSeverity . Error , "always" ] ,
4949 "title-uppercase" : [ RuleConfigSeverity . Error , "always" ] ,
50+ "reject-obvious-words" : [ RuleConfigSeverity . Error , "always" ] ,
5051 } ,
5152 plugins : [
5253 // TODO (ideas for more rules):
@@ -81,6 +82,21 @@ module.exports = {
8182 return Plugins . commitHashAlone ( rawStr ) ;
8283 } ,
8384
85+ "reject-obvious-words" : ( {
86+ header,
87+ body,
88+ } : {
89+ header : any ;
90+ body : any ;
91+ } ) => {
92+ let headerStr = Helpers . convertAnyToString (
93+ header ,
94+ "header"
95+ ) ;
96+ let bodyStr = Helpers . convertAnyToString ( body , "header" ) ;
97+ return Plugins . rejectObviousWords ( headerStr , bodyStr ) ;
98+ } ,
99+
84100 "empty-wip" : ( { header } : { header : any } ) => {
85101 let headerUncastedStr = Helpers . convertAnyToString (
86102 header ,
Original file line number Diff line number Diff line change 11import { abbr } from "./abbreviations" ;
22import { Helpers } from "./helpers" ;
3+ const obviousWords = [ "change" , "update" , "modify" ] ;
34
45export abstract class Plugins {
56 public static bodyProse ( rawStr : string ) {
@@ -260,6 +261,35 @@ export abstract class Plugins {
260261 ] ;
261262 }
262263
264+ public static rejectObviousWords (
265+ headerStr : string | null ,
266+ bodyStr : string | null
267+ ) {
268+ let offence = false ;
269+ let firstWordInTitle = "" ;
270+
271+ if ( headerStr !== null ) {
272+ let colonFirstIndex = headerStr . indexOf ( ":" ) ;
273+ let titleStartIndex = Math . max ( 0 , colonFirstIndex + 1 ) ;
274+ let title = headerStr
275+ . substring ( titleStartIndex , headerStr . length )
276+ . trim ( ) ;
277+ let titleWords = title . split ( " " ) ;
278+ firstWordInTitle = titleWords [ 0 ] ;
279+
280+ if ( firstWordInTitle === "update" ) {
281+ offence = titleWords . length > 1 && bodyStr === null ;
282+ } else {
283+ offence = obviousWords . includes ( firstWordInTitle ) ;
284+ }
285+ }
286+
287+ return [
288+ ! offence ,
289+ `Please don't use obvious words such as ${ firstWordInTitle } in the commit title` ,
290+ ] ;
291+ }
292+
263293 public static titleUppercase ( headerStr : string ) {
264294 let firstWord = headerStr . split ( " " ) [ 0 ] ;
265295 let offence =
You can’t perform that action at this time.
0 commit comments