-
-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ability to use function as config (#913)
* feat: add ability to use function as config * fix: test * test: add specific test for config formatter * docs: clarify function based configuration option * Apply suggestions for README.md from code review Co-authored-by: Iiro Jäppinen <iiro@jappinen.fi> Co-authored-by: Iiro Jäppinen <iiro@jappinen.fi>
- Loading branch information
1 parent
643038d
commit 67a4d06
Showing
6 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = function formatConfig(config) { | ||
if (typeof config === 'function') { | ||
return { '*': config } | ||
} | ||
|
||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import formatConfig from '../lib/formatConfig' | ||
|
||
describe('formatConfig', () => { | ||
it('Object config should return as is', () => { | ||
const simpleConfig = { | ||
'*.js': ['eslint --fix', 'git add'], | ||
} | ||
expect(formatConfig(simpleConfig)).toEqual(simpleConfig) | ||
}) | ||
|
||
it('Function config should be converted to object', () => { | ||
const functionConfig = (stagedFiles) => [`eslint --fix ${stagedFiles}', 'git add`] | ||
expect(formatConfig(functionConfig)).toEqual({ | ||
'*': functionConfig, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters