prettier-plugin-solidity
Advanced tools
Comparing version 1.0.0-alpha.59 to 1.0.0-alpha.60
{ | ||
"name": "prettier-plugin-solidity", | ||
"version": "1.0.0-alpha.59", | ||
"version": "1.0.0-alpha.60", | ||
"description": "prettier plugin for solidity", | ||
@@ -61,3 +61,3 @@ "main": "src", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=10" | ||
}, | ||
@@ -75,3 +75,3 @@ "devDependencies": { | ||
"dependencies": { | ||
"@solidity-parser/parser": "^0.8.1", | ||
"@solidity-parser/parser": "^0.9.0", | ||
"dir-to-object": "^2.0.0", | ||
@@ -78,0 +78,0 @@ "emoji-regex": "^9.0.0", |
@@ -9,2 +9,4 @@ # prettier-plugin-solidity | ||
If you like this project, please consider contributing to our [Gitcoin grant](https://gitcoin.co/grants/1534/prettier-solidity)! | ||
## Installation and usage | ||
@@ -11,0 +13,0 @@ |
@@ -1,2 +0,2 @@ | ||
/* This file was automatically generated on 1599144978.689 */ | ||
/* This file was automatically generated on 1604800512.225 */ | ||
@@ -3,0 +3,0 @@ /* eslint-disable global-require */ |
const { | ||
doc: { | ||
builders: { concat } | ||
builders: { concat, hardline } | ||
} | ||
} = require('prettier/standalone'); | ||
const printComments = require('./print-comments'); | ||
const ExpressionStatement = { | ||
print: ({ node, path, print }) => | ||
concat([path.call(print, 'expression'), node.omitSemicolon ? '' : ';']) | ||
print: ({ node, options, path, print }) => { | ||
const parts = []; | ||
const parent = path.getParentNode(); | ||
if (parent.type === 'IfStatement') { | ||
if (node.comments && node.comments.length) { | ||
const comments = printComments(node, path, options); | ||
if (comments && comments.parts && comments.parts.length) { | ||
parts.push(comments); | ||
parts.push(hardline); | ||
} | ||
} | ||
} | ||
parts.push(path.call(print, 'expression')); | ||
parts.push(node.omitSemicolon ? '' : ';'); | ||
return concat(parts); | ||
} | ||
}; | ||
module.exports = ExpressionStatement; |
@@ -7,2 +7,3 @@ const { | ||
const printComments = require('./print-comments'); | ||
const printSeparatedItem = require('./print-separated-item'); | ||
@@ -26,5 +27,6 @@ | ||
const printElse = (node, path, print) => { | ||
const printElse = (node, path, print, commentsBetweenIfAndElse) => { | ||
if (node.falseBody) { | ||
const elseOnSameLine = node.trueBody.type === 'Block'; | ||
const elseOnSameLine = | ||
node.trueBody.type === 'Block' && commentsBetweenIfAndElse.length === 0; | ||
return concat([ | ||
@@ -40,12 +42,28 @@ elseOnSameLine ? ' ' : hardline, | ||
const IfStatement = { | ||
print: ({ node, path, print }) => | ||
concat([ | ||
print: ({ node, options, path, print }) => { | ||
const comments = node.comments || []; | ||
const commentsBetweenIfAndElse = comments.filter( | ||
(comment) => !comment.leading && !comment.trailing | ||
); | ||
const parts = []; | ||
parts.push( | ||
group( | ||
concat(['if (', printSeparatedItem(path.call(print, 'condition')), ')']) | ||
), | ||
printTrueBody(node, path, print), | ||
printElse(node, path, print) | ||
]) | ||
) | ||
); | ||
parts.push(printTrueBody(node, path, print)); | ||
if (commentsBetweenIfAndElse.length) { | ||
if (node.falseBody) { | ||
parts.push(hardline); | ||
parts.push(printComments(node, path, options)); | ||
} | ||
} | ||
parts.push(printElse(node, path, print, commentsBetweenIfAndElse)); | ||
return concat(parts); | ||
} | ||
}; | ||
module.exports = IfStatement; |
@@ -1,2 +0,2 @@ | ||
/* This file was automatically generated on 1599144978.631 */ | ||
/* This file was automatically generated on 1604800512.152 */ | ||
@@ -33,2 +33,3 @@ /* eslint-disable global-require */ | ||
ExpressionStatement: require('./ExpressionStatement.js'), | ||
FileLevelConstant: require('./FileLevelConstant.js'), | ||
ForStatement: require('./ForStatement.js'), | ||
@@ -35,0 +36,0 @@ FunctionCall: require('./FunctionCall.js'), |
const { | ||
doc: { | ||
builders: { concat } | ||
builders: { concat, group, indent, softline } | ||
} | ||
@@ -9,5 +9,15 @@ } = require('prettier/standalone'); | ||
print: ({ path, print }) => | ||
concat([path.call(print, 'base'), '[', path.call(print, 'index'), ']']) | ||
concat([ | ||
path.call(print, 'base'), | ||
'[', | ||
group( | ||
concat([ | ||
indent(concat([softline, path.call(print, 'index')])), | ||
softline | ||
]) | ||
), | ||
']' | ||
]) | ||
}; | ||
module.exports = IndexAccess; |
const { | ||
doc: { | ||
builders: { concat } | ||
builders: { concat, group, indent, line } | ||
} | ||
} = require('prettier/standalone'); | ||
const initialValue = (node, path, print) => | ||
node.initialValue ? concat([' = ', path.call(print, 'initialValue')]) : ''; | ||
const initialValue = (node, path, print) => { | ||
if (!node.initialValue) { | ||
return ''; | ||
} | ||
if (node.initialValue.type === 'TupleExpression') { | ||
return concat([' = ', path.call(print, 'initialValue')]); | ||
} | ||
return group( | ||
concat([' =', indent(concat([line, path.call(print, 'initialValue')]))]) | ||
); | ||
}; | ||
const StateVariableDeclaration = { | ||
@@ -11,0 +22,0 @@ print: ({ node, path, print }) => |
@@ -20,4 +20,4 @@ const { | ||
const TryStatement = { | ||
print: ({ node, path, print }) => | ||
concat([ | ||
print: ({ node, path, print }) => { | ||
let parts = [ | ||
'try', | ||
@@ -28,11 +28,20 @@ group( | ||
}) | ||
), | ||
returnParameters(node, path, print), | ||
' ', | ||
) | ||
]; | ||
const formattedReturnParameters = returnParameters(node, path, print); | ||
if (formattedReturnParameters) { | ||
parts = parts.concat([formattedReturnParameters, ' ']); | ||
} | ||
parts = parts.concat([ | ||
path.call(print, 'body'), | ||
' ', | ||
join(' ', path.map(print, 'catchClauses')) | ||
]) | ||
]); | ||
return concat(parts); | ||
} | ||
}; | ||
module.exports = TryStatement; |
const { | ||
doc: { | ||
builders: { concat } | ||
builders: { concat, group, indent, line } | ||
} | ||
@@ -13,3 +13,7 @@ } = require('prettier/standalone'); | ||
const initialValue = (node, path, print) => | ||
node.initialValue ? concat([' = ', path.call(print, 'initialValue')]) : ''; | ||
node.initialValue | ||
? group( | ||
concat([' =', indent(concat([line, path.call(print, 'initialValue')]))]) | ||
) | ||
: ''; | ||
@@ -21,11 +25,13 @@ const VariableDeclarationStatement = { | ||
return concat([ | ||
startsWithVar ? 'var ' : '', | ||
embraceVariables( | ||
printSeparatedList(path.map(print, 'variables')), | ||
node.variables.length > 1 || startsWithVar | ||
), | ||
initialValue(node, path, print), | ||
node.omitSemicolon ? '' : ';' | ||
]); | ||
return group( | ||
concat([ | ||
startsWithVar ? 'var ' : '', | ||
embraceVariables( | ||
printSeparatedList(path.map(print, 'variables')), | ||
node.variables.length > 1 || startsWithVar | ||
), | ||
initialValue(node, path, print), | ||
node.omitSemicolon ? '' : ';' | ||
]) | ||
); | ||
} | ||
@@ -32,0 +38,0 @@ }; |
@@ -1,51 +0,4 @@ | ||
const CATEGORY_GLOBAL = 'Global'; | ||
const CATEGORY_COMMON = 'Common'; | ||
const CATEGORY_SOLIDITY = 'Solidity'; | ||
const options = { | ||
bracketSpacing: { | ||
since: '0.0.0', | ||
category: CATEGORY_COMMON, | ||
type: 'boolean', | ||
default: false, | ||
description: 'Print spaces between brackets.', | ||
oppositeDescription: 'Do not print spaces between brackets.' | ||
}, | ||
printWidth: { | ||
since: '0.0.0', | ||
category: CATEGORY_GLOBAL, | ||
type: 'int', | ||
default: 80, | ||
description: 'The line length where Prettier will try wrap.', | ||
range: { | ||
start: 0, | ||
end: Infinity, | ||
step: 1 | ||
} | ||
}, | ||
singleQuote: { | ||
since: '0.0.0', | ||
category: CATEGORY_COMMON, | ||
type: 'boolean', | ||
default: false, | ||
description: 'Use single quotes instead of double quotes.' | ||
}, | ||
tabWidth: { | ||
type: 'int', | ||
category: CATEGORY_GLOBAL, | ||
default: 4, | ||
description: 'Number of spaces per indentation level.', | ||
range: { | ||
start: 0, | ||
end: Infinity, | ||
step: 1 | ||
} | ||
}, | ||
useTabs: { | ||
since: '1.0.0', | ||
category: CATEGORY_GLOBAL, | ||
type: 'boolean', | ||
default: false, | ||
description: 'Indent with tabs instead of spaces.' | ||
}, | ||
explicitTypes: { | ||
@@ -52,0 +5,0 @@ category: CATEGORY_SOLIDITY, |
@@ -186,2 +186,7 @@ "use strict"; | ||
function addBlockStatementFirstComment(node, comment) { | ||
if (!node.body) { | ||
addDanglingComment(node, comment); | ||
return; | ||
} | ||
const body = node.body.filter(n => n.type !== "EmptyStatement"); | ||
@@ -188,0 +193,0 @@ if (body.length === 0) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
489911
251
3766
136
+ Added@solidity-parser/parser@0.9.1(transitive)
+ Addedantlr4@4.13.2(transitive)
- Removed@solidity-parser/parser@0.8.2(transitive)