@prettier/plugin-ruby
Advanced tools
Comparing version 0.18.2 to 0.19.0
@@ -9,2 +9,9 @@ # Changelog | ||
## [0.19.0] - 2020-07-03 | ||
### Added | ||
- [@ryan-hunter-pc] - Add the option to disable the `Symbol#to_proc` transform. | ||
- [@ryan-hunter-pc], [@SViccari], [@kddeisz] - Disable `Symbol#to_proc` transform when used as a key inside of a hash where the key is either `:if` or `:unless`. | ||
## [0.18.2] - 2020-05-01 | ||
@@ -807,3 +814,4 @@ | ||
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.18.2...HEAD | ||
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.19.0...HEAD | ||
[0.19.0]: https://github.com/prettier/plugin-ruby/compare/v0.18.2...v0.19.0 | ||
[0.18.2]: https://github.com/prettier/plugin-ruby/compare/v0.18.1...v0.18.2 | ||
@@ -810,0 +818,0 @@ [0.18.1]: https://github.com/prettier/plugin-ruby/compare/v0.18.0...v0.18.1 |
{ | ||
"name": "@prettier/plugin-ruby", | ||
"version": "0.18.2", | ||
"version": "0.19.0", | ||
"description": "prettier plugin for the Ruby programming language", | ||
@@ -26,6 +26,6 @@ "main": "src/ruby.js", | ||
"all-contributors-cli": "^6.14.1", | ||
"eslint": "^6.8.0", | ||
"eslint": "^7.1.0", | ||
"eslint-config-prettier": "^6.10.1", | ||
"husky": "^4.2.5", | ||
"jest": "^25.2.7", | ||
"jest": "^26.0.0", | ||
"pretty-quick": "^2.0.1" | ||
@@ -32,0 +32,0 @@ }, |
@@ -75,3 +75,3 @@ const { | ||
const proc = blockNode && toProc(blockNode); | ||
const proc = blockNode && toProc(path, opts, blockNode); | ||
@@ -78,0 +78,0 @@ // If we have a successful to_proc transformation, but we're part of an aref |
@@ -79,3 +79,3 @@ const { concat, group, indent, hardline, softline } = require("../prettier"); | ||
const [method, block] = path.getValue().body; | ||
const proc = toProc(block); | ||
const proc = toProc(path, opts, block); | ||
@@ -82,0 +82,0 @@ if (proc && method.type === "call") { |
@@ -145,2 +145,9 @@ const parse = require("./parse"); | ||
"When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals." | ||
}, | ||
toProcTransform: { | ||
type: "boolean", | ||
category: "Global", | ||
default: true, | ||
description: | ||
"When possible, convert blocks to the more concise Symbol#to_proc syntax." | ||
} | ||
@@ -147,0 +154,0 @@ }, |
@@ -14,4 +14,4 @@ const isCall = (node) => ["::", "."].includes(node) || node.type === "@period"; | ||
// This works with `do` blocks as well. | ||
const toProc = (node) => { | ||
if (!node) { | ||
const toProc = (path, opts, node) => { | ||
if (!node || !opts.toProcTransform) { | ||
return null; | ||
@@ -80,2 +80,29 @@ } | ||
// Ensure that we're not inside of a hash that is being passed to a key that | ||
// corresponds to `:if` or `:unless` to avoid problems with callbacks with | ||
// Rails. For more context, see: | ||
// https://github.com/prettier/plugin-ruby/issues/449 | ||
let assocNode = null; | ||
if (path.getValue().type === "method_add_block") { | ||
assocNode = path.getParentNode(); | ||
} else if (path.getValue().type === "args") { | ||
assocNode = path.getParentNode(2); | ||
} | ||
if (assocNode && assocNode.type === "assoc_new") { | ||
const [key] = assocNode.body; | ||
if (key.type === "@label" && ["if:", "unless:"].includes(key.body)) { | ||
return null; | ||
} | ||
if ( | ||
key.type === "symbol_literal" && | ||
["if", "unless"].includes(key.body[0].body[0].body) | ||
) { | ||
return null; | ||
} | ||
} | ||
return `&:${method.body}`; | ||
@@ -82,0 +109,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
270899
2753