Skip to content

Commit

Permalink
Merge pull request diffblue#528 from diffblue/cleanup/max-line-length
Browse files Browse the repository at this point in the history
Extract max line length into a constant
  • Loading branch information
NathanJPhillips authored Aug 14, 2018
2 parents e7e43da + 3016a8e commit 1737d9d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions env-model-generator/src/javaCode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as _ from "lodash";

const maxLineLength = 150;

function indent(line: string): string { return line === "" ? "" : " " + line; }

export abstract class CodeElement {
Expand Down Expand Up @@ -46,7 +48,7 @@ export class FnCall extends CodeElement implements Expression {
argInLines[argInLines.length - 1] += ",";
}
const oneLine = this.fnName + "(" + argsInLines.join(" ") + ")";
if (oneLine.length < 80)
if (oneLine.length < maxLineLength)
return [ oneLine ];
return [
this.fnName + "(",
Expand Down Expand Up @@ -74,7 +76,7 @@ export class BraceInitialiser extends CodeElement implements Expression {
argInLines[argInLines.length - 1] += ",";
}
const oneLine = this.typename + " { " + argsInLines.join(" ") + " }";
if (oneLine.length < 80)
if (oneLine.length < maxLineLength)
return [ oneLine ];
return [
this.typename + " {",
Expand Down Expand Up @@ -138,7 +140,7 @@ export class Assignment extends CodeElement implements Statement {
rhsInLines[rhsInLines.length - 1] += ";";
if (rhsInLines.length === 1) {
const oneLine = this.lhs + " = " + rhsInLines[0];
if (oneLine.length < 100)
if (oneLine.length < maxLineLength)
return [ oneLine ];
}
return [
Expand Down Expand Up @@ -169,15 +171,15 @@ export class Declaration extends CodeElement implements Statement, Member {
rhsInLines[rhsInLines.length - 1] += ";";
const name = this.name + (rhsInLines.length === 0 ? ";" : " =");
const oneLineLhs = `${this.modifiedType} ${name}`;
if (oneLineLhs.length >= 80)
if (oneLineLhs.length >= maxLineLength)
return [
this.modifiedType,
indent(name),
...rhsInLines.map((arg) => indent(indent(arg))),
];
if (rhsInLines.length <= 1) {
const oneLine = rhsInLines.length === 0 ? oneLineLhs : `${oneLineLhs} ${rhsInLines[0]}`;
if (oneLine.length < 80)
if (oneLine.length < maxLineLength)
return [ oneLine ];
}
return [
Expand All @@ -203,7 +205,7 @@ export class Return extends CodeElement implements Statement {
valueInLines[valueInLines.length - 1] += ";";
if (valueInLines.length === 1) {
const oneLine = "return " + valueInLines[0];
if (oneLine.length < 100)
if (oneLine.length < maxLineLength)
return [ oneLine ];
}
return [
Expand Down

0 comments on commit 1737d9d

Please sign in to comment.