Skip to content
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
8 changes: 4 additions & 4 deletions .sgcrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"body": true,
"emoji": false,
"lowercaseTypes": false,
"initial-commit": {
"initialCommit": {
"isEnabled": true,
"emoji": ":tada:",
"message": "Initial commit"
Expand Down Expand Up @@ -56,8 +56,8 @@
}
],
"rules": {
"max-char": 72,
"min-char": 10,
"end-with-dot": false
"maxChar": 72,
"minChar": 10,
"endWithDot": false
}
}
4 changes: 2 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ if (argv.v) {
} else if (!isAdded()) {
console.error(chalk.red('Please', chalk.bold('git add'), 'some files first before you commit.'));
} else if (commitCount() === 0 &&
typeof config['initial-commit'] === 'object' &&
config['initial-commit'].isEnabled) {
typeof config.initCommit === 'object' &&
config.initCommit.isEnabled) {
const message = initMessage(config);

inquirer.prompt(question).then(answers => (
Expand Down
4 changes: 2 additions & 2 deletions lib/getConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const getConfig = (altPath) => {
tempConfig.types = config.types;
}

if (config['initial-commit']) {
tempConfig['initial-commit'] = config['initial-commit'];
if (config.initialCommit) {
tempConfig.initialCommit = config.initialCommit;
}

// next will remove "inherit" from the config
Expand Down
8 changes: 4 additions & 4 deletions lib/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const initMessage = (config) => {
let message = '';

if (config.emoji &&
typeof config['initial-commit'] === 'object' &&
config['initial-commit'].isEnabled) {
message = `${config['initial-commit'].emoji} ${config['initial-commit'].message}`;
typeof config.initialCommit === 'object' &&
config.initialCommit.isEnabled) {
message = `${config.initialCommit.emoji} ${config.initialCommit.message}`;
} else {
message = config['initial-commit'].message;
message = config.initialCommit.message;
}

return message;
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/availableRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const rules = {
},
}),
maxChar: (input, config) => ({
message: () => `The commit message is not allowed to be longer as ${config.rules['max-char']} character, but is ${input.length} character long. Consider writing a body.`,
message: () => `The commit message is not allowed to be longer as ${config.rules.maxChar} character, but is ${input.length} character long. Consider writing a body.`,
check: () => {
let number = config.rules['max-char'];
let number = config.rules.maxChar;

if (number === -1) {
number = Number.POSITIVE_INFINITY;
Expand All @@ -26,9 +26,9 @@ const rules = {
},
}),
minChar: (input, config) => ({
message: () => `The commit message has to be at least ${config.rules['min-char']} character, but is only ${input.length} character long.`,
message: () => `The commit message has to be at least ${config.rules.minChar} character, but is only ${input.length} character long.`,
check: () => {
if (input.length < config.rules['min-char']) {
if (input.length < config.rules.minChar) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/rules/ruleWarningMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const ruleWarningMessages = (input, config) => {
const configRuleEntries = entries(config.rules);

configRuleEntries.forEach((rule) => {
const camelCaseRuleName = (rule[0]).replace(/-([a-z])/g, g => (g[1].toUpperCase()));
const ruleIs = rules[camelCaseRuleName](input, config).check();
const ruleName = rule[0];
const ruleIs = rules[ruleName](input, config).check();

if (!ruleIs) {
warningMessage += `${rules[camelCaseRuleName](input, config).message()}\n`;
warningMessage += `${rules[ruleName](input, config).message()}\n`;
}
});

Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/.sgcrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"body": true,
"emoji": false,
"lowercaseTypes": false,
"initial-commit": {
"initialCommit": {
"isEnabled": true,
"emoji": ":tada:",
"message": "Initial commit"
Expand All @@ -16,8 +16,8 @@
}
],
"rules": {
"max-char": 72,
"min-char": 10,
"end-with-dot": false
"maxChar": 72,
"minChar": 10,
"endWithDot": false
}
}
8 changes: 4 additions & 4 deletions test/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ test('INIT COMMIT | check message without emoji', (t) => {
const config = getConfig();
const message = initMessage(config);

t.is(message, config['initial-commit'].message);
t.is(message, config.initialCommit.message);
});

test('INIT COMMIT | check message with emoji', (t) => {
Expand All @@ -146,14 +146,14 @@ test('INIT COMMIT | check message with emoji', (t) => {

const message = initMessage(config);

t.is(message, `${config['initial-commit'].emoji} ${config['initial-commit'].message}`);
t.is(message, `${config.initialCommit.emoji} ${config.initialCommit.message}`);
});

test('INIT QUESTION | check message without emoji', (t) => {
const config = getConfig();
const question = initQuestion(config);

t.is(question.message, `Confirm as first commit message: "${config['initial-commit'].message}"`);
t.is(question.message, `Confirm as first commit message: "${config.initialCommit.message}"`);
});

test('INIT QUESTION | check message with emoji', (t) => {
Expand All @@ -163,5 +163,5 @@ test('INIT QUESTION | check message with emoji', (t) => {

const question = initQuestion(config);

t.is(question.message, `Confirm as first commit message: "${config['initial-commit'].emoji} ${config['initial-commit'].message}"`);
t.is(question.message, `Confirm as first commit message: "${config.initialCommit.emoji} ${config.initialCommit.message}"`);
});
10 changes: 5 additions & 5 deletions test/rules/availableRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import rules from '../../lib/rules/availableRules';

test('rules endWithDot', (t) => {
const rulesObj = {
'end-with-dot': false,
endWithDot: false,
};
const endWithDot = rules.endWithDot('input with dot.', { rules: rulesObj }).check();
const endWithoutDot = rules.endWithDot('input with dot', { rules: rulesObj }).check();
Expand All @@ -15,7 +15,7 @@ test('rules endWithDot', (t) => {

test('rules minChar', (t) => {
const rulesObj = {
'min-char': 10,
minChar: 10,
};
const notMinChar = rules.minChar('less', { rules: rulesObj }).check();
const minChar = rules.minChar('this are more than 10 characters', { rules: rulesObj }).check();
Expand All @@ -26,7 +26,7 @@ test('rules minChar', (t) => {

test('-1 in minChar', (t) => {
const rulesObj = {
'min-char': -1,
minChar: -1,
};
const shortText = rules.minChar('n', { rules: rulesObj }).check();
const longText = rules.minChar('this are more than 10 characters', { rules: rulesObj }).check();
Expand All @@ -37,7 +37,7 @@ test('-1 in minChar', (t) => {

test('rules mxChar', (t) => {
const rulesObj = {
'max-char': 72,
maxChar: 72,
};
const moreThanMaxChar = rules.maxChar('this are more than 72 characters, believe me or not but the value moreThanMaxChar will be false ;-P', { rules: rulesObj }).check();
const lessThanMaxChar = rules.maxChar('this are less than 72 characters', { rules: rulesObj }).check();
Expand All @@ -48,7 +48,7 @@ test('rules mxChar', (t) => {

test('-1 in maxChar', (t) => {
const rulesObj = {
'max-char': -1,
maxChar: -1,
};
const longText = rules.maxChar('this are more than 72 characters, believe me or not but the value moreThanMaxChar will be true ;-P', { rules: rulesObj }).check();
const shortText = rules.maxChar('this are less than 72 characters', { rules: rulesObj }).check();
Expand Down
6 changes: 3 additions & 3 deletions test/rules/ruleWarningMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import ruleWaringMessages from '../../lib/rules/ruleWarningMessages';
test('ruleWarningMessages', (t) => {
const config = {
rules: {
'max-char': 72,
'min-char': 10,
'end-with-dot': false,
maxChar: 72,
minChar: 10,
endWithDot: false,
},
};
const messages = ruleWaringMessages('input.', config);
Expand Down