-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #772 from okonet/fixes
Fix a bunch of v10 issues
- Loading branch information
Showing
14 changed files
with
97 additions
and
94 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
"*.{js,json,md}": "prettier --write", | ||
"*.js": "npm run lint:base --fix", | ||
".*{rc, json}": "jsonlint --in-place" | ||
"*.js": "npm run lint:base -- --fix" | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,16 +121,16 @@ describe('runAll', () => { | |
|
||
it('Should commit entire staged file when no errors from linter', async () => { | ||
// Stage pretty file | ||
await appendFile('test.js', testJsFilePretty) | ||
await execGit(['add', 'test.js']) | ||
await appendFile('test file.js', testJsFilePretty) | ||
await execGit(['add', 'test file.js']) | ||
|
||
// Run lint-staged with `prettier --list-different` and commit pretty file | ||
await gitCommit({ config: { '*.js': 'prettier --list-different' } }) | ||
|
||
// Nothing is wrong, so a new commit is created | ||
expect(await execGit(['rev-list', '--count', 'HEAD'])).toEqual('2') | ||
expect(await execGit(['log', '-1', '--pretty=%B'])).toMatch('test') | ||
expect(await readFile('test.js')).toEqual(testJsFilePretty) | ||
expect(await readFile('test file.js')).toEqual(testJsFilePretty) | ||
}) | ||
|
||
it('Should commit entire staged file when no errors and linter modifies file', async () => { | ||
|
@@ -381,11 +381,9 @@ describe('runAll', () => { | |
).rejects.toThrowError() | ||
expect(console.printHistory()).toMatchInlineSnapshot(` | ||
" | ||
WARN ‼ Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index. | ||
ERROR | ||
× lint-staged failed due to a git error. | ||
Any lost modifications can be restored from a git stash: | ||
ERROR Any lost modifications can be restored from a git stash: | ||
> git stash list | ||
stash@{0}: On master: automatic lint-staged backup | ||
|
@@ -693,12 +691,15 @@ describe('runAll', () => { | |
|
||
// Run lint-staged with prettier --write to automatically fix the file | ||
// Since prettier reverts all changes, the commit should fail | ||
// use the old syntax with manual `git add` to provide a warning message | ||
await expect( | ||
gitCommit({ config: { '*.js': 'prettier --write' } }) | ||
gitCommit({ config: { '*.js': ['prettier --write', 'git add'] } }) | ||
).rejects.toThrowErrorMatchingInlineSnapshot(`"Something went wrong"`) | ||
|
||
expect(console.printHistory()).toMatchInlineSnapshot(` | ||
" | ||
WARN ‼ Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index. | ||
WARN | ||
‼ lint-staged prevented an empty git commit. | ||
Use the --allow-empty option to continue, or check your task configuration | ||
|
@@ -773,3 +774,28 @@ describe('runAll', () => { | |
expect(await readFile('test.js', submoduleDir)).toEqual(testJsFilePretty) | ||
}) | ||
}) | ||
|
||
describe('runAll', () => { | ||
it('Should throw when run on an empty git repo without an initial commit', async () => { | ||
const tmpDir = await createTempDir() | ||
const cwd = normalize(tmpDir) | ||
const logger = makeConsoleMock() | ||
|
||
await execGit('init', { cwd }) | ||
await execGit(['config', 'user.name', '"test"'], { cwd }) | ||
await execGit(['config', 'user.email', '"[email protected]"'], { cwd }) | ||
await appendFile('test.js', testJsFilePretty, cwd) | ||
await execGit(['add', 'test.js'], { cwd }) | ||
await expect( | ||
runAll({ config: { '*.js': 'prettier --list-different' }, cwd, quiet: true }, logger) | ||
).rejects.toThrowErrorMatchingInlineSnapshot(`"Something went wrong"`) | ||
expect(logger.printHistory()).toMatchInlineSnapshot(` | ||
" | ||
ERROR | ||
× lint-staged failed due to a git error. | ||
ERROR | ||
The initial commit is needed for lint-staged to work. | ||
Please use the --no-verify flag to skip running lint-staged." | ||
`) | ||
}) | ||
}) |
Oops, something went wrong.