Skip to content

Commit

Permalink
feat(js): move binary operators to beginning of line
Browse files Browse the repository at this point in the history
  • Loading branch information
btmills committed Sep 19, 2018
1 parent 79f4251 commit 0342ca2
Show file tree
Hide file tree
Showing 24 changed files with 342 additions and 338 deletions.
8 changes: 5 additions & 3 deletions src/language-js/printer-estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -5241,9 +5241,11 @@ function printBinaryishExpressions(
}

const shouldInline = shouldInlineLogicalExpression(node);
const lineBeforeOperator =
node.operator === "|>" &&
!hasLeadingOwnLineComment(options.originalText, node.right, options);
const lineBeforeOperator = !hasLeadingOwnLineComment(
options.originalText,
node.right,
options
);

const right = shouldInline
? concat([node.operator, " ", path.call(print, "right")])
Expand Down
6 changes: 3 additions & 3 deletions tests/assignment/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ computedDescriptionLines = (focused &&
descriptionLines;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const computedDescriptionLines =
(showConfirm && descriptionLinesConfirming) ||
(focused && !loading && descriptionLinesFocused) ||
descriptionLines;
(showConfirm && descriptionLinesConfirming)
|| (focused && !loading && descriptionLinesFocused)
|| descriptionLines;
computedDescriptionLines =
(focused && !loading && descriptionLinesFocused) || descriptionLines;
Expand Down
24 changes: 12 additions & 12 deletions tests/assignment_comments/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ var fnString =
"some" + "long" + "string";
var fnString =
/* inline */ "some" +
"long" +
"string" +
"some" +
"long" +
"string" +
"some" +
"long" +
"string" +
"some" +
"long" +
"string";
/* inline */ "some"
+ "long"
+ "string"
+ "some"
+ "long"
+ "string"
+ "some"
+ "long"
+ "string"
+ "some"
+ "long"
+ "string";
var fnString = // Comment
// Comment
Expand Down
160 changes: 80 additions & 80 deletions tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ function f() {
function f() {
const appEntitys = getAppEntitys(loadObject).filter(
entity =>
entity &&
entity.isInstallAvailable() &&
!entity.isQueue() &&
entity.isDisabled()
entity
&& entity.isInstallAvailable()
&& !entity.isQueue()
&& entity.isDisabled()
);
}
function f() {
const appEntitys = getAppEntitys(loadObject).map(
entity =>
entity &&
entity.isInstallAvailable() &&
!entity.isQueue() &&
entity.isDisabled() && {
entity
&& entity.isInstallAvailable()
&& !entity.isQueue()
&& entity.isDisabled() && {
id: entity.id
}
);
Expand Down Expand Up @@ -63,9 +63,9 @@ a = (
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a =
// Commment 1
Math.random() * (yRange * (1 - minVerticalFraction)) +
minVerticalFraction * yRange -
offset;
Math.random() * (yRange * (1 - minVerticalFraction))
+ minVerticalFraction * yRange
- offset;
`;

Expand Down Expand Up @@ -127,14 +127,14 @@ if (this.hasPlugin("dynamicImports") && this.lookahead().type) {
}
if (
this.hasPlugin("dynamicImports") &&
this.lookahead().type === tt.parenLeft
this.hasPlugin("dynamicImports")
&& this.lookahead().type === tt.parenLeft
) {
}
if (
this.hasPlugin("dynamicImports") &&
this.lookahead().type === tt.parenLeft.right
this.hasPlugin("dynamicImports")
&& this.lookahead().type === tt.parenLeft.right
) {
}
Expand All @@ -161,8 +161,8 @@ const user = renderedUser || (
);
const user =
renderedUser ||
(shouldRenderUser && (
renderedUser
|| (shouldRenderUser && (
<div>
<User name={this.state.user.name} age={this.state.user.age} />
</div>
Expand Down Expand Up @@ -275,8 +275,8 @@ prevState = prevState || {
selectedCatalog: null
};
prevState = prevState ||
defaultState || {
prevState = prevState
|| defaultState || {
catalogs: [],
loadState: LOADED,
opened: false,
Expand All @@ -285,17 +285,17 @@ prevState = prevState ||
};
prevState =
prevState ||
(defaultState && {
prevState
|| (defaultState && {
catalogs: [],
loadState: LOADED,
opened: false,
searchQuery: "",
selectedCatalog: null
});
prevState = prevState ||
(useDefault && defaultState) || {
prevState = prevState
|| (useDefault && defaultState) || {
catalogs: [],
loadState: LOADED,
opened: false,
Expand All @@ -311,8 +311,8 @@ this.steps = steps || [
];
this.steps =
steps ||
(checkStep && [
steps
|| (checkStep && [
{
name: "mock-module",
path: "/nux/mock-module"
Expand All @@ -329,8 +329,8 @@ this.steps = (steps && checkStep) || [
const create = () => {
const result = doSomething();
return (
shouldReturn &&
result.ok && {
shouldReturn
&& result.ok && {
status: "ok",
createdAt: result.createdAt,
updatedAt: result.updatedAt
Expand All @@ -350,8 +350,8 @@ const create = () => {
};
const obj = {
state: shouldHaveState &&
stateIsOK && {
state: shouldHaveState
&& stateIsOK && {
loadState: LOADED,
opened: false
},
Expand Down Expand Up @@ -400,31 +400,31 @@ exports[`jsx_parent.js - flow-verify 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div
src={
!isJellyfishEnabled &&
diffUpdateMessageInput != null &&
this.state.isUpdateMessageEmpty
!isJellyfishEnabled
&& diffUpdateMessageInput != null
&& this.state.isUpdateMessageEmpty
}
/>;
<div>
{!isJellyfishEnabled &&
diffUpdateMessageInput != null &&
this.state.isUpdateMessageEmpty}
{!isJellyfishEnabled
&& diffUpdateMessageInput != null
&& this.state.isUpdateMessageEmpty}
</div>;
<div
style={
!isJellyfishEnabled &&
diffUpdateMessageInput && {
!isJellyfishEnabled
&& diffUpdateMessageInput && {
fontSize: 14,
color: "#fff"
}
}
/>;
<div>
{!isJellyfishEnabled &&
diffUpdateMessageInput != null && (
{!isJellyfishEnabled
&& diffUpdateMessageInput != null && (
<div>
<span>Text</span>
</div>
Expand Down Expand Up @@ -509,21 +509,21 @@ function foo() {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo() {
return (
this.hasPlugin("dynamicImports") &&
this.lookahead().type === tt.parenLeft.right
this.hasPlugin("dynamicImports")
&& this.lookahead().type === tt.parenLeft.right
);
}
function foo() {
return this.hasPlugin("dynamicImports") &&
this.lookahead().type === tt.parenLeft.right
return this.hasPlugin("dynamicImports")
&& this.lookahead().type === tt.parenLeft.right
? true
: false;
}
function foo() {
return this.calculate().compute().first.numberOfThings >
this.calculate().compute().last.numberOfThings
return this.calculate().compute().first.numberOfThings
> this.calculate().compute().last.numberOfThings
? true
: false;
}
Expand Down Expand Up @@ -551,10 +551,10 @@ defaultContent.filter(defaultLocale => {
// ...
})[0] || null;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this._cumulativeHeights &&
Math.abs(
this._cachedItemHeight(this._firstVisibleIndex + i) -
this._provider.fastHeight(i + this._firstVisibleIndex)
this._cumulativeHeights
&& Math.abs(
this._cachedItemHeight(this._firstVisibleIndex + i)
- this._provider.fastHeight(i + this._firstVisibleIndex)
) > 1;
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(
Expand Down Expand Up @@ -596,42 +596,42 @@ foo(obj.property * new Class() && obj instanceof Class && longVariable ? number
const x = longVariable + longVariable + longVariable;
const x =
longVariable +
longVariable +
longVariable +
longVariable -
longVariable +
longVariable;
longVariable
+ longVariable
+ longVariable
+ longVariable
- longVariable
+ longVariable;
const x =
longVariable +
longVariable * longVariable +
longVariable -
longVariable +
longVariable;
longVariable
+ longVariable * longVariable
+ longVariable
- longVariable
+ longVariable;
const x =
longVariable +
(longVariable * longVariable * longVariable) / longVariable +
longVariable;
longVariable
+ (longVariable * longVariable * longVariable) / longVariable
+ longVariable;
const x =
longVariable &&
longVariable &&
longVariable &&
longVariable &&
longVariable &&
longVariable;
longVariable
&& longVariable
&& longVariable
&& longVariable
&& longVariable
&& longVariable;
const x =
(longVariable && longVariable) ||
(longVariable && longVariable) ||
(longVariable && longVariable);
(longVariable && longVariable)
|| (longVariable && longVariable)
|| (longVariable && longVariable);
const x =
firstItemWithAVeryLongNameThatKeepsGoing ||
firstItemWithAVeryLongNameThatKeepsGoing ||
{};
firstItemWithAVeryLongNameThatKeepsGoing
|| firstItemWithAVeryLongNameThatKeepsGoing
|| {};
const x =
firstItemWithAVeryLongNameThatKeepsGoing ||
firstItemWithAVeryLongNameThatKeepsGoing ||
[];
firstItemWithAVeryLongNameThatKeepsGoing
|| firstItemWithAVeryLongNameThatKeepsGoing
|| [];
const x =
call(
firstItemWithAVeryLongNameThatKeepsGoing,
Expand Down Expand Up @@ -659,8 +659,8 @@ const anyTestFailures = !(
);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const anyTestFailures = !(
aggregatedResults.numFailedTests === 0 &&
aggregatedResults.numRuntimeErrorTestSuites === 0
aggregatedResults.numFailedTests === 0
&& aggregatedResults.numRuntimeErrorTestSuites === 0
);
`;
6 changes: 3 additions & 3 deletions tests/class_comment/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class x {
class X {
TEMPLATE =
// tab index is needed so we can focus, which is needed for keyboard events
'<div class="ag-large-text" tabindex="0">' +
'<div class="ag-large-textarea"></div>' +
"</div>";
'<div class="ag-large-text" tabindex="0">'
+ '<div class="ag-large-textarea"></div>'
+ "</div>";
}
export class SnapshotLogger {
Expand Down

0 comments on commit 0342ca2

Please sign in to comment.