-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support debug flag on format and lint (#367)
This can clue you in on which files ESLint and Prettier are formatting and linting, which can in turn inform your `.eslintignore` and `.prettierignore` files.
- Loading branch information
Showing
8 changed files
with
249 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'skuba': minor | ||
--- | ||
|
||
**format, lint:** Support `--debug` flag |
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,100 @@ | ||
import execa from 'execa'; | ||
|
||
import { hasStringProp } from '../utils/validation'; | ||
|
||
import { format } from './format'; | ||
|
||
jest.mock('execa'); | ||
|
||
const execaCalls = () => | ||
((execa as unknown) as jest.Mock<typeof execa>).mock.calls | ||
.flat(2) | ||
.map((val) => | ||
Array.isArray(val) || !hasStringProp(val, 'localDir') | ||
? val | ||
: { ...val, localDir: 'REDACTED' }, | ||
); | ||
|
||
describe('format', () => { | ||
const consoleLog = jest.spyOn(global.console, 'log').mockReturnValue(); | ||
|
||
const consoleLogCalls = () => consoleLog.mock.calls.flat(2); | ||
|
||
afterEach(jest.clearAllMocks); | ||
|
||
const oldProcessArgv = process.argv; | ||
afterAll(() => (process.argv = oldProcessArgv)); | ||
|
||
it('handles no flags', async () => { | ||
process.argv = []; | ||
|
||
await expect(format()).resolves.toBeUndefined(); | ||
|
||
expect(execaCalls()).toMatchInlineSnapshot(` | ||
Array [ | ||
"eslint", | ||
"--ext=js,ts,tsx", | ||
"--fix", | ||
".", | ||
Object { | ||
"localDir": "REDACTED", | ||
"preferLocal": true, | ||
"stdio": "inherit", | ||
}, | ||
"prettier", | ||
"--write", | ||
".", | ||
Object { | ||
"localDir": "REDACTED", | ||
"preferLocal": true, | ||
"stdio": "inherit", | ||
}, | ||
] | ||
`); | ||
|
||
expect(consoleLogCalls()).toMatchInlineSnapshot(` | ||
Array [ | ||
"✔ ESLint", | ||
"✔ Prettier", | ||
] | ||
`); | ||
}); | ||
|
||
it('handles debug flag', async () => { | ||
process.argv = ['something', '--dEbUg', 'else']; | ||
|
||
await expect(format()).resolves.toBeUndefined(); | ||
|
||
expect(execaCalls()).toMatchInlineSnapshot(` | ||
Array [ | ||
"eslint", | ||
"--debug", | ||
"--ext=js,ts,tsx", | ||
"--fix", | ||
".", | ||
Object { | ||
"localDir": "REDACTED", | ||
"preferLocal": true, | ||
"stdio": "inherit", | ||
}, | ||
"prettier", | ||
"--loglevel", | ||
"debug", | ||
"--write", | ||
".", | ||
Object { | ||
"localDir": "REDACTED", | ||
"preferLocal": true, | ||
"stdio": "inherit", | ||
}, | ||
] | ||
`); | ||
|
||
expect(consoleLogCalls()).toMatchInlineSnapshot(` | ||
Array [ | ||
"✔ ESLint", | ||
"✔ Prettier", | ||
] | ||
`); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,10 +1,24 @@ | ||
import { hasDebugFlag } from '../utils/args'; | ||
import { exec } from '../utils/exec'; | ||
import { log } from '../utils/logging'; | ||
|
||
export const format = async () => { | ||
await exec('eslint', '--ext=js,ts,tsx', '--fix', '.'); | ||
const debug = hasDebugFlag(); | ||
|
||
await exec( | ||
'eslint', | ||
...(debug ? ['--debug'] : []), | ||
'--ext=js,ts,tsx', | ||
'--fix', | ||
'.', | ||
); | ||
log.ok('✔ ESLint'); | ||
|
||
await exec('prettier', '--write', '.'); | ||
await exec( | ||
'prettier', | ||
...(debug ? ['--loglevel', 'debug'] : []), | ||
'--write', | ||
'.', | ||
); | ||
log.ok('✔ Prettier'); | ||
}; |
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
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