Skip to content

Commit ba90e8e

Browse files
byCedricescapedcat
authored andcommitted
feat(resolve-extends): accept short scoped package names in extends (#597)
1 parent 3e0d824 commit ba90e8e

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

@commitlint/resolve-extends/src/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ function getId(raw = '', prefix = '') {
7272
const first = raw.charAt(0);
7373
const scoped = first === '@';
7474
const relative = first === '.';
75-
return scoped || relative ? raw : [prefix, raw].filter(String).join('-');
75+
76+
if (scoped) {
77+
return raw.includes('/') ? raw : [raw, prefix].filter(String).join('/');
78+
}
79+
80+
return relative ? raw : [prefix, raw].filter(String).join('-');
7681
}
7782

7883
function resolveConfig(raw, context = {}) {

@commitlint/resolve-extends/src/index.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ test('ignores prefix for scoped extends', t => {
9696
});
9797
});
9898

99+
test('adds prefix as suffix for scopes only', t => {
100+
const input = {extends: ['@scope']};
101+
102+
resolveExtends(input, {
103+
prefix: 'prefix',
104+
resolve: id,
105+
require(id) {
106+
t.is(id, '@scope/prefix');
107+
}
108+
});
109+
});
110+
99111
test('ignores prefix for relative extends', t => {
100112
const input = {extends: ['./extender']};
101113

docs/concepts-shareable-config.md

+24-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,24 @@ The rules found in `commitlint-config-example` are merged with the rules in `com
2020

2121
This works recursively, enabling shareable configuration to extend on an indefinite chain of other shareable configurations.
2222

23-
## Special cases
23+
## Relative config
2424

25-
Scoped npm packages are not prefixed.
25+
You can also load local configuration by using a relative path to the file.
26+
27+
> This must always start with a `.` (dot).
28+
29+
```js
30+
// commitlint.config.js
31+
module.exports = {
32+
extends: ['./example'] // => ./example.js
33+
}
34+
```
35+
36+
## Scoped packages
37+
38+
When using scoped packages you have two options.
39+
40+
You can provide the full path of the package like:
2641

2742
```js
2843
// commitlint.config.js
@@ -31,11 +46,15 @@ module.exports = {
3146
};
3247
```
3348

34-
The same is true for relative imports
49+
Or just the scope/owner of the package.
50+
51+
> Just like "normal" extends listed above, this will add `<scope>/commitlint-config`.
3552
3653
```js
3754
// commitlint.config.js
3855
module.exports = {
39-
extends: ['./example'] // => ./example.js
40-
}
56+
extends: ['@coolcompany'] // => coolcompany/commitlint-config
57+
};
4158
```
59+
60+
If you don't use the exact `<scope>/commitlint-config` pattern, you have to provide the full name of the package.

0 commit comments

Comments
 (0)