-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add opt-out capability for the auto-formatting (#6)
- Loading branch information
Kent C. Dodds
authored
Oct 12, 2017
1 parent
9f10982
commit 848c7aa
Showing
5 changed files
with
76 additions
and
16 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,41 @@ | ||
import * as utilsMock from '../../utils' | ||
|
||
jest.mock('../../utils', () => ({ | ||
...require.requireActual('../../utils'), | ||
isOptedOut: jest.fn((key, t) => t), | ||
})) | ||
|
||
afterEach(() => { | ||
jest.resetModules() | ||
}) | ||
|
||
test('includes format and git add when not opted out', () => { | ||
utilsMock.isOptedOut.mockImplementation((key, t, f) => f) | ||
const config = require('../lintstagedrc') | ||
const jsLinter = getJsLinter(config.linters) | ||
expect(hasFormat(jsLinter)).toBe(true) | ||
expect(hasGitAdd(jsLinter)).toBe(true) | ||
}) | ||
|
||
test('does not include format and git add when opted out', () => { | ||
utilsMock.isOptedOut.mockImplementation((key, t) => t) | ||
const config = require('../lintstagedrc') | ||
const jsLinter = getJsLinter(config.linters) | ||
expect(hasFormat(jsLinter)).toBe(false) | ||
expect(hasGitAdd(jsLinter)).toBe(false) | ||
}) | ||
|
||
function hasFormat(linter) { | ||
return linter.some(l => l.includes('format')) | ||
} | ||
|
||
function hasGitAdd(linter) { | ||
return linter.includes('git add') | ||
} | ||
|
||
function getJsLinter(linters) { | ||
const key = Object.keys(linters).find( | ||
k => k.includes('**') && k.includes('js'), | ||
) | ||
return linters[key] | ||
} |
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