Skip to content

Commit 6e2a720

Browse files
committed
fix(prettier): fix unspecified parser warning when using prettier 2.x
1 parent 4338d22 commit 6e2a720

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/modified-file.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class ModifiedFile {
9393
*/
9494
hasValidFormattingForCharacterRanges(): boolean {
9595
return this.selectedFormatter.checkFormattingOfRanges(
96+
this.fullPath,
9697
this.fileContents,
9798
this.formatterConfig,
9899
this.modifiedCharacterRanges
@@ -104,6 +105,7 @@ export class ModifiedFile {
104105
*/
105106
formatCharacterRangesWithinContents(): void {
106107
this.formattedFileContents = this.selectedFormatter.formatRanges(
108+
this.fullPath,
107109
this.fileContents,
108110
this.formatterConfig,
109111
this.modifiedCharacterRanges

src/precise-formatter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface PreciseFormatter<FormatterConfig> {
1818
* and character range info.
1919
*/
2020
checkFormattingOfRanges(
21+
filePath: string,
2122
fileContents: string,
2223
config: FormatterConfig | null,
2324
characterRanges: CharacterRange[]
@@ -27,6 +28,7 @@ export interface PreciseFormatter<FormatterConfig> {
2728
* character range info.
2829
*/
2930
formatRanges(
31+
filePath: string,
3032
fileContents: string,
3133
config: FormatterConfig | null,
3234
characterRanges: CharacterRange[]

src/precise-formatters/prettier.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const preciseFormatterPrettier: PreciseFormatter<PrettierOptions> = {
3939
* already formatted appropriately based on the given prettier config.
4040
*/
4141
checkFormattingOfRanges(
42+
filePath: string,
4243
fileContents: string,
4344
config: PrettierOptions | null,
4445
characterRanges: CharacterRange[]
@@ -47,10 +48,9 @@ export const preciseFormatterPrettier: PreciseFormatter<PrettierOptions> = {
4748
return characterRanges.every(characterRange => {
4849
return check(formattedContents, {
4950
...config,
50-
...{
51-
rangeStart: characterRange.rangeStart,
52-
rangeEnd: characterRange.rangeEnd
53-
}
51+
filepath: filePath,
52+
rangeStart: characterRange.rangeStart,
53+
rangeEnd: characterRange.rangeEnd
5454
});
5555
});
5656
},
@@ -60,6 +60,7 @@ export const preciseFormatterPrettier: PreciseFormatter<PrettierOptions> = {
6060
* of the Myer's diff algorithm.
6161
*/
6262
formatRanges(
63+
filePath: string,
6364
fileContents: string,
6465
config: PrettierOptions | null,
6566
characterRanges: CharacterRange[]
@@ -69,7 +70,12 @@ export const preciseFormatterPrettier: PreciseFormatter<PrettierOptions> = {
6970
// we've already made.
7071
return characterRanges.reduceRight(
7172
(fileContents, {rangeStart, rangeEnd}) =>
72-
format(fileContents, {...config, rangeStart, rangeEnd}),
73+
format(fileContents, {
74+
...config,
75+
filepath: filePath,
76+
rangeStart,
77+
rangeEnd
78+
}),
7379
fileContents
7480
);
7581
},

test/precise-formatter-prettier.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe("preciseFormatterPrettier", () => {
2323
var c = 3
2424
`;
2525
const formatted = preciseFormatterPrettier.formatRanges(
26+
"foo.js",
2627
contents,
2728
{
2829
semi: true
@@ -48,6 +49,7 @@ describe("preciseFormatterPrettier", () => {
4849
var c = 3;
4950
`;
5051
const formatted = preciseFormatterPrettier.checkFormattingOfRanges(
52+
"foo.js",
5153
contents,
5254
{
5355
semi: true
@@ -67,6 +69,7 @@ describe("preciseFormatterPrettier", () => {
6769
var c = 3
6870
`;
6971
const formatted = preciseFormatterPrettier.checkFormattingOfRanges(
72+
"foo.js",
7073
contents,
7174
{
7275
semi: true

0 commit comments

Comments
 (0)