Socket
Socket
Sign inDemoInstall

@prettier/plugin-ruby

Package Overview
Dependencies
Maintainers
12
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.22.0 to 1.0.0-rc1

70

CHANGELOG.md

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

## [1.0.0-rc1] - 2020-12-09
### Changed
- [@kddeisz] - Rename options to prep for v1.0 release.
- `addTrailingCommas` -> `trailingComma`, `"es5"` means `true`
- `inlineConditionals` and `inlineLoops` -> `rubyModifier`
- `preferHashLabels` -> `rubyHashLabel`
- `preferSingleQuotes` -> `rubySingleQuote`
- `toProcTransform` -> `rubyToProc`
- [@andyw8], [@kddeisz] - Fix for Ruby `2.5.1` dyna_symbols. Turns out they were previously incorrectly reported as `xstring` nodes.
- [@andyw8], [@kddeisz] - Fix for plain `rescue` nodes with only comments in the body.
- [@andyw8], [@kddeisz] - Move declaration-type comments up to the line in the original source, as in:
```ruby
def foo # :nodoc:
bar
end
```
The comment in the above example should stay in place.
- [@janklimo] - Respect special call syntax, e.g., `a.(1, 2, 3)` should remain the same.
- [@kddeisz] - Fix up a bug with `ensure` being used in a `bodystmt` and not a `begin`.
- [@kddeisz] - Fix up a bug with negative ranges, e.g., `-4..-3`.
- [@kddeisz] - Fix up a bug with operator aliases, e.g., `alias << push`.
- [@kddeisz] - Fix up a bug with calls and unary nodes, e.g., `!!foo&.bar`.
- [@kddeisz] - Fix up a bug with multiple rescue clauses and comments, e.g.,
```ruby
begin
rescue Foo, Bar
# comment
end
```
- [@kddeisz] - Handle string literals that start with `%Q`.
- [@kddeisz] - Handle question method methods in the predicate of an if with a comment in the body.
- [@kddeisz] - Fix bare `break` with comments immediately after.
- [@kddeisz] - Fix for heredocs with comments immediately after the declaration.
- [@kddeisz] - Fix for comments when you're defining a method whose name overlaps with a keyword.
- [@kddeisz] - Don't automatically indent inside interpolated expressions from within a heredoc.
- [@kddeisz] - Don't convert into string literal arrays if the elements have brackets.
- [@kddeisz] - Ensure you break the parent when there is an assignment in the predicate of a loop.
- [@kddeisz] - Fix up a bug with keyword aliases, e.g., `alias in within`.
- [@kddeisz] - Force using braces for regex if a regex starts with a blank space.
- [@kddeisz] - Force using braces for regex if a regex starts with an equals sign.
- [@kddeisz] - Fix up a bug with constant aliases, e.g., `alias in IN`.
- [@andyw8], [@kddeisz] - Ensure `rescue` comments stay on the same line as their declaration.
# [0.22.0] - 2020-12-08

@@ -881,3 +932,4 @@

[unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.22.0...HEAD
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc1...HEAD
[1.0.0-rc1]: https://github.com/prettier/plugin-ruby/compare/v0.22.0...v1.0.0-rc1
[0.22.0]: https://github.com/prettier/plugin-ruby/compare/v0.21.0...v0.22.0

@@ -935,2 +987,3 @@ [0.21.0]: https://github.com/prettier/plugin-ruby/compare/v0.20.1...v0.21.0

[@andrewraycode]: https://github.com/AndrewRayCode
[@andyw8]: https://github.com/andyw8
[@ashfurrow]: https://github.com/ashfurrow

@@ -943,8 +996,9 @@ [@awinograd]: https://github.com/awinograd

[@codingitwrong]: https://github.com/CodingItWrong
[@coiti]: https://github.com/coiti
[@deecewan]: https://github.com/deecewan
[@dudeofawesome]: https://github.com/dudeofawesome
[@eins78]: https://github.com/eins78
[@ftes]: https://github.com/ftes
[@flyerhzm]: https://github.com/flyerhzm
[@fruetel]: https://github.com/Fruetel
[@ftes]: https://github.com/ftes
[@gin0606]: https://github.com/gin0606

@@ -958,3 +1012,5 @@ [@github0013]: https://github.com/github0013

[@janklimo]: https://github.com/janklimo
[@jbielick]: https://github.com/jbielick
[@joeyjoejoejr]: https://github.com/joeyjoejoejr
[@johncsnyder]: https://github.com/johncsnyder
[@johnschoeman]: https://github.com/johnschoeman

@@ -974,2 +1030,3 @@ [@joshuakgoldberg]: https://github.com/JoshuaKGoldberg

[@mmainz]: https://github.com/mmainz
[@mmcnl]: https://github.com/mmcnl
[@noahtheduke]: https://github.com/NoahTheDuke

@@ -980,3 +1037,7 @@ [@overload119]: https://github.com/Overload119

[@rosskinsella]: https://github.com/RossKinsella
[@rsullivan00]: https://github.com/Rsullivan00
[@ryan-hunter-pc]: https://github.com/ryan-hunter-pc
[@shaydavidson]: https://github.com/ShayDavidson
[@steobrien]: https://github.com/steobrien
[@sviccari]: https://github.com/SViccari
[@tobyndockerill]: https://github.com/tobyndockerill

@@ -986,6 +1047,1 @@ [@uri]: https://github.com/uri

[@yuki24]: https://github.com/yuki24
[@rsullivan00]: https://github.com/Rsullivan00
[@steobrien]: https://github.com/steobrien
[@jbielick]: https://github.com/jbielick
[@coiti]: https://github.com/coiti
[@johncsnyder]: https://github.com/johncsnyder

2

CONTRIBUTING.md

@@ -132,3 +132,3 @@ # Contributing

At the moment, we support back to Ruby 2.5. This is because in Ruby 2.5, Ripper got some additional public methods for accessing lexer state, which is necessary for parsing comments. This is not to say that prettier can't parse and print earlier versions of Ruby, it's just that the Ruby process running prettier (whatever `ruby` resolves to when the process runs) must be >= 2.5.
We support all Ruby versions that are under security maintenance or better (https://www.ruby-lang.org/en/downloads/branches/). This means at the moment we support back to Ruby 2.5. This is not to say that prettier can't parse and print code that was written while running earlier versions of Ruby, it's just that the Ruby process running prettier (whatever `ruby` resolves to when the process runs) must be >= 2.5.

@@ -135,0 +135,0 @@ ### Do you support ERB files (.html.erb, .js.erb, etc.)?

{
"name": "@prettier/plugin-ruby",
"version": "0.22.0",
"version": "1.0.0-rc1",
"description": "prettier plugin for the Ruby programming language",

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

@@ -125,13 +125,12 @@ <div align="center">

| API Option | CLI Option | Default | Description |
| -------------------- | ------------------------ | :-----: | ------------------------------------------------------------------------------------------------------------- |
| `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). |
| `requirePragma` | `--require-pragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)). |
| `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |
| `addTrailingCommas` | `--add-trailing-commas` | `false` | Adds a trailing comma to array literals, hash literals, and method calls. |
| `inlineConditionals` | `--inline-conditionals` | `true` | When it fits on one line, allows if and unless statements to use the modifier form. |
| `inlineLoops` | `--inline-loops` | `true` | When it fits on one line, allows while and until statements to use the modifier form. |
| `preferHashLabels` | `--prefer-hash-labels` | `true` | When possible, uses the shortened hash key syntax, as opposed to hash rockets. |
| `preferSingleQuotes` | `--prefer-single-quotes` | `true` | When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals. |
| `toProcTransform` | `--to-proc-transform` | `false` | When possible, convert blocks to the more concise `Symbol#to_proc` syntax. |
| API Option | CLI Option | Default | Description |
| ----------------- | --------------------- | :-----: | ------------------------------------------------------------------------------------------------------------------------------------ |
| `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). |
| `requirePragma` | `--require-pragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)). |
| `rubyHashLabel` | `--ruby-hash-label` | `true` | When possible, uses the shortened hash key syntax, as opposed to hash rockets. |
| `rubyModifier` | `--ruby-modifier` | `true` | When it fits on one line, allows while and until statements to use the modifier form. |
| `rubySingleQuote` | `--ruby-single-quote` | `true` | When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals. |
| `rubyToProc` | `--ruby-to-proc` | `false` | When possible, convert blocks to the more concise `Symbol#to_proc` syntax. |
| `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |
| `trailingComma` | `--trailing-comma` | `"es5"` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#trailing-comma)). `"es5"` is equivalent to `true`. |

@@ -143,3 +142,3 @@ Any of these can be added to your existing [prettier configuration

{
"preferSingleQuotes": false
"rubySingleQuote": false
}

@@ -151,3 +150,3 @@ ```

```bash
prettier --prefer-single-quotes false --write '**/*.rb'
prettier --ruby-single-quote false --write '**/*.rb'
```

@@ -187,3 +186,3 @@

<td align="center"><a href="https://janpiotrowski.de"><img src="https://avatars0.githubusercontent.com/u/183673?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jan Piotrowski</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/commits?author=janpio" title="Documentation">📖</a></td>
<td align="center"><a href="https://www.andywaite.com"><img src="https://avatars1.githubusercontent.com/u/13400?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Andy Waite</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/commits?author=andyw8" title="Documentation">📖</a></td>
<td align="center"><a href="https://www.andywaite.com"><img src="https://avatars1.githubusercontent.com/u/13400?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Andy Waite</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/commits?author=andyw8" title="Documentation">📖</a> <a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Aandyw8" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/jviney"><img src="https://avatars3.githubusercontent.com/u/7051?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan Viney</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Ajviney" title="Bug reports">🐛</a></td>

@@ -190,0 +189,0 @@ <td align="center"><a href="https://github.com/acrewdson"><img src="https://avatars0.githubusercontent.com/u/10353074?v=4?s=100" width="100px;" alt=""/><br /><sub><b>acrewdson</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Aacrewdson" title="Bug reports">🐛</a></td>

@@ -34,3 +34,3 @@ const {

const embed = (path, _print, textToDoc, _opts) => {
const embed = (path, print, textToDoc, _opts) => {
const node = path.getValue();

@@ -51,3 +51,3 @@

// example, if you use <<~CSS, we'd hook it up to the css parser.
const parser = parsers[beging.slice(3).toLowerCase()];
const parser = parsers[beging.body.slice(3).toLowerCase()];
if (!parser) {

@@ -67,5 +67,5 @@ return null;

// ourselves.
if (beging[2] === "~") {
if (beging.body[2] === "~") {
return concat([
beging,
path.call(print, "beging"),
lineSuffix(

@@ -83,3 +83,3 @@ group(

concat([
beging,
path.call(print, "beging"),
lineSuffix(group(concat([formatted, literalLineNoBreak, ending])))

@@ -86,0 +86,0 @@ ])

@@ -12,3 +12,3 @@ const {

const toProc = require("../toProc");
const { docLength } = require("../utils");
const { docLength, getTrailingComma } = require("../utils");

@@ -18,3 +18,2 @@ module.exports = {

const argsNode = path.getValue().body[0];
const { addTrailingCommas } = opts;

@@ -46,3 +45,3 @@ if (argsNode === null) {

join(concat([",", line]), args),
addTrailingCommas && !hasBlock ? ifBreak(",", "") : ""
getTrailingComma(opts) && !hasBlock ? ifBreak(",", "") : ""
];

@@ -49,0 +48,0 @@

@@ -12,2 +12,4 @@ const {

const { getTrailingComma } = require("../utils");
// Checks that every argument within this args node is a string_literal node

@@ -41,5 +43,6 @@ // that has no spaces or interpolations. This means we're dealing with an array

// Finally, verify that the string doesn't contain a space or an escape
// character so that we know it can be put into a string literal array.
return !part.body.includes(" ") && !part.body.includes("\\");
// Finally, verify that the string doesn't contain a space, an escape
// character, or brackets so that we know it can be put into a string
// literal array.
return !/[\s\\[\]]/.test(part.body);
});

@@ -158,3 +161,3 @@ }

join(concat([",", line]), path.call(print, "body", 0)),
opts.addTrailingCommas ? ifBreak(",", "") : ""
getTrailingComma(opts) ? ifBreak(",", "") : ""
])

@@ -161,0 +164,0 @@ ),

@@ -9,3 +9,3 @@ const {

} = require("../prettier");
const { concatBody, first, makeCall } = require("../utils");
const { concatBody, first, makeCall, noIndent } = require("../utils");

@@ -15,3 +15,2 @@ const toProc = require("../toProc");

const chained = ["call", "method_add_arg"];
const noIndent = ["array", "hash", "if", "method_add_block", "xstring_literal"];

@@ -26,5 +25,5 @@ function printCall(path, opts, print) {

// You can call lambdas with a special syntax that looks like func.(*args).
// In this case, "call" is returned for the 3rd child node.
const messageDoc =
messageNode === "call" ? messageNode : path.call(print, "body", 2);
// In this case, "call" is returned for the 3rd child node. We don't alter
// call syntax so if `call` is implicit, we don't print it out.
const messageDoc = messageNode === "call" ? "" : path.call(print, "body", 2);

@@ -31,0 +30,0 @@ // For certain left sides of the call nodes, we want to attach directly to

@@ -84,3 +84,3 @@ const {

function printSingle(keyword, modifier = false) {
return function printSingleWithKeyword(path, { inlineConditionals }, print) {
return function printSingleWithKeyword(path, { rubyModifier }, print) {
const [_predicateNode, statementsNode] = path.getValue().body;

@@ -101,3 +101,3 @@ const predicateDoc = path.call(print, "body", 0);

// multiline form.
if (!inlineConditionals || (!modifier && statementsNode.body[0].comments)) {
if (!rubyModifier || (!modifier && statementsNode.body[0].comments)) {
return concat([concat(multilineParts), breakParent]);

@@ -195,3 +195,3 @@ }

// A normalized print function for both `if` and `unless` nodes.
const printConditional = (keyword) => (path, { inlineConditionals }, print) => {
const printConditional = (keyword) => (path, { rubyModifier }, print) => {
if (canTernary(path)) {

@@ -245,3 +245,3 @@ let ternaryParts = [path.call(print, "body", 0), " ? "].concat(

return printSingle(keyword)(path, { inlineConditionals }, print);
return printSingle(keyword)(path, { rubyModifier }, print);
};

@@ -248,0 +248,0 @@

@@ -10,4 +10,5 @@ const {

} = require("../prettier");
const { prefix, skipAssignIndent } = require("../utils");
const { getTrailingComma, prefix, skipAssignIndent } = require("../utils");
// When attempting to convert a hash rocket into a hash label, you need to take

@@ -28,3 +29,3 @@ // care because only certain patterns are allowed. Ruby source says that they

function printHashKey(path, { preferHashLabels }, print) {
function printHashKey(path, { rubyHashLabel }, print) {
const labelNode = path.getValue().body[0];

@@ -35,3 +36,3 @@ const labelDoc = path.call(print, "body", 0);

case "@label":
if (preferHashLabels) {
if (rubyHashLabel) {
return labelDoc;

@@ -41,3 +42,3 @@ }

case "symbol_literal": {
if (preferHashLabels && isValidHashLabel(labelNode)) {
if (rubyHashLabel && isValidHashLabel(labelNode)) {
return concat([path.call(print, "body", 0, "body", 0), ":"]);

@@ -48,3 +49,3 @@ }

case "dyna_symbol":
if (preferHashLabels) {
if (rubyHashLabel) {
return concat(labelDoc.parts.slice(1).concat(":"));

@@ -106,3 +107,3 @@ }

path.call(print, "body", 0),
opts.addTrailingCommas ? ifBreak(",", "") : ""
getTrailingComma(opts) ? ifBreak(",", "") : ""
])

@@ -109,0 +110,0 @@ ),

@@ -5,3 +5,3 @@ const { concat, group, lineSuffix, join } = require("../prettier");

function printHeredoc(path, opts, print) {
const { beging, body, ending } = path.getValue();
const { body, ending } = path.getValue();

@@ -25,3 +25,3 @@ const parts = body.map((part, index) => {

concat([
beging,
path.call(print, "beging"),
lineSuffix(

@@ -28,0 +28,0 @@ group(concat([literalLineNoBreak].concat(parts).concat(ending)))

@@ -20,7 +20,9 @@ const { concat, group, indent, line } = require("../prettier");

return function printHookWithName(path, opts, print) {
const stmtsNode = path.getValue().body[0];
const printedStmts = path.call(print, "body", 0);
const stmtsNode = path.getValue().body[1];
const printedStmts = path.call(print, "body", 1);
const parts = [
`${name} {`,
name,
" ",
path.call(print, "body", 0),
indent(concat([line, printedStmts])),

@@ -27,0 +29,0 @@ concat([line, "}"])

const {
align,
breakParent,
concat,

@@ -14,3 +15,3 @@ group,

const printLoop = (keyword, modifier) => (path, { inlineLoops }, print) => {
const printLoop = (keyword, modifier) => (path, { rubyModifier }, print) => {
const [_predicate, stmts] = path.getValue().body;

@@ -70,4 +71,4 @@

// use the modifier form and we must use the block form.
if (!inlineLoops || containsAssignment(path.getValue().body[0])) {
return blockLoop;
if (!rubyModifier || containsAssignment(path.getValue().body[0])) {
return concat([breakParent, blockLoop]);
}

@@ -74,0 +75,0 @@

@@ -31,3 +31,5 @@ const { concat, group, hardline, indent } = require("../prettier");

const stmts = body.body[0].body;
if (
!body.body.slice(1).some((node) => node) &&
stmts.length === 1 &&

@@ -34,0 +36,0 @@ stmts[0].type === "void_stmt" &&

const { concat, group, indent, line, softline } = require("../prettier");
const { noIndent } = require("../utils");
function printBinary(path, opts, print) {
const operator = path.getValue().body[1];
const useNoSpace = operator === "**";
const [_leftNode, operator, rightNode] = path.getValue().body;
const space = operator === "**" ? "" : " ";
if (noIndent.includes(rightNode.type)) {
return group(
concat([
group(path.call(print, "body", 0)),
space,
operator,
space,
group(path.call(print, "body", 2))
])
);
}
return group(
concat([
group(path.call(print, "body", 0)),
indent(
concat([
useNoSpace ? "" : " ",
group(
concat([
operator,
useNoSpace ? softline : line,
path.call(print, "body", 2)
])
)
])
space,
group(
indent(
concat([
operator,
space === "" ? softline : line,
path.call(print, "body", 2)
])
)
)

@@ -22,0 +33,0 @@ ])

const { concat } = require("../prettier");
function isStringContent(node) {
return node.type === "@tstring_content";
}
function shouldUseBraces(node) {
const first = node.body[0];
// If the first part of this regex is plain string content and we have a
// space or an =, then we want to use braces because otherwise we could end up
// with an ambiguous operator, e.g. foo / bar/ or foo /=bar/
if (first && isStringContent(first) && [" ", "="].includes(first.body[0])) {
return true;
}
return node.body.some(
(child) => isStringContent(child) && child.body.includes("/")
);
}
// This function is responsible for printing out regexp_literal nodes. They can

@@ -11,12 +30,8 @@ // either use the special %r literal syntax or they can use forward slashes. At

function printRegexpLiteral(path, opts, print) {
const { ending } = path.getValue();
const contents = path.map(print, "body");
const node = path.getValue();
const useBraces = shouldUseBraces(node);
const useBraces = contents.some(
(content) => typeof content === "string" && content.includes("/")
);
const parts = [useBraces ? "%r{" : "/"]
.concat(contents)
.concat([useBraces ? "}" : "/", ending.slice(1)]);
.concat(path.map(print, "body"))
.concat([useBraces ? "}" : "/", node.ending.slice(1)]);

@@ -23,0 +38,0 @@ return concat(parts);

@@ -23,4 +23,4 @@ const {

return concat([
"ensure",
indent(concat([hardline, concat(path.map(print, "body"))]))
path.call(print, "body", 0),
indent(concat([hardline, path.call(print, "body", 1)]))
]);

@@ -27,0 +27,0 @@ }

@@ -15,31 +15,41 @@ const {

module.exports = {
"@__end__": (path, _opts, _print) => {
const { body } = path.getValue();
return concat([trim, "__END__", literalline, body]);
},
bodystmt: (path, opts, print) => {
const [_statements, rescue, elseClause, ensure] = path.getValue().body;
const parts = [path.call(print, "body", 0)];
function printBodyStmt(path, opts, print) {
const [stmts, rescue, elseClause, ensure] = path.getValue().body;
const parts = [];
if (rescue) {
parts.push(dedent(concat([hardline, path.call(print, "body", 1)])));
}
if (
stmts.body.length > 1 ||
stmts.body[0].type != "void_stmt" ||
stmts.body[0].comments
) {
parts.push(path.call(print, "body", 0));
}
if (elseClause) {
// Before Ruby 2.6, this piece of bodystmt was an explicit "else" node
const stmts =
elseClause.type === "else"
? path.call(print, "body", 2, "body", 0)
: path.call(print, "body", 2);
if (rescue) {
parts.push(dedent(concat([hardline, path.call(print, "body", 1)])));
}
parts.push(concat([dedent(concat([hardline, "else"])), hardline, stmts]));
}
if (elseClause) {
// Before Ruby 2.6, this piece of bodystmt was an explicit "else" node
const stmts =
elseClause.type === "else"
? path.call(print, "body", 2, "body", 0)
: path.call(print, "body", 2);
if (ensure) {
parts.push(dedent(concat([hardline, path.call(print, "body", 3)])));
}
parts.push(concat([dedent(concat([hardline, "else"])), hardline, stmts]));
}
return group(concat(parts));
if (ensure) {
parts.push(dedent(concat([hardline, path.call(print, "body", 3)])));
}
return group(concat(parts));
}
module.exports = {
"@__end__": (path, _opts, _print) => {
const { body } = path.getValue();
return concat([trim, "__END__", literalline, body]);
},
bodystmt: printBodyStmt,
paren: (path, opts, print) => {

@@ -46,0 +56,0 @@ if (!path.getValue().body[0]) {

@@ -69,3 +69,3 @@ const {

const boundary = /%q?(.)/.exec(quote)[1];
const boundary = /%[Qq]?(.)/.exec(quote)[1];
if (boundary in quotePairs) {

@@ -81,3 +81,3 @@ return quotePairs[boundary];

// correct quotes.
function printChar(path, { preferSingleQuotes }, _print) {
function printChar(path, { rubySingleQuote }, _print) {
const { body } = path.getValue();

@@ -89,3 +89,3 @@

const quote = preferSingleQuotes ? "'" : '"';
const quote = rubySingleQuote ? "'" : '"';
return concat([quote, body.slice(1), quote]);

@@ -113,3 +113,3 @@ }

// quotes.
function printStringLiteral(path, { preferSingleQuotes }, print) {
function printStringLiteral(path, { rubySingleQuote }, print) {
const node = path.getValue();

@@ -120,3 +120,3 @@

if (node.body.length === 0) {
return preferSingleQuotes ? "''" : '""';
return rubySingleQuote ? "''" : '""';
}

@@ -129,3 +129,3 @@

} else {
quote = preferSingleQuotes && isSingleQuotable(node) ? "'" : '"';
quote = rubySingleQuote && isSingleQuotable(node) ? "'" : '"';
}

@@ -176,6 +176,7 @@

// If the interpolated expression is inside of an xstring literal (a string
// that gets sent to the command line) then we don't want to automatically
// indent, as this can lead to some very odd looking expressions
if (path.getParentNode().type === "xstring_literal") {
// If the interpolated expression is inside of a heredoc or an xstring
// literal (a string that gets sent to the command line) then we don't want
// to automatically indent, as this can lead to some very odd looking
// expressions
if (["heredoc", "xstring_literal"].includes(path.getParentNode().type)) {
return concat(["#{", parts, "}"]);

@@ -182,0 +183,0 @@ }

@@ -43,4 +43,6 @@ const { concat, trim } = require("./prettier");

switch (node.type) {
case "heredoc":
return [node.beging];
case "rescue":
return node.body[0].concat(node.body.slice(1));
return [].concat(node.body[0]).concat(node.body.slice(1));
case "aryptn":

@@ -47,0 +49,0 @@ return [node.body[0]]

@@ -79,17 +79,10 @@ const printer = require("./printer");

options: {
addTrailingCommas: {
rubyHashLabel: {
type: "boolean",
category: "Global",
default: false,
description:
"Adds a trailing comma to array literals, hash literals, and method calls."
},
inlineConditionals: {
type: "boolean",
category: "Global",
default: true,
description:
"When it fits on one line, allows if and unless statements to use the modifier form."
"When possible, uses the shortened hash key syntax, as opposed to hash rockets."
},
inlineLoops: {
rubyModifier: {
type: "boolean",

@@ -99,5 +92,5 @@ category: "Global",

description:
"When it fits on one line, allows while and until statements to use the modifier form."
"When it fits on one line, allows if, unless, while, and until statements to use the modifier form."
},
preferHashLabels: {
rubySingleQuote: {
type: "boolean",

@@ -107,12 +100,5 @@ category: "Global",

description:
"When possible, uses the shortened hash key syntax, as opposed to hash rockets."
},
preferSingleQuotes: {
type: "boolean",
category: "Global",
default: true,
description:
"When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals."
},
toProcTransform: {
rubyToProc: {
type: "boolean",

@@ -127,4 +113,5 @@ category: "Global",

printWidth: 80,
tabWidth: 2
tabWidth: 2,
trailingComma: "none"
}
};

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

const toProc = (path, opts, node) => {
if (!node || !opts.toProcTransform) {
if (!node || !opts.rubyToProc) {
return null;

@@ -18,0 +18,0 @@ }

@@ -34,2 +34,4 @@ const { concat } = require("./prettier");

const getTrailingComma = (opts) => ["all", "es5"].includes(opts.trailingComma);
const hasAncestor = (path, types) => {

@@ -63,2 +65,11 @@ let parent = 0;

const noIndent = [
"array",
"hash",
"heredoc",
"if",
"method_add_block",
"xstring_literal"
];
const prefix = (value) => (path, opts, print) =>

@@ -78,2 +89,3 @@ concat([value, path.call(print, "body", 0)]);

first,
getTrailingComma,
hasAncestor,

@@ -84,4 +96,5 @@ isEmptyStmts,

makeCall,
noIndent,
prefix,
skipAssignIndent
};

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

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