Format prettier with newer prettier (#2431)

master
Simen Bekkhus 2017-07-08 14:07:39 +02:00 committed by Christopher Chedeau
parent 3e184d8f37
commit 1b4846b67d
11 changed files with 61 additions and 66 deletions

View File

@ -174,9 +174,10 @@ function format(input, opt) {
if (ast !== past) {
const MAX_AST_SIZE = 2097152; // 2MB
const astDiff = ast.length > MAX_AST_SIZE || past.length > MAX_AST_SIZE
? "AST diff too large to render"
: diff(ast, past);
const astDiff =
ast.length > MAX_AST_SIZE || past.length > MAX_AST_SIZE
? "AST diff too large to render"
: diff(ast, past);
throw "ast(input) !== ast(prettier(input))\n" +
astDiff +
"\n" +

View File

@ -46,7 +46,7 @@
"eslint-plugin-react": "7.1.0",
"jest": "20.0.0",
"mkdirp": "^0.5.1",
"prettier": "1.4.2",
"prettier": "1.5.2",
"rimraf": "2.6.1",
"rollup": "0.41.1",
"rollup-plugin-commonjs": "7.0.0",

View File

@ -19,12 +19,10 @@ function flattenDoc(doc) {
return Object.assign({}, doc, { parts: res });
} else if (doc.type === "if-break") {
return Object.assign({}, doc, {
breakContents: doc.breakContents != null
? flattenDoc(doc.breakContents)
: null,
flatContents: doc.flatContents != null
? flattenDoc(doc.flatContents)
: null
breakContents:
doc.breakContents != null ? flattenDoc(doc.breakContents) : null,
flatContents:
doc.flatContents != null ? flattenDoc(doc.flatContents) : null
});
} else if (doc.type === "group") {
return Object.assign({}, doc, {

View File

@ -65,9 +65,10 @@ function toBabylon(node) {
};
const value = JSON.parse(node.rawValue);
const type = value === null
? "NullLiteral"
: constructorTypes[value.constructor.name];
const type =
value === null
? "NullLiteral"
: constructorTypes[value.constructor.name];
return Object.assign(result, {
type: type,

View File

@ -206,10 +206,10 @@ function genericPrint(path, options, print) {
case "selector-combinator": {
if (n.value === "+" || n.value === ">" || n.value === "~") {
const parent = path.getParentNode();
const leading = parent.type === "selector-selector" &&
parent.nodes[0] === n
? ""
: line;
const leading =
parent.type === "selector-selector" && parent.nodes[0] === n
? ""
: line;
return concat([leading, n.value, " "]);
}
return n.value.trim() || line;

View File

@ -153,10 +153,10 @@ function genericPrint(path, options, printPath, args) {
path.each(
decoratorPath => {
const decorator = decoratorPath.getValue();
const prefix = decorator.type === "Decorator" ||
decorator.type === "TSDecorator"
? ""
: "@";
const prefix =
decorator.type === "Decorator" || decorator.type === "TSDecorator"
? ""
: "@";
decorators.push(prefix, printPath(decoratorPath), hardline);
},
"declaration",
@ -909,10 +909,10 @@ function genericPrintNoParens(path, options, print, args) {
util.locStart(n),
util.locEnd(n)
));
const separator = n.type === "TSInterfaceBody" ||
n.type === "TSTypeLiteral"
? ifBreak(semi, ";")
: ",";
const separator =
n.type === "TSInterfaceBody" || n.type === "TSTypeLiteral"
? ifBreak(semi, ";")
: ",";
const fields = [];
const leftBrace = n.exact ? "{|" : "{";
const rightBrace = n.exact ? "|}" : "}";
@ -987,7 +987,7 @@ function genericPrintNoParens(path, options, print, args) {
),
ifBreak(
canHaveTrailingSeparator &&
(separator !== "," || shouldPrintComma(options))
(separator !== "," || shouldPrintComma(options))
? separator
: ""
),
@ -1113,8 +1113,8 @@ function genericPrintNoParens(path, options, print, args) {
needsForcedTrailingComma ? "," : "",
ifBreak(
canHaveTrailingComma &&
!needsForcedTrailingComma &&
shouldPrintComma(options)
!needsForcedTrailingComma &&
shouldPrintComma(options)
? ","
: ""
),
@ -1540,7 +1540,7 @@ function genericPrintNoParens(path, options, print, args) {
return concat([
casePath.call(print),
n.cases.indexOf(caseNode) !== n.cases.length - 1 &&
util.isNextLineEmpty(options.originalText, caseNode)
util.isNextLineEmpty(options.originalText, caseNode)
? hardline
: ""
]);
@ -4230,9 +4230,10 @@ function nodeStr(node, options, isFlowOrTypeScriptDirectiveLiteral) {
canChangeDirectiveQuotes = true;
}
const enclosingQuote = options.parser === "json"
? double.quote
: shouldUseAlternateQuote ? alternate.quote : preferred.quote;
const enclosingQuote =
options.parser === "json"
? double.quote
: shouldUseAlternateQuote ? alternate.quote : preferred.quote;
// Directives are exact code unit sequences, which means that you can't
// change the escape sequences they use.

View File

@ -37,24 +37,14 @@ class Footer extends React.Component {
</a>
<div>
<h5>Docs</h5>
<a href={this.url("/why-prettier.html")}>
Why Prettier?
</a>
<a href={this.url("/usage.html")}>
Usage
</a>
<a href={this.url("/options.html")}>
Options
</a>
<a href={this.url("/editors.html")}>
Editor Integeration
</a>
<a href={this.url("/why-prettier.html")}>Why Prettier?</a>
<a href={this.url("/usage.html")}>Usage</a>
<a href={this.url("/options.html")}>Options</a>
<a href={this.url("/editors.html")}>Editor Integeration</a>
</div>
<div>
<h5>Community</h5>
<a href={this.url("/users/")}>
User Showcase
</a>
<a href={this.url("/users/")}>User Showcase</a>
<a
href="http://stackoverflow.com/questions/tagged/prettier"
target="_blank"

View File

@ -43,7 +43,9 @@ class HomeSplash extends React.Component {
<div className="inner">
<h2 className="projectTitle">
{siteConfig.title}
<small>{siteConfig.tagline}</small>
<small>
{siteConfig.tagline}
</small>
</h2>
<div className="section promoSection">
<div className="promoRow">
@ -162,14 +164,15 @@ class Index extends React.Component {
</Container>*/}
<div className="productShowcaseSection paddingTop paddingBottom lightBackground">
<h2>Who{"'"}s Using Prettier?</h2>
<h2>
Who{"'"}s Using Prettier?
</h2>
<p>
A few of the
{" "}
A few of the{" "}
<a href="https://www.npmjs.com/browse/depended/prettier">
many projects
</a>
{" "}using Prettier
</a>{" "}
using Prettier
</p>
<div className="logos">
{showcase}

View File

@ -23,14 +23,15 @@ class Users extends React.Component {
<Container padding={["bottom", "top"]}>
<div className="showcaseSection">
<div className="prose">
<h1>Who{"'"}s Using This?</h1>
<h1>
Who{"'"}s Using This?
</h1>
<p>
A few of the
{" "}
A few of the{" "}
<a href="https://www.npmjs.com/browse/depended/prettier">
many projects
</a>
{" "}using Prettier
</a>{" "}
using Prettier
</p>
</div>
<div className="logos">

View File

@ -10,11 +10,11 @@ var state = (function loadState(hash) {
options: undefined,
content:
'hello ( "world"\n);\n\n' +
'[ "lorem", "ipsum", \'dolor\', sit("amet"), consectetur[ \'adipiscing\' ] + "elit" ].reduce(\n (first, second) => first + second,\n "")\n\n' +
"const Foo = ({ bar, baz, things }) => {\n" +
' return <div style={{\ncolor: "papayawhip"}}>\n' +
" <br/>{things.map(thing => reallyLongPleaseDontPutOnOneLine(thing) ? <p>{ok}</p> : <Quax bar={bar} baz={ baz } {...thing}></Quax>)\n" +
" }</div>}"
'[ "lorem", "ipsum", \'dolor\', sit("amet"), consectetur[ \'adipiscing\' ] + "elit" ].reduce(\n (first, second) => first + second,\n "")\n\n' +
"const Foo = ({ bar, baz, things }) => {\n" +
' return <div style={{\ncolor: "papayawhip"}}>\n' +
" <br/>{things.map(thing => reallyLongPleaseDontPutOnOneLine(thing) ? <p>{ok}</p> : <Quax bar={bar} baz={ baz } {...thing}></Quax>)\n" +
" }</div>}"
};
}
})(decodeURIComponent(location.hash.slice(1)));

View File

@ -2990,9 +2990,9 @@ preserve@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
prettier@1.4.2:
version "1.4.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.4.2.tgz#bcdd95ed1eca434ac7f98ca26ea4d25a2af6a2ac"
prettier@1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.5.2.tgz#7ea0751da27b93bfb6cecfcec509994f52d83bb3"
pretty-format@^20.0.3:
version "20.0.3"