Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@prettier/plugin-ruby

Package Overview
Dependencies
Maintainers
9
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prettier/plugin-ruby - npm Package Compare versions

Comparing version 0.3.3 to 0.3.4

12

CHANGELOG.md

@@ -9,2 +9,11 @@ # Changelog

## [0.3.4] - 2019-02-09
### Changed
- Comments are now properly attached inside `defs` nodes.
- Support multiple inline comments on nodes.
- Support inline comments from within the `EXPR_END|EXPR_LABEL` lexer state.
- Stop transforming multistatement blocks with `to_proc`. (Thanks to @cbothner.)
- `do` blocks necessarily need to break their parent nodes.
- Handle `next` node edge case with `args_add` as the body. (Thanks to @eins78 for the report.)
## [0.3.3] - 2019-02-09

@@ -79,3 +88,4 @@ ### Changed

[Unreleased]: https://github.com/CultureHQ/add-to-calendar/compare/0.3.3...HEAD
[Unreleased]: https://github.com/CultureHQ/add-to-calendar/compare/0.3.4...HEAD
[0.3.4]: https://github.com/CultureHQ/add-to-calendar/compare/v0.3.3...v0.3.4
[0.3.3]: https://github.com/CultureHQ/add-to-calendar/compare/v0.3.2...v0.3.3

@@ -82,0 +92,0 @@ [0.3.2]: https://github.com/CultureHQ/add-to-calendar/compare/v0.3.1...v0.3.2

2

package.json
{
"name": "@prettier/plugin-ruby",
"version": "0.3.3",
"version": "0.3.4",
"description": "prettier plugin for the Ruby programming language",

@@ -5,0 +5,0 @@ "main": "src/ruby.js",

@@ -132,3 +132,3 @@ <div align="center">

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
The package is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

@@ -135,0 +135,0 @@ ## Maintainers

const { align, breakParent, concat, dedent, dedentToRoot, group, hardline, ifBreak, indent, join, line, lineSuffix, literalline, markAsRoot, softline, trim } = require("prettier").doc.builders;
const { concatBody, empty, first, literal, makeCall, prefix, skipAssignIndent, surround } = require("./utils");
const { concatBody, empty, first, literal, makeCall, prefix, printComments, skipAssignIndent, surround } = require("./utils");

@@ -98,9 +98,10 @@ module.exports = {

if (preferHashLabels && path.getValue().body[0].body.length === 1) {
const { comment } = path.getValue().body[0];
const { comments, start } = path.getValue().body[0];
const node = concat([path.call(print, "body", 0, "body", 0, "body", 0), ":"]);
parts.push(concat([
path.call(print, "body", 0, "body", 0, "body", 0),
":",
comment ? lineSuffix(` ${comment.body}`) : ""
]));
if (comments) {
parts.push(printComments(node, start, comments));
} else {
parts.push(node);
}
} else {

@@ -422,2 +423,6 @@ parts.push(concat([printedLabel, " =>"]));

if (path.getValue().body[0].type === "args_add") {
return concat(["next ", path.call(print, "body", 0)]);
}
if (args.body[1].type !== "paren") {

@@ -424,0 +429,0 @@ return concat(["next ", path.call(print, "body", 0)]);

@@ -1,2 +0,2 @@

const { concat, group, ifBreak, indent, softline } = require("prettier").doc.builders;
const { breakParent, concat, group, ifBreak, indent, softline } = require("prettier").doc.builders;

@@ -17,3 +17,3 @@ const isCall = node => ["::", "."].includes(node) || node.type === "@period";

const toProcTransform = (path, opts, print) => {
const [variables, statements] = path.getValue().body;
const [variables, blockContents] = path.getValue().body;

@@ -27,32 +27,45 @@ // Ensure that there are variables being passed to this block.

// Ensure there is one and only one parameter, and that it is required.
const reqParams = params.body[0];
if (params.body.slice(1).some(varType => varType) || reqParams.length !== 1) {
const [reqParams, ...other] = params.body;
if (!Array.isArray(reqParams) || reqParams.length !== 1 || other.some(Boolean)) {
return;
}
let callBody;
let statements;
if (blockContents.type === "bodystmt") {
// We’re in a `do` block
const [blockStatements, ...rescueElseEnsure] = blockContents.body;
// If the statement types match this pattern, we're in a brace block with an
// eligible block.
if (statements.body.length === 1 && statements.body[0].type === "call") {
callBody = statements.body[0].body;
// You can’t use the to_proc shortcut if you’re rescuing
if (rescueElseEnsure.some(Boolean)) {
return;
}
statements = blockStatements;
} else {
// We’re in a brace block
statements = blockContents;
}
// If the statement types match this pattern, we're in a `do` block with an
// eligible block.
const statementTypes = statements.body.map(statement => statement && statement.type);
if (statementTypes.length === 4 && statementTypes[0] === "stmts" && statementTypes.slice(1).every(statementType => !statementType)) {
callBody = statements.body[0].body[0].body;
// Ensure the block contains only one statement
if (statements.body.length !== 1) {
return;
}
// If we have a call, then we can compare to ensure the variables are the
// same.
// Ensure that statement is a call
const [statement] = statements.body;
if (statement.type !== "call") {
return;
}
// Ensure the call is a method of the block argument
const [varRef, call, method, args] = statement.body;
if (
callBody && callBody[0] && callBody[0].type === "var_ref"
&& callBody[0].body[0].body === reqParams[0].body
&& isCall(callBody[1])
&& callBody[2].type === "@ident"
&& !callBody[3]
varRef.type === "var_ref" &&
varRef.body[0].body === reqParams[0].body &&
isCall(call) &&
method.type === "@ident" &&
!args
) {
return `(&:${callBody[2].body})`;
return `(&:${method.body})`;
}

@@ -79,4 +92,4 @@ };

const stmts = statements.type === "stmts" ? statements.body : statements.body[0].body;
if (stmts.length > 1 && (stmts.filter(stmt => stmt.type !== "@comment").length === 1)) {
return doBlock;
if (stmts.length > 1 && stmts.filter(stmt => stmt.type !== "@comment").length === 1) {
return concat([breakParent, doBlock]);
}

@@ -87,3 +100,3 @@

if (path.getParentNode().body[0].type === "command") {
return doBlock;
return concat([breakParent, doBlock]);
}

@@ -90,0 +103,0 @@

const { breakParent, concat, hardline, lineSuffix } = require("prettier").doc.builders;
const { printComments } = require("./utils");
const nodes = require("./nodes");
module.exports = (path, opts, print) => {
const { type, body, comment, start } = path.getValue();
const { type, body, comments, start } = path.getValue();

@@ -10,17 +11,4 @@ if (type in nodes) {

if (comment) {
if (comment.start < start) {
return concat([
comment.break ? breakParent : "",
comment.body,
hardline,
printed
]);
}
return concat([
printed,
comment.break ? breakParent : "",
lineSuffix(` ${comment.body}`)
]);
if (comments) {
return printComments(printed, start, comments);
}

@@ -27,0 +15,0 @@ return printed;

@@ -1,2 +0,2 @@

const { concat } = require("prettier").doc.builders;
const { breakParent, concat, hardline, lineSuffix } = require("prettier").doc.builders;

@@ -20,2 +20,25 @@ const concatBody = (path, opts, print) => concat(path.map(print, "body"));

const printComments = (printed, start, comments) => {
let node = printed;
comments.forEach(comment => {
if (comment.start < start) {
node = concat([
comment.break ? breakParent : "",
comment.body,
hardline,
node
]);
} else {
node = concat([
node,
comment.break ? breakParent : "",
lineSuffix(` ${comment.body}`)
]);
}
});
return node;
};
const skipAssignIndent = node => (

@@ -40,4 +63,5 @@ ["array", "hash", "heredoc"].includes(node.type)

prefix,
printComments,
skipAssignIndent,
surround
};

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