Socket
Socket
Sign inDemoInstall

prettier-plugin-solidity

Package Overview
Dependencies
Maintainers
0
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-solidity - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

2

package.json
{
"name": "prettier-plugin-solidity",
"version": "1.4.0",
"version": "1.4.1",
"description": "A Prettier Plugin for automatically formatting your Solidity code.",

@@ -5,0 +5,0 @@ "type": "module",

@@ -0,6 +1,27 @@

import { doc } from 'prettier';
import { printComments } from '../common/printer-helpers.js';
const { hardline } = doc.builders;
export const ExpressionStatement = {
print: ({ node, path, print }) => [
path.call(print, 'expression'),
node.omitSemicolon ? '' : ';'
]
print: ({ node, options, path, print }) => {
const parts = [];
const parent = path.getParentNode();
if (parent.type === 'IfStatement') {
if (node.comments?.length) {
const comments = printComments(node, path, options);
if (comments?.length) {
parts.push(comments);
parts.push(hardline);
}
}
}
parts.push(path.call(print, 'expression'));
parts.push(node.omitSemicolon ? '' : ';');
return parts;
}
};
import { doc } from 'prettier';
import { printSeparatedItem } from '../common/printer-helpers.js';
import {
printComments,
printSeparatedItem
} from '../common/printer-helpers.js';

@@ -22,5 +25,6 @@ const { group, hardline, indent, line } = doc.builders;

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 [

@@ -36,9 +40,20 @@ elseOnSameLine ? ' ' : hardline,

export const IfStatement = {
print: ({ node, path, print }) => [
'if (',
printSeparatedItem(path.call(print, 'condition')),
')',
printTrueBody(node, path, print),
printElse(node, path, print)
]
print: ({ node, options, path, print }) => {
const comments = node.comments || [];
const commentsBetweenIfAndElse = comments.filter(
(comment) => !comment.leading && !comment.trailing
);
const parts = [];
parts.push('if (', printSeparatedItem(path.call(print, 'condition')), ')');
parts.push(printTrueBody(node, path, print));
if (commentsBetweenIfAndElse.length && node.falseBody) {
parts.push(hardline);
parts.push(printComments(node, path, options));
}
parts.push(printElse(node, path, print, commentsBetweenIfAndElse));
return parts;
}
};

@@ -260,20 +260,6 @@ import { util } from "prettier";

) {
if (followingNode.type === "Block") {
if(followingNode.statements.length === 0) {
addDanglingComment(followingNode, comment);
} else {
addLeadingComment(followingNode.statements[followingNode.statements.length - 1], comment);
}
} else if (followingNode.type === "IfStatement") {
if (followingNode.trueBody.type === "Block") {
if(followingNode.trueBody.statements.length === 0) {
addDanglingComment(followingNode.trueBody, comment);
} else {
addLeadingComment(followingNode.trueBody.statements[0], comment);
}
} else {
addLeadingComment(followingNode.trueBody, comment);
}
if (precedingNode.type === "ExpressionStatement") {
addTrailingComment(precedingNode, comment);
} else {
addLeadingComment(precedingNode, comment);
addDanglingComment(enclosingNode, comment);
}

@@ -283,12 +269,4 @@ return true;

if (enclosingNode.trueBody === followingNode) {
if (followingNode.type === "Block") {
if(followingNode.statements.length === 0) {
addDanglingComment(followingNode, comment);
} else {
addLeadingComment(followingNode.statements[0], comment);
}
} else {
addLeadingComment(followingNode, comment);
}
if (followingNode.type === "ExpressionStatement") {
addBlockStatementFirstComment(followingNode, comment);
return true;

@@ -298,11 +276,3 @@ }

if (followingNode.type === "IfStatement") {
if (followingNode.trueBody.type === "Block") {
if(followingNode.trueBody.statements.length === 0) {
addDanglingComment(followingNode.trueBody, comment);
} else {
addLeadingComment(followingNode.trueBody.statements[0], comment);
}
} else {
addLeadingComment(followingNode.trueBody, comment);
}
addBlockOrNotComment(followingNode.trueBody, comment);
return true;

@@ -309,0 +279,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc