Skip to content
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

subjectLimit option usage and validation #114

Merged
merged 2 commits into from
May 9, 2020
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Hopefully this will help you to have consistent commit messages and have a fully

Here are the options you can set in your `.cz-config.js`:

* **subjectLimit**: {number, default 100}: This is the commit first line. Example: `feat: this is a new feature` or `feat(scopePayments): this is a new feature`
* **subjectLimit**: {number, default 100}: This is the subject limit. Example: `this is a new feature` or `fix a bug`
* **subjectSeparator**: {string, default ': '}: This is the subject separator. Example: `feat: this is a new feature`
* **typePrefix**: {string, default ''}: This is the commit type prefix. Example: config: `{ typePrefix: '[' }`, result: `[feat: this is a new feature`
* **typeSuffix**: {string, default ''}: This is the commit type suffix. Example: config: `{ typePrefix: '[', typeSuffix: ']', subjectSeparator: ' ' }`, result: `[feat] this is a new feature`
Expand Down
5 changes: 2 additions & 3 deletions buildCommit.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ module.exports = (answers, config) => {

// Hard limit this line
// eslint-disable-next-line max-len
const head = (
const head =
addType(answers.type, config) +
addScope(answers.scope, config) +
addTicketNumber(answers.ticketNumber, config) +
addSubject(answers.subject)
).slice(0, defaultMaxLineWidth);
addSubject(answers.subject.slice(0, config.subjectLimit));

// Wrap these lines at 100 characters
let body = wrap(answers.body, wrapOptions) || '';
Expand Down
7 changes: 2 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ const readConfigFile = () => {
module.exports = {
prompter(cz, commit) {
const config = readConfigFile();
const subjectLimit = config.subjectLimit || 100;

log.info(
`\n\nLine 1 will be cropped at ${subjectLimit} characters. All other lines will be wrapped after 100 characters.\n`
);
config.subjectLimit = config.subjectLimit || 100;
log.info('All lines except first will be wrapped after 100 characters.');

const questions = require('./questions').getQuestions(config, cz);

Expand Down
4 changes: 2 additions & 2 deletions spec/czCustomizableSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('cz-customizable', () => {
}, 100);
});

it('should truncate first line if number of characters is higher than 200', () => {
it('should truncate subject if number of characters is higher than 100', () => {
const chars100 =
'0123456789-0123456789-0123456789-0123456789-0123456789-0123456789-0123456789-0123456789-0123456789-0123456789';

Expand All @@ -183,7 +183,7 @@ describe('cz-customizable', () => {
const firstPart = 'feat(myScope): ';

const firstLine = commit.mostRecentCall.args[0].split('\n\n')[0];
expect(firstLine).toEqual(firstPart + answers.subject.slice(0, 100 - firstPart.length));
expect(firstLine).toEqual(firstPart + answers.subject.slice(0, 100));

// it should wrap body
const body = commit.mostRecentCall.args[0].split('\n\n')[1];
Expand Down
4 changes: 2 additions & 2 deletions spec/questionsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('cz-customizable', () => {
isTicketNumberRequired: true,
ticketNumberPrefix: 'TICKET-',
ticketNumberRegExp: '\\d{1,5}',
subjectLimit: 20,
subjectLimit: 40,
};

// question 1 - TYPE
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('cz-customizable', () => {
expect(getQuestion(5).type).toEqual('input');
expect(getQuestion(5).message).toMatch(/IMPERATIVE tense description/);
expect(getQuestion(5).filter('Subject')).toEqual('subject');
expect(getQuestion(5).validate('bad subject that exceed limit')).toEqual('Exceed limit: 20');
expect(getQuestion(5).validate('bad subject that exceed limit for 6 characters')).toEqual('Exceed limit: 40');
expect(getQuestion(5).validate('good subject')).toEqual(true);

// question 6 - BODY
Expand Down