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

feat(resolve-extends): accept short scoped package names in extends #597

Merged
merged 1 commit into from
Mar 21, 2019
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
7 changes: 6 additions & 1 deletion @commitlint/resolve-extends/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ function getId(raw = '', prefix = '') {
const first = raw.charAt(0);
const scoped = first === '@';
const relative = first === '.';
return scoped || relative ? raw : [prefix, raw].filter(String).join('-');

if (scoped) {
return raw.includes('/') ? raw : [raw, prefix].filter(String).join('/');
}

return relative ? raw : [prefix, raw].filter(String).join('-');
}

function resolveConfig(raw, context = {}) {
Expand Down
12 changes: 12 additions & 0 deletions @commitlint/resolve-extends/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ test('ignores prefix for scoped extends', t => {
});
});

test('adds prefix as suffix for scopes only', t => {
const input = {extends: ['@scope']};

resolveExtends(input, {
prefix: 'prefix',
resolve: id,
require(id) {
t.is(id, '@scope/prefix');
}
});
});

test('ignores prefix for relative extends', t => {
const input = {extends: ['./extender']};

Expand Down
29 changes: 24 additions & 5 deletions docs/concepts-shareable-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,24 @@ The rules found in `commitlint-config-example` are merged with the rules in `com

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

## Special cases
## Relative config

Scoped npm packages are not prefixed.
You can also load local configuration by using a relative path to the file.

> This must always start with a `.` (dot).

```js
// commitlint.config.js
module.exports = {
extends: ['./example'] // => ./example.js
}
```

## Scoped packages

When using scoped packages you have two options.

You can provide the full path of the package like:

```js
// commitlint.config.js
Expand All @@ -31,11 +46,15 @@ module.exports = {
};
```

The same is true for relative imports
Or just the scope/owner of the package.

> Just like "normal" extends listed above, this will add `<scope>/commitlint-config`.

```js
// commitlint.config.js
module.exports = {
extends: ['./example'] // => ./example.js
}
extends: ['@coolcompany'] // => coolcompany/commitlint-config
};
```

If you don't use the exact `<scope>/commitlint-config` pattern, you have to provide the full name of the package.