diff --git a/lib/loadConfig.js b/lib/loadConfig.js index 8c9e02f71..af2286235 100644 --- a/lib/loadConfig.js +++ b/lib/loadConfig.js @@ -32,6 +32,8 @@ export const dynamicImport = (path) => const jsonParse = (path, content) => JSON.parse(content) +const yamlParse = (path, content) => YAML.parse(content) + /** * `lilconfig` doesn't support yaml files by default, * so we add custom loaders for those. Files without @@ -43,9 +45,9 @@ const loaders = { '.json': jsonParse, '.mjs': dynamicImport, '.cjs': dynamicImport, - '.yaml': YAML.parse, - '.yml': YAML.parse, - noExt: YAML.parse, + '.yaml': yamlParse, + '.yml': yamlParse, + noExt: yamlParse, } const resolveConfig = (configPath) => { diff --git a/test/__mocks__/my-config.yml b/test/__mocks__/my-config.yml new file mode 100644 index 000000000..85079e9fb --- /dev/null +++ b/test/__mocks__/my-config.yml @@ -0,0 +1 @@ +'*': 'mytask' diff --git a/test/index.spec.js b/test/index.spec.js index a5fbb3ed3..5c1ed8ea2 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -157,6 +157,27 @@ describe('lintStaged', () => { `) }) + it('should load YAML config file', async () => { + expect.assertions(1) + + await lintStaged( + { + configPath: path.join(__dirname, '__mocks__', 'my-config.yml'), + debug: true, + quiet: true, + }, + logger + ) + + expect(logger.printHistory()).toMatchInlineSnapshot(` + " + LOG Running lint-staged with the following config: + LOG { + '*': 'mytask' + }" + `) + }) + it('should load CommonJS config file from absolute path', async () => { expect.assertions(1)