Skip to content

Commit

Permalink
feat: add .editorconfig support (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
loicplaire authored and gregberge committed Jul 8, 2018
1 parent 261594a commit 968fd82
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/core/src/plugins/prettier.js
Expand Up @@ -4,7 +4,9 @@ import merge from 'lodash/merge'
export default async (code, config = {}, state = {}) => {
if (!config.prettier) return code
const filePath = state.filePath || process.cwd()
const prettierRcConfig = await prettier.resolveConfig(filePath)
const prettierRcConfig = await prettier.resolveConfig(filePath, {
editorconfig: true,
})
return prettier.format(
code,
merge({ parser: 'babylon' }, prettierRcConfig, config.prettierConfig || {}),
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/plugins/prettier.test.js
Expand Up @@ -22,4 +22,18 @@ describe('prettier', () => {
)
expect(result).toBe('const foo = <div />;\n')
})

it('should resolve the prettier config with the editorconfig option', async () => {
jest.resetModules()
jest.doMock('prettier')
/* eslint-disable global-require */
const prettierPlugin = require('./prettier').default
const { resolveConfig } = require('prettier')
/* eslint-enable global-require */

await prettierPlugin(`const foo = <div></div>`, { prettier: true })
expect(resolveConfig).toHaveBeenCalledWith(expect.any(String), {
editorconfig: true,
})
})
})

0 comments on commit 968fd82

Please sign in to comment.