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 1.2.2 to 1.2.3

src/plugin.js

15

CHANGELOG.md

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

## [1.2.3] - 2021-01-02
### Changed
- [@lukyth], [@kddeisz] - Ensure if a ternary breaks into an `if..else..end` within a `command_call` node that parentheses are added.
- [@AlanFoster], [@kddeisz] - Ensure you consume the optional `do` keyword on `while` and `until` loops so that it doesn't confuse the parser.
- [@AlanFoster], [@kddeisz] - Ensure key-value pairs split on line when the key has a comment attached within a hash.
- [@AlanFoster], [@kddeisz] - Fix for `for` loops that have multiple index variables.
- [@AlanFoster], [@kddeisz] - Fix parsing very large files by reducing the size of the JSON output from the parser.
- [@AlanFoster], [@kddeisz] - Ensure you don't skip parentheses if you're returning a value with the `not` unary operator.
## [1.2.2] - 2021-01-01

@@ -1002,3 +1013,4 @@

[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.2.2...HEAD
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.2.3...HEAD
[1.2.3]: https://github.com/prettier/plugin-ruby/compare/v1.2.2...v1.2.3
[1.2.2]: https://github.com/prettier/plugin-ruby/compare/v1.2.1...v1.2.2

@@ -1101,2 +1113,3 @@ [1.2.1]: https://github.com/prettier/plugin-ruby/compare/v1.2.0...v1.2.1

[@localhostdotdev]: https://github.com/localhostdotdev
[@lukyth]: https://github.com/lukyth
[@marcmaniez]: https://github.com/MarcManiez

@@ -1103,0 +1116,0 @@ [@masqita]: https://github.com/masqita

4

CONTRIBUTING.md

@@ -25,3 +25,3 @@ # Contributing

When the prettier process first spins up, it examines which files it's going to print and selects an appropriate plugin for each one. Once selected, it runs that plugin's `parse` function, seen [here](src/parser.js). For the case of the Ruby plugin, that entails spawning a Ruby process that runs [parser.rb](src/parser.rb) with the input code preloaded on stdin.
When the prettier process first spins up, it examines which files it's going to print and selects an appropriate plugin for each one. Once selected, it runs that plugin's `parse` function, seen [here](src/ruby/parser.js). For the case of the Ruby plugin, that entails spawning a Ruby process that runs [parser.rb](src/ruby/parser.rb) with the input code preloaded on stdin.

@@ -75,3 +75,3 @@ `parser.rb` will read the text off of stdin and then feed it to a new `Ripper` instance, which is a Ruby standard library recursive-descent parser. Briefly, the way that `Ripper` works is by tokenizing the input and then matching those tokens against a grammar to form s-expressions. To extend `Ripper`, you overwrite the methods that control how those s-expressions are formed, e.g., to modify the s-expression that is formed when `Ripper` encounters a string literal, you would override the `#on_string_literal` method. Below is an example for seeing that in action.

Once prettier has a working AST, it will take it and call the selected plugin's [`printNode` function](src/printer.js), whose purpose is to convert that AST into prettier's intermediate representation called Docs. It does this by handing the print function a `FastPath` object that keeps track of the state of the printing as it goes, and allows accessing various parts of the AST quickly.
Once prettier has a working AST, it will take it and call the selected plugin's [`printNode` function](src/ruby/printer.js), whose purpose is to convert that AST into prettier's intermediate representation called Docs. It does this by handing the print function a `FastPath` object that keeps track of the state of the printing as it goes, and allows accessing various parts of the AST quickly.

@@ -78,0 +78,0 @@ Effectively, it walks the AST in the reverse direction from the way `Ripper` built it (top-down instead of bottom-up). The first node that gets passed into the `print` function is the `program` node as that's always on top. Then it is the `program` node's responsibility to recursively call print on its child nodes as it best sees fit.

{
"name": "@prettier/plugin-ruby",
"version": "1.2.2",
"version": "1.2.3",
"description": "prettier plugin for the Ruby programming language",
"main": "src/ruby.js",
"main": "src/plugin.js",
"scripts": {

@@ -7,0 +7,0 @@ "check-format": "prettier --check '**/*'",

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

Below are the options (from [`src/ruby.js`](src/ruby.js)) that `@prettier/plugin-ruby` currently supports:
Below are the options (from [`src/plugin.js`](src/plugin.js)) that `@prettier/plugin-ruby` currently supports:

@@ -126,0 +126,0 @@ | API Option | CLI Option | Default | Description |

@@ -1,95 +0,12 @@

const { concat } = require("./prettier");
const isEmptyStmts = require("./utils/isEmptyStmts");
const literalLineNoBreak = require("./utils/literalLineNoBreak");
const printEmptyCollection = require("./utils/printEmptyCollection");
// If the node is a type of assignment or if the node is a paren and nested
// inside that paren is a node that is a type of assignment.
const containsAssignment = (node) =>
node &&
(["assign", "massign", "opassign"].includes(node.type) ||
(Array.isArray(node.body) && node.body.some(containsAssignment)));
const docLength = (doc) => {
if (doc.length) {
return doc.length;
}
if (doc.parts) {
return doc.parts.reduce((sum, child) => sum + docLength(child), 0);
}
if (doc.contents) {
return docLength(doc.contents);
}
return 0;
};
const empty = () => "";
const first = (path, opts, print) => path.call(print, "body", 0);
const getTrailingComma = (opts) => ["all", "es5"].includes(opts.trailingComma);
const hasAncestor = (path, types) => {
let parent = 0;
let parentNode = path.getParentNode();
while (parentNode) {
if (types.includes(parentNode.type)) {
return true;
}
parent += 1;
parentNode = path.getParentNode(parent);
}
return false;
};
const literal = (value) => () => value;
const makeCall = (path, opts, print) => {
const operation = path.getValue().body[1];
if ([".", "&."].includes(operation)) {
return operation;
}
return operation === "::" ? "." : path.call(print, "body", 1);
};
const noIndent = [
"array",
"hash",
"heredoc",
"if",
"method_add_block",
"xstring_literal"
];
const prefix = (value) => (path, opts, print) =>
concat([value, path.call(print, "body", 0)]);
const skippable = ["array", "hash", "heredoc", "lambda", "regexp_literal"];
const skipAssignIndent = (node) =>
skippable.includes(node.type) ||
(node.type === "call" && skipAssignIndent(node.body[0]));
module.exports = {
containsAssignment,
docLength,
empty,
first,
getTrailingComma,
hasAncestor,
isEmptyStmts,
literal,
literalLineNoBreak,
makeCall,
noIndent,
prefix,
printEmptyCollection,
skipAssignIndent
containsAssignment: require("./utils/containsAssignment"),
getTrailingComma: require("./utils/getTrailingComma"),
isEmptyStmts: require("./utils/isEmptyStmts"),
hasAncestor: require("./utils/hasAncestor"),
literal: require("./utils/literal"),
literalLineNoBreak: require("./utils/literalLineNoBreak"),
makeCall: require("./utils/makeCall"),
noIndent: require("./utils/noIndent"),
printEmptyCollection: require("./utils/printEmptyCollection"),
skipAssignIndent: require("./utils/skipAssignIndent")
};
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