Skip to content

Commit 0082ec2

Browse files
committed
fix: fix YAML config loading
1 parent f20ddf9 commit 0082ec2

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

lib/loadConfig.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export const dynamicImport = (path) =>
3232

3333
const jsonParse = (path, content) => JSON.parse(content)
3434

35+
const yamlParse = (path, content) => YAML.parse(content)
36+
3537
/**
3638
* `lilconfig` doesn't support yaml files by default,
3739
* so we add custom loaders for those. Files without
@@ -43,9 +45,9 @@ const loaders = {
4345
'.json': jsonParse,
4446
'.mjs': dynamicImport,
4547
'.cjs': dynamicImport,
46-
'.yaml': YAML.parse,
47-
'.yml': YAML.parse,
48-
noExt: YAML.parse,
48+
'.yaml': yamlParse,
49+
'.yml': yamlParse,
50+
noExt: yamlParse,
4951
}
5052

5153
const resolveConfig = (configPath) => {

test/__mocks__/my-config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'*': 'mytask'

test/index.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,27 @@ describe('lintStaged', () => {
157157
`)
158158
})
159159

160+
it('should load YAML config file', async () => {
161+
expect.assertions(1)
162+
163+
await lintStaged(
164+
{
165+
configPath: path.join(__dirname, '__mocks__', 'my-config.yml'),
166+
debug: true,
167+
quiet: true,
168+
},
169+
logger
170+
)
171+
172+
expect(logger.printHistory()).toMatchInlineSnapshot(`
173+
"
174+
LOG Running lint-staged with the following config:
175+
LOG {
176+
'*': 'mytask'
177+
}"
178+
`)
179+
})
180+
160181
it('should load CommonJS config file from absolute path', async () => {
161182
expect.assertions(1)
162183

0 commit comments

Comments
 (0)