Skip to content

Commit

Permalink
fix(precise-formatters/prettier): Ensure filepath is set in PrettierO…
Browse files Browse the repository at this point in the history
…ptions (#10)
  • Loading branch information
JamesHenry committed Feb 16, 2018
1 parent a6fcd39 commit 5184dcf
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/precise-formatters/prettier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ export const preciseFormatterPrettier: PreciseFormatter<PrettierOptions> = {
* modified file path.
*/
resolveConfig(modifiedFilePath: string): PrettierOptions | null {
return resolveConfig.sync(modifiedFilePath, {
useCache: false,
});
return {
...resolveConfig.sync(modifiedFilePath, {
useCache: false,
}),
filepath: modifiedFilePath,
};
},
/**
* Return true if the whole file has already been formatted appropriately based on
Expand Down
13 changes: 13 additions & 0 deletions test/__snapshots__/git-utils.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`git-utils getDiffForFile() brand-new-json-file 1`] = `
"diff --git a/brand-new-json-file.json b/brand-new-json-file.json
new file mode 100644
index 0000000..f663bcc
--- /dev/null
+++ b/brand-new-json-file.json
@@ -0,0 +1,3 @@
+{
+ \\"foo\\": true
+}
\\\\ No newline at end of file"
`;

exports[`git-utils getDiffForFile() brand-new-jsx-file 1`] = `
"diff --git a/brand-new-jsx-file.jsx b/brand-new-jsx-file.jsx
new file mode 100644
Expand Down
7 changes: 7 additions & 0 deletions test/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`precise-commits main() brand-new-json-file 1`] = `
"{
\\"foo\\": true
}
"
`;

exports[`precise-commits main() brand-new-jsx-file 1`] = `
"function HelloWorld({
greeting = 'hello',
Expand Down
14 changes: 14 additions & 0 deletions test/__snapshots__/precise-formatter-prettier.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`preciseFormatterPrettier resolveConfig() brand-new-json-file 1`] = `
Object {
"filepath": "./test/fixtures/brand-new-json-file/initial.json",
"semi": true,
"singleQuote": true,
"trailingComma": "all",
}
`;

exports[`preciseFormatterPrettier resolveConfig() brand-new-jsx-file 1`] = `
Object {
"filepath": "./test/fixtures/brand-new-jsx-file/initial.jsx",
"semi": true,
"singleQuote": true,
"trailingComma": "all",
Expand All @@ -10,6 +20,7 @@ Object {

exports[`preciseFormatterPrettier resolveConfig() empty-javascript-file 1`] = `
Object {
"filepath": "./test/fixtures/empty-javascript-file/initial.js",
"semi": true,
"singleQuote": true,
"trailingComma": "all",
Expand All @@ -18,6 +29,7 @@ Object {

exports[`preciseFormatterPrettier resolveConfig() formatting-would-affect-total-line-count 1`] = `
Object {
"filepath": "./test/fixtures/formatting-would-affect-total-line-count/initial.js",
"semi": true,
"singleQuote": true,
"trailingComma": "all",
Expand All @@ -26,6 +38,7 @@ Object {

exports[`preciseFormatterPrettier resolveConfig() multiple-updated-lines-javascript-file 1`] = `
Object {
"filepath": "./test/fixtures/multiple-updated-lines-javascript-file/initial.js",
"semi": true,
"singleQuote": false,
"trailingComma": "none",
Expand All @@ -34,6 +47,7 @@ Object {

exports[`preciseFormatterPrettier resolveConfig() single-updated-line-typescript 1`] = `
Object {
"filepath": "./test/fixtures/single-updated-line-typescript/initial.ts",
"parser": "typescript",
"semi": true,
"singleQuote": true,
Expand Down
21 changes: 21 additions & 0 deletions test/__snapshots__/utils.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`utils calculateCharacterRangesFromLineChanges() brand-new-json-file 1`] = `
Array [
Object {
"rangeEnd": 19,
"rangeStart": 0,
},
]
`;

exports[`utils calculateCharacterRangesFromLineChanges() brand-new-jsx-file 1`] = `
Array [
Object {
Expand Down Expand Up @@ -53,6 +62,18 @@ Array [
]
`;

exports[`utils extractLineChangeData() brand-new-json-file 1`] = `
Object {
"additions": Array [
Object {
"noOfLines": 3,
"start": 1,
},
],
"removals": Array [],
}
`;

exports[`utils extractLineChangeData() brand-new-jsx-file 1`] = `
Object {
"additions": Array [
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/brand-new-json-file/staged.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"foo": true
}

0 comments on commit 5184dcf

Please sign in to comment.