Skip to content

Commit cd322a9

Browse files
committed
Feat: remove inherit, change readme defaults
1 parent 31e6578 commit cd322a9

File tree

10 files changed

+48
-114
lines changed

10 files changed

+48
-114
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ coverage
88

99
# macOS
1010
.DS_STORE
11+
12+
# IDE / Editors
13+
.vscode

.sgcrc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
2-
"questions": {
3-
"scope": false,
4-
"body": true
5-
},
2+
"scope": false,
3+
"body": true,
64
"emoji": false,
75
"types": [
86
{

README.md

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,39 @@ $ sgc
4141
You can even create a global config. Just go to your users home and create a `.sgcrc`. The global config will be triggered if no project configurations are present.
4242

4343
**Options:**
44-
- [questions](#questions)
44+
- [body](#body)
45+
- [scope](#scope)
4546
- [emoji](#emoji)
4647
- [types](#types)
4748
- [rules](#rules)
48-
- [inherit](#inherit)
4949

50-
### questions
50+
### body
5151

52-
**Type:** `object`
52+
**Type:** `boolean`
5353

54-
**Options:**
55-
- `scope` Asks for the scope in parentheses of the commit. Default: `false`
56-
- `body` Asks if more info (body) should be added. Default: `true`
54+
**Default**: `true`
5755

58-
An object with predefined settings, what should be asked.
56+
Asks if more info (body) should be added. This will open your default editor.
5957

6058
Example:
61-
```js
59+
```json
6260
{
63-
"questions": {
64-
"scope": true
65-
}
61+
"body": false
62+
}
63+
```
64+
65+
### scope
66+
67+
**Type:** `boolean`
68+
69+
**Default:** `false`
70+
71+
Asks for the scope in parentheses of the commit.
72+
73+
Example:
74+
```json
75+
{
76+
"scope": true
6677
}
6778
```
6879

@@ -83,7 +94,8 @@ Example:
8394

8495
### types
8596

86-
> Types will define your git commits.
97+
> Types will define your git commits. If `types` is not set in your own `.sgcrc`, the `types` of the global [.sgcrc](.sgcrc)
98+
8799

88100
**Keys**
89101

@@ -135,15 +147,15 @@ Available rules:
135147

136148
**Type:** `number`
137149

138-
**Default:** `undefined`
150+
**Default:** `72`
139151

140-
If a number is set, it will not allow to commit messages **more than** the given number
152+
If a number is set, it will not allow to commit messages **more than** the given number. If it is set to `false` the rule is deactivated
141153

142154
Example:
143155
```json
144156
{
145157
"rules": {
146-
"max-char": 10
158+
"max-char": false
147159
}
148160
}
149161
```
@@ -152,15 +164,15 @@ Example:
152164

153165
**Type:** `number`
154166

155-
**Default:** `undefined`
167+
**Default:** `10`
156168

157-
If a number is set, it will not allow to commit messages **less than** the given number
169+
If a number is set, it will not allow to commit messages **less than** the given number. If it is set to `false` the rule is deactivated
158170

159171
Example:
160172
```json
161173
{
162174
"rules": {
163-
"min-char": 10
175+
"min-char": false
164176
}
165177
}
166178
```
@@ -181,28 +193,3 @@ Example:
181193
}
182194
}
183195
```
184-
185-
### inherit
186-
187-
**Type:** `boolean | array`
188-
189-
**Default:** `false`
190-
191-
This will inherit every object entry which is given in the array. If this is set to true everything is inherited. The own configuration won't get overwritten.
192-
193-
Example:
194-
```js
195-
// following set "emoji" to true, and will inherit everything except "emoji" from the defaults.
196-
{
197-
"emoji": true,
198-
"inherit": true
199-
}
200-
201-
// following has "emoji" to true and just types are "types" from the defaults.
202-
{
203-
"emoji": true,
204-
"inherit": [
205-
"types"
206-
]
207-
}
208-
```

lib/getConfig.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,20 @@ const getConfig = (altPath) => {
2424
// 3. default config
2525
// - 1. from ../.sgcrc
2626
// - 2. test case ../.sgcrc is renamed to ../.sgcrc_default
27-
let config = configObject || packageConfig || globalConfig || sgcrcDefault;
28-
29-
config.inherit = config.inherit === undefined ? {} : config.inherit;
27+
const config = configObject || packageConfig || globalConfig || sgcrcDefault;
3028

3129
// set defaults which are necessary
32-
let configDefaults = {};
33-
34-
configDefaults.questions = sgcrcDefault.questions;
30+
const tempConfig = merge({}, sgcrcDefault, config);
3531

36-
// inherit everything
37-
if (config.inherit === true) {
38-
configDefaults = sgcrcDefault;
32+
// do not merge types
33+
// so return them to their set default
34+
if (config.types) {
35+
tempConfig.types = config.types;
3936
}
4037

41-
if (Object.prototype.toString.call(config.inherit) === '[object Array]') {
42-
config.inherit.forEach((element) => {
43-
if (!config[element] && sgcrcDefault[element] !== undefined) {
44-
config[element] = sgcrcDefault[element];
45-
}
46-
});
47-
}
48-
49-
config = merge({}, configDefaults, config);
50-
5138
// next will remove "inherit" from the config
5239
// eslint-disable-next-line
53-
const { inherit, ...copiedConfig } = config;
40+
const { inherit, ...copiedConfig } = tempConfig;
5441

5542
return copiedConfig;
5643
};

lib/questions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const questions = (config) => {
3232
type: 'input',
3333
name: 'scope',
3434
message: 'Enter your scope (no whitespaces allowed):',
35-
when: () => config.questions.scope,
35+
when: () => config.scope,
3636
validate: input => (input.match(/\s/) !== null ? 'No whitespaces allowed' : true),
3737
filter: input => (input ? `(${input})` : input),
3838
},
@@ -50,7 +50,7 @@ const questions = (config) => {
5050
type: 'confirm',
5151
name: 'body',
5252
message: 'Do you want to add a body?',
53-
when: () => config.questions.body,
53+
when: () => config.body,
5454
default: false,
5555
},
5656
{

test/fixtures/.sgcrc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
2-
"questions": {
3-
"scope": false,
4-
"body": true
5-
},
2+
"scope": false,
3+
"body": true,
64
"emoji": false,
75
"types": [
86
{

test/fixtures/.sgcrc_inherit

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/fixtures/.sgcrc_inherit_all

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/getConfig.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ test('read config from a specific path', (t) => {
4444
test('read config from a .sgcrc_default', (t) => {
4545
const globalConfig = json.readToObjSync(path.join(cwd, '.sgcrc_default'));
4646

47-
globalConfig.questions = {
48-
scope: false,
49-
body: true,
50-
};
51-
5247
t.deepEqual(getConfig(), globalConfig);
5348
});
5449

test/questions.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import os from 'os';
22
import test from 'ava';
33
import path from 'path';
44
import fs from 'fs-extra';
5-
import json from 'json-extra';
6-
import merge from 'lodash.merge';
75

86
import getConfig from '../lib/getConfig';
97
import questions, { choices } from '../lib/questions';
@@ -47,27 +45,6 @@ test('choices are rendered without emoji', (t) => {
4745
t.deepEqual(choicesList, withoutEmoji);
4846
});
4947

50-
test('choices with inherit mode | all', (t) => {
51-
const sgc = getConfig(path.join(fixtures, '.sgcrc_inherit_all'));
52-
const sgcrc = json.readToObjSync(path.join(cwd, '.sgcrc_default'));
53-
54-
t.deepEqual(sgc, merge({}, sgcrc, sgc));
55-
});
56-
57-
test('choices with inherit mode | some', (t) => {
58-
const sgc = getConfig(path.join(fixtures, '.sgcrc_inherit'));
59-
const sgcrc = json.readToObjSync(path.join(cwd, '.sgcrc_default'));
60-
61-
const ownConfig = {
62-
emoji: true,
63-
};
64-
65-
ownConfig.rules = sgcrc.rules;
66-
ownConfig.questions = sgcrc.questions;
67-
68-
t.deepEqual(sgc, ownConfig);
69-
});
70-
7148
test('choices are rendered with emoji (default)', (t) => {
7249
const sgc = getConfig(path.join(fixtures, '.sgcrc'));
7350

@@ -129,5 +106,5 @@ test('CONFIRM EDITOR | check if it shows if it has to', (t) => {
129106
const config = getConfig();
130107
const questionsList = questions(config);
131108

132-
t.is(questionsList[3].when(), config.questions.body);
109+
t.is(questionsList[3].when(), config.body);
133110
});

0 commit comments

Comments
 (0)