diff --git a/@commitlint/load/fixtures/extends-with-local-plugins/commitlint.config.js b/@commitlint/load/fixtures/extends-with-local-plugins/commitlint.config.js new file mode 100644 index 0000000000..f0c973fd8c --- /dev/null +++ b/@commitlint/load/fixtures/extends-with-local-plugins/commitlint.config.js @@ -0,0 +1,3 @@ +module.exports = { + extends: ['./config-with-local-plugin'], +}; diff --git a/@commitlint/load/fixtures/extends-with-local-plugins/config-with-local-plugin/commitlint.config.js b/@commitlint/load/fixtures/extends-with-local-plugins/config-with-local-plugin/commitlint.config.js new file mode 100644 index 0000000000..2412bcd48a --- /dev/null +++ b/@commitlint/load/fixtures/extends-with-local-plugins/config-with-local-plugin/commitlint.config.js @@ -0,0 +1,21 @@ +module.exports = { + extends: [], + plugins: [{ + rules: { + 'hello-world-rule': ({ subject }) => { + const HELLO_WORLD = 'Hello World'; + return [ + subject.includes(HELLO_WORLD), + `Your subject should contain ${HELLO_WORLD} message` + ]; + }, + 'is-positive': ({ subject }) => { + const POSITIVE_EMOJI = ':)'; + return [ + subject.includes(POSITIVE_EMOJI), + `Your subject should contain ${POSITIVE_EMOJI} message` + ]; + } + } + }] +}; diff --git a/@commitlint/load/fixtures/extends-with-local-plugins/config-with-local-plugin/index.js b/@commitlint/load/fixtures/extends-with-local-plugins/config-with-local-plugin/index.js new file mode 100644 index 0000000000..fe16cc487b --- /dev/null +++ b/@commitlint/load/fixtures/extends-with-local-plugins/config-with-local-plugin/index.js @@ -0,0 +1 @@ +module.exports = require('./commitlint.config.js'); diff --git a/@commitlint/load/fixtures/extends-with-plugins/commitlint.config.js b/@commitlint/load/fixtures/extends-with-plugins/commitlint.config.js new file mode 100644 index 0000000000..cf6e89466d --- /dev/null +++ b/@commitlint/load/fixtures/extends-with-plugins/commitlint.config.js @@ -0,0 +1,3 @@ +module.exports = { + extends: ['./config-with-plugins'], +}; diff --git a/@commitlint/load/fixtures/extends-with-plugins/config-with-plugins/commitlint.config.js b/@commitlint/load/fixtures/extends-with-plugins/config-with-plugins/commitlint.config.js new file mode 100644 index 0000000000..1a285b7b1a --- /dev/null +++ b/@commitlint/load/fixtures/extends-with-plugins/config-with-plugins/commitlint.config.js @@ -0,0 +1,3 @@ +module.exports = { + plugins: ['example', '@scope/example'] +}; diff --git a/@commitlint/load/fixtures/extends-with-plugins/config-with-plugins/index.js b/@commitlint/load/fixtures/extends-with-plugins/config-with-plugins/index.js new file mode 100644 index 0000000000..fe16cc487b --- /dev/null +++ b/@commitlint/load/fixtures/extends-with-plugins/config-with-plugins/index.js @@ -0,0 +1 @@ +module.exports = require('./commitlint.config.js'); diff --git a/@commitlint/load/src/load.test.ts b/@commitlint/load/src/load.test.ts index 80e71147d9..1a3e4ba1f8 100644 --- a/@commitlint/load/src/load.test.ts +++ b/@commitlint/load/src/load.test.ts @@ -95,6 +95,32 @@ test('plugins should be loaded from config', async () => { }); }); +test('plugins should be loaded from shareable config', async () => { + const cwd = await gitBootstrap('fixtures/extends-with-plugins'); + const actual = await load({}, {cwd}); + + expect(actual.plugins).toMatchObject({ + example: plugin, + '@scope/example': scopedPlugin + }); +}); + +test('local plugins should be loaded from shareable configs', async () => { + const cwd = await gitBootstrap('fixtures/extends-with-local-plugins'); + const actual = await load({}, {cwd}); + + expect(actual.plugins).toEqual( + expect.objectContaining({ + local: { + rules: { + 'hello-world-rule': expect.any(Function), + 'is-positive': expect.any(Function) + } + } + }) + ); +}); + test('uses seed with parserPreset', async () => { const cwd = await gitBootstrap('fixtures/parser-preset'); const {parserPreset: actual} = await load( diff --git a/@commitlint/load/src/load.ts b/@commitlint/load/src/load.ts index 63fec9b908..c939e82192 100644 --- a/@commitlint/load/src/load.ts +++ b/@commitlint/load/src/load.ts @@ -3,6 +3,7 @@ import Path from 'path'; import merge from 'lodash/merge'; import mergeWith from 'lodash/mergeWith'; import pick from 'lodash/pick'; +import union from 'lodash/union'; import resolveFrom from 'resolve-from'; import executeRule from '@commitlint/execute-rule'; @@ -84,6 +85,11 @@ export default async function load( resolveFrom.silent(base, config.formatter) || config.formatter; } + // Read plugins from extends + if (Array.isArray(extended.plugins)) { + config.plugins = union(config.plugins, extended.plugins || []); + } + // resolve plugins if (Array.isArray(config.plugins)) { config.plugins.forEach(plugin => {