Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: fix YAML config loading
  • Loading branch information
iiroj committed Nov 22, 2021
1 parent f20ddf9 commit 0082ec2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/loadConfig.js
Expand Up @@ -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
Expand All @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions test/__mocks__/my-config.yml
@@ -0,0 +1 @@
'*': 'mytask'
21 changes: 21 additions & 0 deletions test/index.spec.js
Expand Up @@ -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)

Expand Down

0 comments on commit 0082ec2

Please sign in to comment.