@prettier/plugin-ruby
Advanced tools
Comparing version 1.5.2 to 1.5.3
@@ -9,2 +9,10 @@ # Changelog | ||
## [1.5.3] - 2021-02-28 | ||
### Changed | ||
- [#812](https://github.com/prettier/plugin-ruby/issues/812) - valscion, kddeisz - Splats and blocks within args that have comments attached should place their respective operators in the right place. | ||
- [#816](https://github.com/prettier/plugin-ruby/pull/816) - valscion - Document RuboCop's Style/Lambda should be disabled | ||
- [#814](https://github.com/prettier/plugin-ruby/issues/814) - jscheid, kddeisz - Provide better errors when the source location of the error is known. | ||
## [1.5.2] - 2021-02-03 | ||
@@ -11,0 +19,0 @@ |
{ | ||
"name": "@prettier/plugin-ruby", | ||
"version": "1.5.2", | ||
"version": "1.5.3", | ||
"description": "prettier plugin for the Ruby programming language", | ||
@@ -25,5 +25,5 @@ "main": "src/plugin.js", | ||
"devDependencies": { | ||
"eslint": "^7.8.1", | ||
"eslint-config-prettier": "^7.0.0", | ||
"husky": "^4.3.5", | ||
"eslint": "^7.21.0", | ||
"eslint-config-prettier": "^8.0.0", | ||
"husky": "^5.0.9", | ||
"jest": "^26.0.0", | ||
@@ -30,0 +30,0 @@ "pretty-quick": "^3.1.0" |
@@ -8,22 +8,17 @@ const requestParse = require("./requestParse"); | ||
function parseSync(parser, source) { | ||
const response = requestParse(parser, source); | ||
const { stdout, stderr, status } = requestParse(parser, source); | ||
if ( | ||
response.stdout.length === 0 || | ||
(response.status !== null && response.status !== 0) | ||
) { | ||
console.error("Could not parse response from server"); | ||
console.error(response); | ||
throw new Error(response.stderr || "An unknown error occurred"); | ||
if (stdout.length === 0 || (status !== null && status !== 0)) { | ||
throw new Error(stderr || "An unknown error occurred"); | ||
} | ||
const parsed = JSON.parse(response.stdout); | ||
const parsed = JSON.parse(stdout); | ||
if (parsed.error) { | ||
throw new Error( | ||
`@prettier/plugin-ruby encountered an error when attempting to parse \ | ||
the ruby source. This usually means there was a syntax error in the \ | ||
file in question. You can verify by running \`ruby -i [path/to/file]\`.` | ||
); | ||
const error = new Error(parsed.error); | ||
if (parsed.loc) { | ||
error.loc = parsed.loc; | ||
} | ||
throw error; | ||
} | ||
@@ -30,0 +25,0 @@ |
@@ -109,23 +109,64 @@ const { | ||
module.exports = { | ||
arg_paren: printArgParen, | ||
args: printArgs, | ||
args_add_block: (path, opts, print) => { | ||
const parts = path.call(print, "body", 0); | ||
function printArgsAddBlock(path, opts, print) { | ||
const node = path.getValue(); | ||
const parts = path.call(print, "body", 0); | ||
if (path.getValue().body[1]) { | ||
parts.push(concat(["&", path.call(print, "body", 1)])); | ||
if (node.body[1]) { | ||
let blockDoc = path.call(print, "body", 1); | ||
if (node.body[1].comments) { | ||
// If we have a method call like: | ||
// | ||
// foo( | ||
// # comment | ||
// &block | ||
// ) | ||
// | ||
// then we need to make sure we don't accidentally prepend the operator | ||
// before the comment. | ||
blockDoc.parts[2] = concat(["&", blockDoc.parts[2]]); | ||
} else { | ||
// If we don't have any comments, we can just prepend the operator | ||
blockDoc = concat(["&", blockDoc]); | ||
} | ||
return parts; | ||
}, | ||
args_add_star: (path, opts, print) => { | ||
const printed = path.map(print, "body"); | ||
const parts = printed[0] | ||
.concat([concat(["*", printed[1]])]) | ||
.concat(printed.slice(2)); | ||
parts.push(blockDoc); | ||
} | ||
return parts; | ||
}, | ||
blockarg: (path, opts, print) => concat(["&", path.call(print, "body", 0)]) | ||
return parts; | ||
} | ||
function printArgsAddStar(path, opts, print) { | ||
const node = path.getValue(); | ||
const docs = path.map(print, "body"); | ||
if (node.body[1].comments) { | ||
// If we have an array like: | ||
// | ||
// [ | ||
// # comment | ||
// *values | ||
// ] | ||
// | ||
// then we need to make sure we don't accidentally prepend the operator | ||
// before the comment. | ||
docs[1].parts[2] = concat(["*", docs[1].parts[2]]); | ||
} else { | ||
// If we don't have any comments, we can just prepend the operator | ||
docs[1] = concat(["*", docs[1]]); | ||
} | ||
return docs[0].concat(docs[1]).concat(docs.slice(2)); | ||
} | ||
function printBlockArg(path, opts, print) { | ||
return concat(["&", path.call(print, "body", 0)]); | ||
} | ||
module.exports = { | ||
arg_paren: printArgParen, | ||
args: printArgs, | ||
args_add_block: printArgsAddBlock, | ||
args_add_star: printArgsAddStar, | ||
blockarg: printBlockArg | ||
}; |
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
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
346897
4480