Skip to content

Commit

Permalink
feat(core): expose fine-grained API for subject-case
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Nov 18, 2017
1 parent e755726 commit 924ec09
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions @commitlint/core/src/rules/subject-case.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import ensureCase from '../library/ensure-case';
import message from '../library/message';

const negated = when => when === 'never';

export default (parsed, when, value) => {
const {subject} = parsed;

if (!subject) {
if (typeof subject !== 'string') {
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.every(check => {
const r = ensureCase(subject, check.case);
return negated(check.when) ? !r : r;
});

const result = ensureCase(subject, value);
return [
negated ? !result : result,
negated(when) ? !result : result,
message([`subject must`, negated ? `not` : null, `be ${value}`])
];
};

0 comments on commit 924ec09

Please sign in to comment.