forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rules): support array for scope-case and type-case
As per issue conventional-changelog#307 port the logic from subject-case for array definitions over to scope-case and type-case.
- Loading branch information
Simeon Cheeseman
committed
Mar 27, 2018
1 parent
86c34f1
commit d2a5fb5
Showing
5 changed files
with
206 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
import * as ensure from '@commitlint/ensure'; | ||
import message from '@commitlint/message'; | ||
|
||
const negated = when => when === 'never'; | ||
|
||
export default (parsed, when, value) => { | ||
const {scope} = parsed; | ||
|
||
if (!scope) { | ||
return [true]; | ||
} | ||
|
||
const negated = when === 'never'; | ||
const checks = (Array.isArray(value) ? value : [value]).map(check => { | ||
if (typeof check === 'string') { | ||
return { | ||
when: 'always', | ||
case: check | ||
}; | ||
} | ||
return check; | ||
}); | ||
|
||
const result = checks.some(check => { | ||
const r = ensure.case(scope, check.case); | ||
return negated(check.when) ? !r : r; | ||
}); | ||
|
||
const list = checks.map(c => c.case).join(', '); | ||
|
||
const result = ensure.case(scope, value); | ||
return [ | ||
negated ? !result : result, | ||
message([`scope must`, negated ? `not` : null, `be ${value}`]) | ||
negated(when) ? !result : result, | ||
message([`scope must`, negated(when) ? `not` : null, `be ${list}`]) | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
import * as ensure from '@commitlint/ensure'; | ||
import message from '@commitlint/message'; | ||
|
||
const negated = when => when === 'never'; | ||
|
||
export default (parsed, when, value) => { | ||
const {type} = parsed; | ||
|
||
if (!type) { | ||
return [true]; | ||
} | ||
|
||
const negated = when === 'never'; | ||
const checks = (Array.isArray(value) ? value : [value]).map(check => { | ||
if (typeof check === 'string') { | ||
return { | ||
when: 'always', | ||
case: check | ||
}; | ||
} | ||
return check; | ||
}); | ||
|
||
const result = checks.some(check => { | ||
const r = ensure.case(type, check.case); | ||
return negated(check.when) ? !r : r; | ||
}); | ||
|
||
const list = checks.map(c => c.case).join(', '); | ||
|
||
const result = ensure.case(type, value); | ||
return [ | ||
negated ? !result : result, | ||
message([`type must`, negated ? `not` : null, `be ${value}`]) | ||
negated(when) ? !result : result, | ||
message([`type must`, negated(when) ? `not` : null, `be ${list}`]) | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters