prettier/tests/comments/__snapshots__/jsfmt.spec.js.snap

922 lines
17 KiB
Plaintext
Raw Normal View History

exports[`test blank.js 1`] = `
"// This file only
// has comments. This comment
// should still exist
//
// when printed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file only
// has comments. This comment
// should still exist
//
// when printed.
"
`;
exports[`test blank.js 2`] = `
"// This file only
// has comments. This comment
// should still exist
//
// when printed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file only
// has comments. This comment
// should still exist
//
// when printed.
"
`;
exports[`test dangling.js 1`] = `
"var x = {/* dangling */};
var x = {
// dangling
};
var x = [/* dangling */];
function x() {
/* dangling */
}
declare class Foo extends Qux<string> {/* dangling */}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var x = {/* dangling */};
var x = {
// dangling
};
var x = [/* dangling */];
function x() {
/* dangling */
}
declare class Foo extends Qux<string> {/* dangling */}
"
`;
exports[`test dangling.js 2`] = `
"var x = {/* dangling */};
var x = {
// dangling
};
var x = [/* dangling */];
function x() {
/* dangling */
}
declare class Foo extends Qux<string> {/* dangling */}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var x = {/* dangling */};
var x = {
// dangling
};
var x = [/* dangling */];
function x() {
/* dangling */
}
declare class Foo extends Qux<string> {/* dangling */}
"
`;
exports[`test dangling_array.js 1`] = `
"expect(() => {}).toTriggerReadyStateChanges([
// Nothing.
]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
expect(() => {}).toTriggerReadyStateChanges(
[
// Nothing.
]
);
"
`;
exports[`test dangling_array.js 2`] = `
"expect(() => {}).toTriggerReadyStateChanges([
// Nothing.
]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
expect(() => {}).toTriggerReadyStateChanges(
[
// Nothing.
]
);
"
`;
exports[`test first-line.js 1`] = `
"a // comment
b
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a; // comment
b;
"
`;
exports[`test first-line.js 2`] = `
"a // comment
b
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a; // comment
b;
"
`;
exports[`test if.js 1`] = `
"if (1)
// comment
{
false
}
// comment
else if (2)
true
// multi
// ple
// lines
else if (3)
// existing comment
true
// okay?
else if (4) {
// empty with existing comment
}
// comment
else {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (1) {
// comment
false;
} else if (2)
// comment
true;
else if (3)
// multi
// ple
// lines
// existing comment
true;
else if (4) {
// okay?
// empty with existing comment
} else {
// comment
}
"
`;
exports[`test if.js 2`] = `
"if (1)
// comment
{
false
}
// comment
else if (2)
true
// multi
// ple
// lines
else if (3)
// existing comment
true
// okay?
else if (4) {
// empty with existing comment
}
// comment
else {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (1) {
// comment
false;
} else if (2)
// comment
true;
else if (3)
// multi
// ple
// lines
// existing comment
true;
else if (4) {
// okay?
// empty with existing comment
} else {
// comment
}
"
`;
exports[`test issues.js 1`] = `
"// Does not need to break as it fits in 80 columns
this.call(a, /* comment */ b);
function f(
someReallyLongArgument: WithSomeLongType,
someReallyLongArgument2: WithSomeLongType,
// Trailing comment should stay after
) {}
// Comments should either stay at the end of the line or always before, but
// not one before and one after.
throw new ProcessSystemError({
code: acc.error.code, // Alias of errno
originalError: acc.error, // Just in case.
});
// Adding a comment stops the pretty printing process and everything is
// squished in a single line afterward
export type BuckWebSocketMessage = {
// Not actually from Buck - this is to let the receiver know that the socket is connected.
type: \'SocketConnected\',
} | {
type: \'BuildProgressUpdated\',
progressValue: number,
} | {
type: \'BuildFinished\',
exitCode: number,
} | {
type: \'BuildStarted\',
} | {
type: \'ParseStarted\',
} | {
type: \'ParseFinished\',
} | {
type: \'RunStarted\',
} | {
type: \'RunComplete\',
};
// Missing one level of indentation because of the comment
const rootEpic = (actions, store) => (
combineEpics(...epics)(actions, store)
// Log errors and continue.
.catch((err, stream) => {
getLogger().error(err);
return stream;
})
);
// Two extra levels of indentation because of the comment
export type AsyncExecuteOptions = child_process$execFileOpts & {
// The contents to write to stdin.
stdin?: ?string,
dontLogInNuclide?: ?boolean,
};
// optional trailing comma gets moved all the way to the beginning
const regex = new RegExp(
\'^\\\\s*\' + // beginning of the line
\'name\\\\s*=\\\\s*\' + // name =
\'[\\\'\"]\' + // opening quotation mark
escapeStringRegExp(target.name) + // target name
\'[\\\'\"]\' + // closing quotation mark
\',?$\', // optional trailing comma
);
// The comment is moved and doesn\'t trigger the eslint rule anymore
import path from \'path\'; // eslint-disable-line nuclide-internal/prefer-nuclide-uri
// Comments disappear in-between MemberExpressions
Observable.of(process)
// Don\'t complete until we say so!
.merge(Observable.never())
// Get the errors.
.takeUntil(throwOnError ? errors.flatMap(Observable.throw) : errors)
.takeUntil(exit);
// Comments disappear inside of JSX
<div>
{/* Some comment */}
</div>;
// Comments in JSX tag are placed in a non optimal way
<div
// comment
/>;
// Comments disappear in empty blocks
if (1) {
// Comment
}
// Comments trigger invalid JavaScript in-between else if
if (1) {
}
// Comment
else {
}
// The comment makes the line break in a weird way
const result = asyncExecute(\'non_existing_command\', /* args */ []);
// The closing paren is printed on the same line as the comment
foo({}
// Hi
);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Does not need to break as it fits in 80 columns
this.call(a, /* comment */ b);
function f(
someReallyLongArgument: WithSomeLongType,
someReallyLongArgument2: WithSomeLongType
) // Trailing comment should stay after
{
}
// Comments should either stay at the end of the line or always before, but
// not one before and one after.
throw new ProcessSystemError({
code: acc.error.code, // Alias of errno
originalError: acc.error // Just in case.
});
// Adding a comment stops the pretty printing process and everything is
// squished in a single line afterward
export type BuckWebSocketMessage =
| {
// Not actually from Buck - this is to let the receiver know that the socket is connected.
type: \"SocketConnected\"
}
| {
type: \"BuildProgressUpdated\",
progressValue: number
}
| {
type: \"BuildFinished\",
exitCode: number
}
| {
type: \"BuildStarted\"
}
| {
type: \"ParseStarted\"
}
| {
type: \"ParseFinished\"
}
| {
type: \"RunStarted\"
}
| {
type: \"RunComplete\"
};
// Missing one level of indentation because of the comment
const rootEpic = (actions, store) => combineEpics(...epics)(actions, store)
// Log errors and continue.
.catch((err, stream) => {
getLogger().error(err);
return stream;
});
// Two extra levels of indentation because of the comment
export type AsyncExecuteOptions =
& child_process$execFileOpts
& {
// The contents to write to stdin.
stdin?: ?string,
dontLogInNuclide?: ?boolean
};
// optional trailing comma gets moved all the way to the beginning
const regex = new RegExp(
\"^\\\\s*\" + // beginning of the line
\"name\\\\s*=\\\\s*\" + // name =
\"[\'\\\"]\" + // opening quotation mark
escapeStringRegExp(target.name) + // target name
\"[\'\\\"]\" + // closing quotation mark
\",?$\" // optional trailing comma
);
// The comment is moved and doesn\'t trigger the eslint rule anymore
import path from \"path\"; // eslint-disable-line nuclide-internal/prefer-nuclide-uri
// Comments disappear in-between MemberExpressions
Observable.of(process)
// Don\'t complete until we say so!
.merge(Observable.never())
// Get the errors.
.takeUntil(throwOnError ? errors.flatMap(Observable.throw) : errors)
.takeUntil(exit);
/* Comments disappear inside of JSX*/
<div>
{/* Some comment */}
</div>;
/* Comments in JSX tag are placed in a non optimal way*/
<div
2017-01-24 21:54:01 +03:00
/* comment*/
/>;
// Comments disappear in empty blocks
if (1) {
// Comment
}
// Comments trigger invalid JavaScript in-between else if
if (1) {
} else {
// Comment
}
// The comment makes the line break in a weird way
const result = asyncExecute(\"non_existing_command\", /* args */ []);
// The closing paren is printed on the same line as the comment
foo(
{}
// Hi
);
"
`;
exports[`test issues.js 2`] = `
"// Does not need to break as it fits in 80 columns
this.call(a, /* comment */ b);
function f(
someReallyLongArgument: WithSomeLongType,
someReallyLongArgument2: WithSomeLongType,
// Trailing comment should stay after
) {}
// Comments should either stay at the end of the line or always before, but
// not one before and one after.
throw new ProcessSystemError({
code: acc.error.code, // Alias of errno
originalError: acc.error, // Just in case.
});
// Adding a comment stops the pretty printing process and everything is
// squished in a single line afterward
export type BuckWebSocketMessage = {
// Not actually from Buck - this is to let the receiver know that the socket is connected.
type: \'SocketConnected\',
} | {
type: \'BuildProgressUpdated\',
progressValue: number,
} | {
type: \'BuildFinished\',
exitCode: number,
} | {
type: \'BuildStarted\',
} | {
type: \'ParseStarted\',
} | {
type: \'ParseFinished\',
} | {
type: \'RunStarted\',
} | {
type: \'RunComplete\',
};
// Missing one level of indentation because of the comment
const rootEpic = (actions, store) => (
combineEpics(...epics)(actions, store)
// Log errors and continue.
.catch((err, stream) => {
getLogger().error(err);
return stream;
})
);
// Two extra levels of indentation because of the comment
export type AsyncExecuteOptions = child_process$execFileOpts & {
// The contents to write to stdin.
stdin?: ?string,
dontLogInNuclide?: ?boolean,
};
// optional trailing comma gets moved all the way to the beginning
const regex = new RegExp(
\'^\\\\s*\' + // beginning of the line
\'name\\\\s*=\\\\s*\' + // name =
\'[\\\'\"]\' + // opening quotation mark
escapeStringRegExp(target.name) + // target name
\'[\\\'\"]\' + // closing quotation mark
\',?$\', // optional trailing comma
);
// The comment is moved and doesn\'t trigger the eslint rule anymore
import path from \'path\'; // eslint-disable-line nuclide-internal/prefer-nuclide-uri
// Comments disappear in-between MemberExpressions
Observable.of(process)
// Don\'t complete until we say so!
.merge(Observable.never())
// Get the errors.
.takeUntil(throwOnError ? errors.flatMap(Observable.throw) : errors)
.takeUntil(exit);
// Comments disappear inside of JSX
<div>
{/* Some comment */}
</div>;
// Comments in JSX tag are placed in a non optimal way
<div
// comment
/>;
// Comments disappear in empty blocks
if (1) {
// Comment
}
// Comments trigger invalid JavaScript in-between else if
if (1) {
}
// Comment
else {
}
// The comment makes the line break in a weird way
const result = asyncExecute(\'non_existing_command\', /* args */ []);
// The closing paren is printed on the same line as the comment
foo({}
// Hi
);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Does not need to break as it fits in 80 columns
this.call(a, /* comment */ b);
function f(
someReallyLongArgument: WithSomeLongType,
someReallyLongArgument2: WithSomeLongType
) // Trailing comment should stay after
{
}
// Comments should either stay at the end of the line or always before, but
// not one before and one after.
throw new ProcessSystemError({
code: acc.error.code, // Alias of errno
originalError: acc.error // Just in case.
});
// Adding a comment stops the pretty printing process and everything is
// squished in a single line afterward
export type BuckWebSocketMessage =
| {
// Not actually from Buck - this is to let the receiver know that the socket is connected.
type: \"SocketConnected\"
}
| {
type: \"BuildProgressUpdated\",
progressValue: number
}
| {
type: \"BuildFinished\",
exitCode: number
}
| {
type: \"BuildStarted\"
}
| {
type: \"ParseStarted\"
}
| {
type: \"ParseFinished\"
}
| {
type: \"RunStarted\"
}
| {
type: \"RunComplete\"
};
// Missing one level of indentation because of the comment
const rootEpic = (actions, store) => combineEpics(...epics)(actions, store)
// Log errors and continue.
.catch((err, stream) => {
getLogger().error(err);
return stream;
});
// Two extra levels of indentation because of the comment
export type AsyncExecuteOptions =
& child_process$execFileOpts
& {
// The contents to write to stdin.
stdin?: ?string,
dontLogInNuclide?: ?boolean
};
// optional trailing comma gets moved all the way to the beginning
const regex = new RegExp(
\"^\\\\s*\" + // beginning of the line
\"name\\\\s*=\\\\s*\" + // name =
\"[\'\\\"]\" + // opening quotation mark
escapeStringRegExp(target.name) + // target name
\"[\'\\\"]\" + // closing quotation mark
\",?$\" // optional trailing comma
);
// The comment is moved and doesn\'t trigger the eslint rule anymore
import path from \"path\"; // eslint-disable-line nuclide-internal/prefer-nuclide-uri
// Comments disappear in-between MemberExpressions
Observable.of(process)
// Don\'t complete until we say so!
.merge(Observable.never())
// Get the errors.
.takeUntil(throwOnError ? errors.flatMap(Observable.throw) : errors)
.takeUntil(exit);
// Comments disappear inside of JSX
<div>
{/* Some comment */}
</div>;
// Comments in JSX tag are placed in a non optimal way
<div
// comment
2017-01-24 21:54:01 +03:00
/>;
// Comments disappear in empty blocks
if (1) {
// Comment
}
// Comments trigger invalid JavaScript in-between else if
if (1) {
} else {
// Comment
}
// The comment makes the line break in a weird way
const result = asyncExecute(\"non_existing_command\", /* args */ []);
// The closing paren is printed on the same line as the comment
foo(
{}
// Hi
);
"
`;
exports[`test jsx.js 1`] = `
"<div>
{
/* comment */
}
</div>;
<div>
{/* comment */
}
</div>;
<div>
{/* comment
*/
}
</div>;
<div>
{a/* comment
*/
}
</div>;
<div>
{/* comment
*/
a
}
</div>;
<div>
{/* comment */
}
</div>;
<div>
{/* comment */}
</div>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div>
{
/* comment */
}
</div>;
<div>
{/* comment */}
</div>;
<div>
{/* comment
*/}
</div>;
<div>
{a /* comment
*/}
</div>;
<div>
{
/* comment
*/
a
}
</div>;
<div>
{/* comment */}
</div>;
<div>
{/* comment */}
</div>;
"
`;
exports[`test jsx.js 2`] = `
"<div>
{
/* comment */
}
</div>;
<div>
{/* comment */
}
</div>;
<div>
{/* comment
*/
}
</div>;
<div>
{a/* comment
*/
}
</div>;
<div>
{/* comment
*/
a
}
</div>;
<div>
{/* comment */
}
</div>;
<div>
{/* comment */}
</div>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div>
{
/* comment */
}
</div>;
<div>
{/* comment */}
</div>;
<div>
{/* comment
*/}
</div>;
<div>
{a /* comment
*/}
</div>;
<div>
{
/* comment
*/
a
}
</div>;
<div>
{/* comment */}
</div>;
<div>
{/* comment */}
</div>;
"
`;
exports[`test preserve-new-line-last.js 1`] = `
"function name() {
// comment1
func1()
// comment2
func2()
// comment3 why func3 commented
// func3()
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function name() {
// comment1
func1();
// comment2
func2();
// comment3 why func3 commented
// func3()
}
"
`;
exports[`test preserve-new-line-last.js 2`] = `
"function name() {
// comment1
func1()
// comment2
func2()
// comment3 why func3 commented
// func3()
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function name() {
// comment1
func1();
// comment2
func2();
// comment3 why func3 commented
// func3()
}
"
`;
exports[`test try.js 1`] = `
"// comment 1
try {
// comment 2
}
// comment 3
catch(e) {
// comment 4
}
// comment 5
finally // comment 6
{
// comment 7
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// comment 1
try {
// comment 2
} catch (e) {
// comment 3
// comment 4
} finally { // comment 6
// comment 5
// comment 7
}
"
`;
exports[`test try.js 2`] = `
"// comment 1
try {
// comment 2
}
// comment 3
catch(e) {
// comment 4
}
// comment 5
finally // comment 6
{
// comment 7
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// comment 1
try {
// comment 2
} catch (e) {
// comment 3
// comment 4
} finally { // comment 6
// comment 5
// comment 7
}
"
`;