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.8.0 to 0.9.0

bin/has-pragma

11

CHANGELOG.md

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

## [0.9.0] - 2019-03-18
### Added
- Support the `hasPragma` function.
- Support the new `number_arg` node type in Ruby 2.7.
### Changed
- Limit the number of nodes that are allowed to turn into ternary expressions.
## [0.8.0] - 2019-03-08

@@ -206,3 +214,4 @@ ### Added

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

@@ -209,0 +218,0 @@ [0.7.0]: https://github.com/prettier/plugin-ruby/compare/v0.6.3...v0.7.0

2

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

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

@@ -435,2 +435,3 @@ const { align, breakParent, concat, dedent, group, hardline, ifBreak, indent, join, line, literalline, markAsRoot, softline, trim } = require("prettier").doc.builders;

},
number_arg: first,
opassign: (path, opts, print) => group(concat([

@@ -437,0 +438,0 @@ path.call(print, "body", 0),

const { align, breakParent, concat, hardline, group, ifBreak, indent, softline } = require("prettier").doc.builders;
const noTernary = [
"@comment",
"alias",
"assign",
"break",
"command",
"command_call",
"if_mod",
"ifop",
"lambda",
"massign",
"next",
"opassign",
"rescue_mod",
"return",
"return0",
"super",
"undef",
"unless_mod",
"until_mod",
"var_alias",
"void_stmt",
"while_mod",
"yield",
"yield0",
"zsuper"
];
const printWithAddition = (keyword, path, print, { breaking = false } = {}) => concat([

@@ -17,2 +45,6 @@ `${keyword} `,

const canTernary = stmts => (
stmts.body.length === 1 && !noTernary.includes(stmts.body[0].type)
);
const printConditional = keyword => (path, { inlineConditionals }, print) => {

@@ -42,17 +74,12 @@ const [_predicate, stmts, addition] = path.getValue().body;

// If there is an else and only an else, attempt to shorten to a ternary
if (addition && addition.type === "else") {
const parts = [path.call(print, "body", 0), " ? "];
const truthyValue = path.call(print, "body", 1);
const falsyValue = path.call(print, "body", 2, "body", 0);
if (addition && addition.type === "else" && canTernary(stmts) && canTernary(addition.body[0])) {
const ternary = printTernaryConditions(
keyword,
path.call(print, "body", 1),
path.call(print, "body", 2, "body", 0)
);
if (stmts.body.length === 1 && ["command", "command_call"].includes(stmts.body[0].type)) {
return printWithAddition(keyword, path, print, { breaking: true });
}
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([forceBreak].concat(parts).concat(ternary))
concat([path.call(print, "body", 0), " ? "].concat(ternary))
));

@@ -59,0 +86,0 @@ }

const parse = require("./parse");
const print = require("./print");
const pragmaPattern = /#\s*@(prettier|format)/;
const hasPragma = text => pragmaPattern.test(text);
module.exports = {

@@ -8,4 +11,19 @@ languages: [{

parsers: ["ruby"],
extensions: [".rb", ".rake", ".gemspec"],
linguistLanguageId: 303,
extensions: [
".gemspec",
".podspec",
".rake",
".rb",
".ru"
],
filenames: [
".irbrc",
".pryrc",
"Capfile",
"Gemfile",
"Guardfile",
"Podfile",
"Rakefile"
],
linguistLanguageId: 326,
vscodeLanguageIds: ["ruby"]

@@ -16,3 +34,4 @@ }],

parse,
astFormat: "ruby"
astFormat: "ruby",
hasPragma
}

@@ -19,0 +38,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