Socket
Socket
Sign inDemoInstall

@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.7.0 to 0.8.0

.all-contributorsrc

23

CHANGELOG.md

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

## [0.8.0] - 2019-03-08
### Added
- [INTERNAL] Add `eslint` and fix up existing violations.
- Add the infra for the `prettier` ruby gem. (Thanks to @AlanFoster.)
- Add a `rake` task for easier process integration for the ruby gem.
- Handle direct interpolation of strings with %w array literals (i.e., `["#{foo}"]` should not be transformed into a %w array).
### Changed
- Fix string escaping for hex digit bit patterns when there's only one character after the "x".
- Don't allow line breaks between brace block params. (Thanks to @AlanFoster.)
- [INTERNAL] Switch over the array.rb test case to minitest. (Thanks to @johnschoeman.)
- [INTERNAL] Test improvements to allow running in parallel. (Thanks to @AlanFoster.)
- [INTERNAL] Switch over assign.rb test case to minitest. (Thanks to @johnschoeman.)
- [INTERNAL] Add a contributing guide. (Thanks to @AlanFoster.)
- Handle longer command nodes. (Thanks to @AlanFoster.)
- Changed the ruby executable within the `prettier` gem to `rbprettier` for easier autocomplete.
### Removed
- All instances of the spread (`...`) operator so that we can support older versions of node.
## [0.7.0] - 2019-02-24

@@ -186,3 +206,4 @@ ### Changed

[Unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.7.0...HEAD
[Unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.8.0...HEAD
[0.8.0]: https://github.com/prettier/plugin-ruby/compare/v0.7.0...v0.8.0
[0.7.0]: https://github.com/prettier/plugin-ruby/compare/v0.6.3...v0.7.0

@@ -189,0 +210,0 @@ [0.6.3]: https://github.com/prettier/plugin-ruby/compare/v0.6.2...v0.6.3

22

package.json
{
"name": "@prettier/plugin-ruby",
"version": "0.7.0",
"version": "0.8.0",
"description": "prettier plugin for the Ruby programming language",
"main": "src/ruby.js",
"scripts": {
"test": "jest",
"build": "pkg --output pkg/prettier --targets=linux,macos,win node_modules/prettier/bin-prettier.js",
"lint": "eslint .",
"print": "prettier --plugin=.",
"rubocop": "run() { prettier --plugin=. $@ | bundle exec rubocop --stdin $1; }; run"
"rubocop": "run() { prettier --plugin=. $@ | bundle exec rubocop --stdin $1; }; run",
"test": "jest"
},

@@ -25,7 +27,15 @@ "repository": {

"devDependencies": {
"jest": "^24.0.0"
"all-contributors-cli": "^6.1.2",
"eslint": "^5.15.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.16.0",
"jest": "^24.0.0",
"pkg": "^4.3.7"
},
"engines": {
"node": ">=8.3.0"
"jest": {
"setupFiles": [
"./test/testRunner.js"
],
"testRegex": ".test.js$"
}
}
<div align="center">
<img alt="Prettier" height="124px" src="https://cdn.rawgit.com/prettier/prettier-logo/master/images/prettier-icon-light.svg">
<img alt="Ruby" height="124px" vspace="" hspace="25" src="https://www.ruby-lang.org/images/header-ruby-logo@2x.png">
<img alt="Prettier Ruby" height="256px" src="./docs/logo.png">
</div>

@@ -134,33 +133,20 @@

## Development
## Contributing
After checking out the repo, run `yarn` and `bundle` to install dependencies. Then, run `yarn test` to run the tests. You can pretty print a Ruby source file by running `yarn print [PATH]`.
Check out our [contributing guide](CONTRIBUTING.md). Bug reports and pull requests are welcome on GitHub at https://github.com/prettier/plugin-ruby.
Useful resources for understanding the AST structure are:
## License
- https://github.com/ruby/ruby/blob/trunk/parse.y - the Ruby parser that will give you the names of the nodes as well as their structure
- https://github.com/ruby/ruby/blob/trunk/test/ripper/test_parser_events.rb - the test file that gives you code examples of each kind of node
The package is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Contributing
## Contributors
Bug reports and pull requests are welcome on GitHub at https://github.com/prettier/plugin-ruby.
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
## License
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
<table><tr><td align="center"><a href="https://kevindeisz.com"><img src="https://avatars2.githubusercontent.com/u/5093358?v=4" width="100px;" alt="Kevin Deisz"/><br /><sub><b>Kevin Deisz</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Code">💻</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Documentation">📖</a> <a href="#maintenance-kddeisz" title="Maintenance">🚧</a> <a href="#review-kddeisz" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Tests">⚠️</a></td><td align="center"><a href="https://www.alanfoster.me/"><img src="https://avatars2.githubusercontent.com/u/1271782?v=4" width="100px;" alt="Alan Foster"/><br /><sub><b>Alan Foster</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Code">💻</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Documentation">📖</a> <a href="#review-AlanFoster" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/johnschoeman"><img src="https://avatars0.githubusercontent.com/u/16049495?v=4" width="100px;" alt="johnschoeman"/><br /><sub><b>johnschoeman</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=johnschoeman" title="Tests">⚠️</a></td><td align="center"><a href="https://twitter.com/aaronjensen"><img src="https://avatars3.githubusercontent.com/u/8588?v=4" width="100px;" alt="Aaron Jensen"/><br /><sub><b>Aaron Jensen</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=aaronjensen" title="Documentation">📖</a></td><td align="center"><a href="http://cameronbothner.com"><img src="https://avatars1.githubusercontent.com/u/4642599?v=4" width="100px;" alt="Cameron Bothner"/><br /><sub><b>Cameron Bothner</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=cbothner" title="Code">💻</a></td></tr></table>
The package is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
<!-- ALL-CONTRIBUTORS-LIST:END -->
## Maintainers
<table>
<tbody>
<tr>
<td align="center">
<a href="https://github.com/kddeisz">
<img width="150" height="150" src="https://github.com/kddeisz.png?v=3&s=150">
</br>
Kevin Deisz
</a>
</td>
</tr>
<tbody>
</table>
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

@@ -34,13 +34,13 @@ /**

const patterns = [
"[abtnvfres\\\\]", // simple
"\\d{3}", // octal bits
"x[0-9a-fA-F]{2}", // hex bit
"u[0-9a-fA-F]{4}", // unicode char
"[abtnvfres\\\\]", // simple
"[0-7]{1,3}", // octal bits
"x[0-9a-fA-F]{1,2}", // hex bit
"u[0-9a-fA-F]{4}", // unicode char
"u\\{[0-9a-fA-F ]+\\}", // unicode chars
"c[ -~]|C\\-[ -~]", // control
"M\\-[ -~]", // meta
"c[ -~]|C\\-[ -~]", // control
"M\\-[ -~]", // meta
"M\\-\\\\C\\-[ -~]|M\\-\\\\c[ -~]|c\\\\M\\-[ -~]", // meta control
"c\\?|C\\-\\?" // delete
"c\\?|C\\-\\?" // delete
];
module.exports = new RegExp(`\\\\(${patterns.join("|")})`);

@@ -1,20 +0,11 @@

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, makeList, prefix, printComments, skipAssignIndent, surround } = require("./utils");
const { align, breakParent, concat, dedent, group, hardline, ifBreak, indent, join, line, literalline, markAsRoot, softline, trim } = require("prettier").doc.builders;
const { removeLines } = require("prettier").doc.utils;
const { concatBody, docLength, empty, first, literal, makeCall, makeList, prefix, printComments, skipAssignIndent } = require("./utils");
module.exports = {
...require("./nodes/alias"),
...require("./nodes/arrays"),
...require("./nodes/blocks"),
...require("./nodes/conditionals"),
...require("./nodes/hooks"),
...require("./nodes/loops"),
...require("./nodes/methods"),
...require("./nodes/params"),
...require("./nodes/regexp"),
...require("./nodes/strings"),
"@int": (path, opts, print) => {
const nodes = {
"@int": (path, _opts, _print) => {
const { body } = path.getValue();
return /^0[0-9]/.test(body) ? `0o${body.slice(1)}` : body;
},
"@__end__": (path, opts, print) => {
"@__end__": (path, _opts, _print) => {
const { body } = path.getValue();

@@ -39,3 +30,3 @@ return concat([trim, "__END__", literalline, body]);

concat([softline, ")"])
]))
]));
},

@@ -53,4 +44,4 @@ args: makeList,

args_add_star: (path, opts, print) => {
const [before, star, ...after] = path.map(print, "body");
const parts = [...before, concat(["*", star]), ...after];
const printed = path.map(print, "body");
const parts = printed[0].concat([concat(["*", printed[1]])]).concat(printed.slice(2));

@@ -86,3 +77,3 @@ return parts;

default:
parts.push(concat([printedLabel, " =>"]))
parts.push(concat([printedLabel, " =>"]));
break;

@@ -100,15 +91,16 @@ }

assoc_splat: prefix("**"),
assoclist_from_args: (path, opts, print) => group(
join(concat([",", line]),
path.map(print, "body", 0))
),
assoclist_from_args: (path, opts, print) => group(join(
concat([",", line]),
path.map(print, "body", 0)
)),
assign: (path, opts, print) => {
let [printedTarget, printedValue] = path.map(print, "body");
const [printedTarget, printedValue] = path.map(print, "body");
let adjustedValue = printedValue;
if (["mrhs_add_star", "mrhs_new_from_args"].includes(path.getValue().body[1].type)) {
printedValue = group(join(concat([",", line]), printedValue));
adjustedValue = group(join(concat([",", line]), printedValue));
}
if (skipAssignIndent(path.getValue().body[1])) {
return group(concat([printedTarget, " = ", printedValue]));
return group(concat([printedTarget, " = ", adjustedValue]));
}

@@ -119,6 +111,6 @@

" =",
indent(concat([line, printedValue]))
indent(concat([line, adjustedValue]))
]));
},
assign_error: (path, opts, print) => {
assign_error: (_path, _opts, _print) => {
throw new Error("Can't set variable");

@@ -144,6 +136,6 @@ },

},
block_var: (path, opts, print) => concat(["|", path.call(print, "body", 0), "| "]),
block_var: (path, opts, print) => concat(["|", removeLines(path.call(print, "body", 0)), "| "]),
blockarg: (path, opts, print) => concat(["&", path.call(print, "body", 0)]),
bodystmt: (path, opts, print) => {
const [statements, rescue, elseClause, ensure] = path.getValue().body;
const [_statements, rescue, elseClause, ensure] = path.getValue().body;
const parts = [path.call(print, "body", 0)];

@@ -192,3 +184,3 @@

path.call(print, "body", 0),
indent(concat([softline, makeCall(path, opts, print), name])),
indent(concat([softline, makeCall(path, opts, print), name]))
]));

@@ -230,3 +222,3 @@ },

},
class_name_error: (path, opts, print) => {
class_name_error: (_path, _opts, _print) => {
throw new Error("class/module name must be CONSTANT");

@@ -259,4 +251,4 @@ },

return group(ifBreak(
concat([...parts, align(parts.reduce((sum, part) => sum + part.length, 0), args)]),
concat([...parts, args])
concat(parts.concat([align(docLength(concat(parts)), args)])),
concat(parts.concat([args]))
));

@@ -296,3 +288,3 @@ },

},
embdoc: (path, opts, print) => concat([trim, path.getValue().body]),
embdoc: (path, _opts, _print) => concat([trim, path.getValue().body]),
ensure: (path, opts, print) => group(concat([

@@ -310,3 +302,3 @@ "ensure",

if (path.getValue().body[0] === null) {
return '{}';
return "{}";
}

@@ -319,3 +311,3 @@

concat(path.map(print, "body")),
addTrailingCommas ? ifBreak(",", "") : "",
addTrailingCommas ? ifBreak(",", "") : ""
])),

@@ -332,3 +324,3 @@ concat([line, "}"])

} else {
params = params.body[0];
([params] = params.body);
paramsConcat = path.call(print, "body", 0, "body", 0);

@@ -352,3 +344,3 @@ }

"lambda {",
noParams ? "" : concat([" |", paramsConcat, "|"]),
noParams ? "" : concat([" |", removeLines(paramsConcat), "|"]),
indent(concat([line, path.call(print, "body", 1)])),

@@ -364,3 +356,3 @@ concat([line, "}"])

"lambda do",
noParams ? "" : concat([" |", paramsConcat, "|"]),
noParams ? "" : concat([" |", removeLines(paramsConcat), "|"]),
indent(concat([softline, path.call(print, "body", 1)])),

@@ -394,14 +386,14 @@ concat([softline, "end"])

mlhs: makeList,
mlhs_add_post: (path, opts, print) => [
...path.call(print, "body", 0),
...path.call(print, "body", 1)
],
mlhs_add_star: (path, opts, print) => [
...path.call(print, "body", 0),
path.getValue().body[1] ? concat(["*", path.call(print, "body", 1)]) : "*"
],
mlhs_add_post: (path, opts, print) => (
path.call(print, "body", 0).concat(path.call(print, "body", 1))
),
mlhs_add_star: (path, opts, print) => (
path.call(print, "body", 0).concat([
path.getValue().body[1] ? concat(["*", path.call(print, "body", 1)]) : "*"
])
),
mlhs_paren: (path, opts, print) => {
if (["massign", "mlhs_paren"].includes(path.getParentNode().type)) {
// If we're nested in brackets as part of the left hand side of an assignment
// (a, b, c) = 1, 2, 3
// If we're nested in brackets as part of the left hand side of an
// assignment, i.e., (a, b, c) = 1, 2, 3
// ignore the current node and just go straight to the content

@@ -415,9 +407,8 @@ return path.call(print, "body", 0);

concat([softline, ")"])
]))
]));
},
mrhs: makeList,
mrhs_add_star: (path, opts, print) => [
...path.call(print, "body", 0),
concat(["*", path.call(print, "body", 1)])
],
mrhs_add_star: (path, opts, print) => (
path.call(print, "body", 0).concat([concat(["*", path.call(print, "body", 1)])])
),
mrhs_new_from_args: (path, opts, print) => {

@@ -552,3 +543,3 @@ const parts = path.call(print, "body", 0);

const parts = [];
let line = null;
let lineNo = null;

@@ -562,7 +553,7 @@ path.getValue().body.forEach((stmt, index) => {

if (line === null) {
if (lineNo === null) {
parts.push(printed);
} else if (stmt.start - line > 1) {
} else if (stmt.start - lineNo > 1) {
parts.push(hardline, hardline, printed);
} else if (stmt.start !== line || path.getParentNode().type !== "string_embexpr") {
} else if (stmt.start !== lineNo || path.getParentNode().type !== "string_embexpr") {
parts.push(hardline, printed);

@@ -573,3 +564,3 @@ } else {

line = stmt.end;
lineNo = stmt.end;
});

@@ -643,1 +634,16 @@

};
module.exports = Object.assign(
{},
require("./nodes/alias"),
require("./nodes/arrays"),
require("./nodes/blocks"),
require("./nodes/conditionals"),
require("./nodes/hooks"),
require("./nodes/loops"),
require("./nodes/methods"),
require("./nodes/params"),
require("./nodes/regexp"),
require("./nodes/strings"),
nodes
);

@@ -12,3 +12,3 @@ const { concat, join } = require("prettier").doc.builders;

const aliasError = (path, opts, print) => {
const aliasError = (_path, _opts, _print) => {
throw new Error("can't make alias for the number variables");

@@ -24,5 +24,3 @@ };

const alias = (path, opts, print) => {
return concat(["alias ", aliasVars(path, opts, print)]);
};
const alias = (path, opts, print) => concat(["alias ", aliasVars(path, opts, print)]);

@@ -29,0 +27,0 @@ module.exports = {

@@ -6,2 +6,3 @@ const { concat, group, ifBreak, indent, join, line, softline } = require("prettier").doc.builders;

&& arg.body[0].body.length === 1
&& arg.body[0].body[0].type === "@tstring_content"
&& !arg.body[0].body[0].body.includes(" ")

@@ -14,3 +15,5 @@ ));

const makeArray = start => (path, opts, print) => [start, ...path.map(print, "body")];
const makeArray = start => (path, opts, print) => (
[start].concat(path.map(print, "body"))
);

@@ -31,6 +34,6 @@ const getSpecialArrayParts = (path, print, args) => args.body.map((_arg, index) => (

const printSpecialArray = ([first, ...rest]) => group(concat([
first,
const printSpecialArray = parts => group(concat([
parts[0],
"[",
indent(concat([softline, join(line, rest)])),
indent(concat([softline, join(line, parts.slice(1))])),
concat([softline, "]"])

@@ -52,11 +55,11 @@ ]));

if (args === null) {
return '[]';
return "[]";
}
if (isStringArray(args)) {
return printSpecialArray(["%w", ...getSpecialArrayParts(path, print, args)]);
return printSpecialArray(["%w"].concat(getSpecialArrayParts(path, print, args)));
}
if (isSymbolArray(args)) {
return printSpecialArray(["%i", ...getSpecialArrayParts(path, print, args)]);
return printSpecialArray(["%i"].concat(getSpecialArrayParts(path, print, args)));
}

@@ -63,0 +66,0 @@

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

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

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

// This additionally works with `do` blocks as well.
const toProcTransform = (path, opts, print) => {
const toProcTransform = path => {
const [variables, blockContents] = path.getValue().body;

@@ -23,9 +23,10 @@

if (!params || params.type !== "params") {
return;
return null;
}
// Ensure there is one and only one parameter, and that it is required.
const [reqParams, ...other] = params.body;
if (!Array.isArray(reqParams) || reqParams.length !== 1 || other.some(Boolean)) {
return;
const reqParams = params.body[0];
const otherParams = params.body.slice(1);
if (!Array.isArray(reqParams) || reqParams.length !== 1 || otherParams.some(Boolean)) {
return null;
}

@@ -36,7 +37,8 @@

// We’re in a `do` block
const [blockStatements, ...rescueElseEnsure] = blockContents.body;
const blockStatements = blockContents.body[0];
const rescueElseEnsure = blockStatements.body.slice(1);
// You can’t use the to_proc shortcut if you’re rescuing
if (rescueElseEnsure.some(Boolean)) {
return;
return null;
}

@@ -52,3 +54,3 @@

if (statements.body.length !== 1) {
return;
return null;
}

@@ -59,3 +61,3 @@

if (statement.type !== "call") {
return;
return null;
}

@@ -67,7 +69,7 @@

if (
varRef.type === "var_ref" &&
varRef.body[0].body === reqParams[0].body &&
isCall(call) &&
method.type === "@ident" &&
!args
varRef.type === "var_ref"
&& varRef.body[0].body === reqParams[0].body
&& isCall(call)
&& method.type === "@ident"
&& !args
) {

@@ -80,6 +82,8 @@ if (["command", "command_call"].includes(path.getParentNode().body[0].type)) {

}
return null;
};
const printBlock = (path, opts, print) => {
const toProcResponse = toProcTransform(path, opts, print);
const toProcResponse = toProcTransform(path);
if (toProcResponse) {

@@ -86,0 +90,0 @@ return toProcResponse;

@@ -50,9 +50,8 @@ const { align, breakParent, concat, hardline, group, ifBreak, indent, softline } = require("prettier").doc.builders;

const forceBreak = stmts.body.every(({ type }) => ["void_stmt", "@comment"].includes(type)) ? breakParent : "";
const ternary = printTernaryConditions(keyword, truthyValue, falsyValue);
return group(ifBreak(
printWithAddition(keyword, path, print),
concat([
stmts.body.every(({ type }) => ["void_stmt", "@comment"].includes(type)) ? breakParent : "",
...parts,
...printTernaryConditions(keyword, truthyValue, falsyValue)
])
concat([forceBreak].concat(parts).concat(ternary))
));

@@ -79,3 +78,3 @@ }

path.call(print, "body", 0)
]),
])
));

@@ -82,0 +81,0 @@ };

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

const { concat, group, indent, line, lineSuffixBoundary } = require("prettier").doc.builders;
const { concat, group, indent, line } = require("prettier").doc.builders;

@@ -3,0 +3,0 @@ const printHook = name => (path, opts, print) => group(concat([

const { concat, group, hardline, indent } = require("prettier").doc.builders;
const printMethod = offset => (path, opts, print) => {
const [name, params, body] = path.getValue().body.slice(offset);
const [_name, params, body] = path.getValue().body.slice(offset);
const declaration = ["def "];

@@ -26,3 +26,3 @@

if (stmts.length === 1 && stmts[0].type === "void_stmt") {
return group(concat([...declaration, "; end"]));
return group(concat(declaration.concat(["; end"])));
}

@@ -29,0 +29,0 @@

@@ -8,3 +8,3 @@ const { concat, group, join, line } = require("prettier").doc.builders;

const printParams = (path, opts, print) => {
const [reqs, optls, rest, post, kwargs, kwarg_rest, block] = path.getValue().body;
const [reqs, optls, rest, post, kwargs, kwargRest, block] = path.getValue().body;
let parts = [];

@@ -33,3 +33,3 @@

if (kwargs) {
parts = parts.concat(kwargs.map(([kwarg, value], index) => {
parts = parts.concat(kwargs.map(([, value], index) => {
if (!value) {

@@ -42,3 +42,3 @@ return path.call(print, "body", 4, index, 0);

if (kwarg_rest) {
if (kwargRest) {
parts.push(path.call(print, "body", 5));

@@ -56,3 +56,3 @@ }

throw new Error("formal argument cannot be a global variable");
}
};

@@ -59,0 +59,0 @@ module.exports = {

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

const { concat, group, indent, softline } = require("prettier").doc.builders;
const { concat } = require("prettier").doc.builders;
const { makeList } = require("../utils");

@@ -9,10 +9,6 @@

const useBraces = contents.some(content => typeof content === "string" && content.includes("/"));
const parts = [useBraces ? "%r{" : "/"].concat(contents).concat([useBraces ? "}" : "/", ending.slice(1)]);
return concat([
useBraces ? "%r{" : "/",
...contents,
useBraces ? "}" : "/",
ending.slice(1)
]);
return concat(parts);
}
};

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

const { concat, group, hardline, indent, join, line, literalline, softline } = require("prettier").doc.builders;
const { concat, group, hardline, indent, join, literalline, softline } = require("prettier").doc.builders;
const { concatBody, empty, makeList, surround } = require("../utils");

@@ -14,3 +14,3 @@ const escapePattern = require("../escapePattern");

const makeString = (content, enclosingQuote) => {
const otherQuote = enclosingQuote === '"' ? "'" : '"';
const otherQuote = enclosingQuote === "\"" ? "'" : enclosingQuote;

@@ -25,3 +25,3 @@ // Escape and unescape single and double quotes as needed to be able to

if (quote === enclosingQuote) {
return "\\" + quote;
return `\\${quote}`;
}

@@ -33,3 +33,3 @@

return "\\" + escaped;
return `\\${escaped}`;
});

@@ -39,3 +39,3 @@ };

module.exports = {
"@CHAR": (path, { preferSingleQuotes }, print) => {
"@CHAR": (path, { preferSingleQuotes }, _print) => {
const { body } = path.getValue();

@@ -47,3 +47,3 @@

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

@@ -56,3 +56,3 @@ },

beging,
concat([literalline, ...path.map(print, "body")]),
concat([literalline].concat(path.map(print, "body"))),
ending

@@ -100,3 +100,3 @@ ]);

if (preferSingleQuotes && string.body.every(isSingleQuotable)) {
quote = "\'";
quote = "'";
}

@@ -115,3 +115,3 @@

return concat([quote, ...parts, quote]);
return concat([quote].concat(parts).concat([quote]));
},

@@ -118,0 +118,0 @@ word_add: concatBody,

const { spawnSync } = require("child_process");
const path = require("path");
module.exports = (text, parsers, opts) => {
module.exports = (text, _parsers, _opts) => {
const child = spawnSync("ruby", [path.join(__dirname, "./ripper.rb")], { input: text });

@@ -6,0 +6,0 @@

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

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

@@ -3,0 +2,0 @@ const nodes = require("./nodes");

@@ -8,3 +8,3 @@ const parse = require("./parse");

parsers: ["ruby"],
extensions: [".rb", ".rake"],
extensions: [".rb", ".rake", ".gemspec"],
linguistLanguageId: 303,

@@ -11,0 +11,0 @@ vscodeLanguageIds: ["ruby"]

@@ -5,2 +5,14 @@ const { breakParent, concat, hardline, lineSuffix } = require("prettier").doc.builders;

const docLength = doc => {
if (doc.length) {
return doc.length;
}
if (doc.parts) {
return doc.parts.reduce((sum, child) => sum + docLength(child), 0);
}
return 0;
};
const empty = () => "";

@@ -66,2 +78,3 @@

concatBody,
docLength,
empty,

@@ -68,0 +81,0 @@ first,

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