Skip to content

Commit 5184dcf

Browse files
authored
fix(precise-formatters/prettier): Ensure filepath is set in PrettierOptions (#10)
1 parent a6fcd39 commit 5184dcf

File tree

6 files changed

+64
-3
lines changed

6 files changed

+64
-3
lines changed

src/precise-formatters/prettier.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ export const preciseFormatterPrettier: PreciseFormatter<PrettierOptions> = {
2929
* modified file path.
3030
*/
3131
resolveConfig(modifiedFilePath: string): PrettierOptions | null {
32-
return resolveConfig.sync(modifiedFilePath, {
33-
useCache: false,
34-
});
32+
return {
33+
...resolveConfig.sync(modifiedFilePath, {
34+
useCache: false,
35+
}),
36+
filepath: modifiedFilePath,
37+
};
3538
},
3639
/**
3740
* Return true if the whole file has already been formatted appropriately based on

test/__snapshots__/git-utils.spec.ts.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`git-utils getDiffForFile() brand-new-json-file 1`] = `
4+
"diff --git a/brand-new-json-file.json b/brand-new-json-file.json
5+
new file mode 100644
6+
index 0000000..f663bcc
7+
--- /dev/null
8+
+++ b/brand-new-json-file.json
9+
@@ -0,0 +1,3 @@
10+
+{
11+
+ \\"foo\\": true
12+
+}
13+
\\\\ No newline at end of file"
14+
`;
15+
316
exports[`git-utils getDiffForFile() brand-new-jsx-file 1`] = `
417
"diff --git a/brand-new-jsx-file.jsx b/brand-new-jsx-file.jsx
518
new file mode 100644

test/__snapshots__/index.spec.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`precise-commits main() brand-new-json-file 1`] = `
4+
"{
5+
\\"foo\\": true
6+
}
7+
"
8+
`;
9+
310
exports[`precise-commits main() brand-new-jsx-file 1`] = `
411
"function HelloWorld({
512
greeting = 'hello',

test/__snapshots__/precise-formatter-prettier.spec.ts.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`preciseFormatterPrettier resolveConfig() brand-new-json-file 1`] = `
4+
Object {
5+
"filepath": "./test/fixtures/brand-new-json-file/initial.json",
6+
"semi": true,
7+
"singleQuote": true,
8+
"trailingComma": "all",
9+
}
10+
`;
11+
312
exports[`preciseFormatterPrettier resolveConfig() brand-new-jsx-file 1`] = `
413
Object {
14+
"filepath": "./test/fixtures/brand-new-jsx-file/initial.jsx",
515
"semi": true,
616
"singleQuote": true,
717
"trailingComma": "all",
@@ -10,6 +20,7 @@ Object {
1020

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

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

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

3548
exports[`preciseFormatterPrettier resolveConfig() single-updated-line-typescript 1`] = `
3649
Object {
50+
"filepath": "./test/fixtures/single-updated-line-typescript/initial.ts",
3751
"parser": "typescript",
3852
"semi": true,
3953
"singleQuote": true,

test/__snapshots__/utils.spec.ts.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`utils calculateCharacterRangesFromLineChanges() brand-new-json-file 1`] = `
4+
Array [
5+
Object {
6+
"rangeEnd": 19,
7+
"rangeStart": 0,
8+
},
9+
]
10+
`;
11+
312
exports[`utils calculateCharacterRangesFromLineChanges() brand-new-jsx-file 1`] = `
413
Array [
514
Object {
@@ -53,6 +62,18 @@ Array [
5362
]
5463
`;
5564

65+
exports[`utils extractLineChangeData() brand-new-json-file 1`] = `
66+
Object {
67+
"additions": Array [
68+
Object {
69+
"noOfLines": 3,
70+
"start": 1,
71+
},
72+
],
73+
"removals": Array [],
74+
}
75+
`;
76+
5677
exports[`utils extractLineChangeData() brand-new-jsx-file 1`] = `
5778
Object {
5879
"additions": Array [
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"foo": true
3+
}

0 commit comments

Comments
 (0)