Skip to content

feat(core): add Signed-off-by rule #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions @commitlint/core/src/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
'scope-enum': require('./scope-enum'),
'scope-max-length': require('./scope-max-length'),
'scope-min-length': require('./scope-min-length'),
'signed-off-by': require('./signed-off-by'),
'subject-case': require('./subject-case'),
'subject-empty': require('./subject-empty'),
'subject-full-stop': require('./subject-full-stop'),
Expand Down
13 changes: 13 additions & 0 deletions @commitlint/core/src/rules/signed-off-by.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default (parsed, when, value) => {
const input = /.*\n(Signed-off-by:).*\n+/g.exec(parsed.raw);

const negated = when === 'never';
const hasSignedOffBy = Boolean(input && input[1] === value);

return [
negated ? !hasSignedOffBy : hasSignedOffBy,
['message', negated ? 'must not' : 'must', 'be signed off']
.filter(Boolean)
.join(' ')
];
};
79 changes: 79 additions & 0 deletions @commitlint/core/src/rules/signed-off-by.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import test from 'ava';
import parse from '../library/parse';
import check from './signed-off-by';

const messages = {
empty: 'chore:\n',
with: `chore: subject\nbody\nfooter\nSigned-off-by:\n\n`,
without: `chore: subject\nbody\nfooter\n\n`,
inSubject: `chore: subject Signed-off-by:\nbody\nfooter\n\n`,
inBody: `chore: subject\nbody Signed-off-by:\nfooter\n\n`
};

const parsed = {
empty: parse(messages.empty),
with: parse(messages.with),
without: parse(messages.without),
inSubject: parse(messages.inSubject),
inBody: parse(messages.inBody)
};

test('empty against "always signed-off-by" should fail', async t => {
const [actual] = check(await parsed.empty, 'always', 'Signed-off-by:');
const expected = false;
t.is(actual, expected);
});

test('empty against "never signed-off-by" should succeed', async t => {
const [actual] = check(await parsed.empty, 'never', 'Signed-off-by:');
const expected = true;
t.is(actual, expected);
});

test('with against "always signed-off-by" should succeed', async t => {
const [actual] = check(await parsed.with, 'always', 'Signed-off-by:');
const expected = true;
t.is(actual, expected);
});

test('with against "never signed-off-by" should fail', async t => {
const [actual] = check(await parsed.with, 'never', 'Signed-off-by:');
const expected = false;
t.is(actual, expected);
});

test('without against "always signed-off-by" should fail', async t => {
const [actual] = check(await parsed.without, 'always', 'Signed-off-by:');
const expected = false;
t.is(actual, expected);
});

test('without against "never signed-off-by" should succeed', async t => {
const [actual] = check(await parsed.without, 'never', 'Signed-off-by:');
const expected = true;
t.is(actual, expected);
});

test('inSubject against "always signed-off-by" should fail', async t => {
const [actual] = check(await parsed.inSubject, 'always', 'Signed-off-by:');
const expected = false;
t.is(actual, expected);
});

test('inSubject against "never signed-off-by" should succeed', async t => {
const [actual] = check(await parsed.inSubject, 'never', 'Signed-off-by:');
const expected = true;
t.is(actual, expected);
});

test('inBody against "always signed-off-by" should fail', async t => {
const [actual] = check(await parsed.inBody, 'always', 'Signed-off-by:');
const expected = false;
t.is(actual, expected);
});

test('inBody against "never signed-off-by" should succeed', async t => {
const [actual] = check(await parsed.inBody, 'never', 'Signed-off-by:');
const expected = true;
t.is(actual, expected);
});
8 changes: 8 additions & 0 deletions docs/reference-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,11 @@ Rule configurations are either of type `array` residing on a key with the rule's
```js
0
```

#### signed-off-by
* **condition**: `message` has `value`
* **rule**: `always`
* **value**
```js
'Signed-off-by:'
```