diff --git a/src/printer.js b/src/printer.js index 42354ddf2..847d0285a 100644 --- a/src/printer.js +++ b/src/printer.js @@ -65,7 +65,7 @@ function genericPrint(path, options, printPath) { if ( node.comments && node.comments.length > 0 && - node.comments[0].value.trim() === "prettier-ignore" + node.comments[node.comments.length - 1].value.trim() === "prettier-ignore" ) { return options.originalText.slice(util.locStart(node), util.locEnd(node)); } diff --git a/tests/ignore/__snapshots__/jsfmt.spec.js.snap b/tests/ignore/__snapshots__/jsfmt.spec.js.snap index 8c530fdae..b2c170ea4 100644 --- a/tests/ignore/__snapshots__/jsfmt.spec.js.snap +++ b/tests/ignore/__snapshots__/jsfmt.spec.js.snap @@ -18,6 +18,14 @@ exports[`ignore.js 1`] = ` 0, 0, 0 ); + // Let's make sure that this comment doesn't interfere + + // prettier-ignore + const commentsWithPrettierIgnore = { + \\"ewww\\": + \\"gross-formatting\\", + }; + // prettier-ignore console.error( 'In order to use ' + prompt + ', you need to configure a ' + @@ -69,6 +77,14 @@ function a() { 0, 0, 0 ); + // Let's make sure that this comment doesn't interfere + + // prettier-ignore + const commentsWithPrettierIgnore = { + \\"ewww\\": + \\"gross-formatting\\", + }; + // prettier-ignore console.error( 'In order to use ' + prompt + ', you need to configure a ' + diff --git a/tests/ignore/ignore.js b/tests/ignore/ignore.js index 737a0688c..9e16dbd98 100644 --- a/tests/ignore/ignore.js +++ b/tests/ignore/ignore.js @@ -15,6 +15,14 @@ function a() { 0, 0, 0 ); + // Let's make sure that this comment doesn't interfere + + // prettier-ignore + const commentsWithPrettierIgnore = { + "ewww": + "gross-formatting", + }; + // prettier-ignore console.error( 'In order to use ' + prompt + ', you need to configure a ' +