@prettier/plugin-ruby
Advanced tools
Comparing version 1.5.3 to 1.5.4
@@ -9,2 +9,10 @@ # Changelog | ||
## [1.5.4] - 2021-03-17 | ||
### Changed | ||
- [#835](https://github.com/prettier/plugin-ruby/issues/835) - valscion, kddeisz - Array splat operator should not get moved by leading comments. | ||
- [#836](https://github.com/prettier/plugin-ruby/issues/836) - valscion, kddeisz - Array splat operator should not get moved by trailing comments. | ||
- [#821](https://github.com/prettier/plugin-ruby/issues/821) - jscheid, kddeisz - Better error handling when using GNU netcat. | ||
## [1.5.3] - 2021-02-28 | ||
@@ -1089,3 +1097,5 @@ | ||
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.5.2...HEAD | ||
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.5.4...HEAD | ||
[1.5.4]: https://github.com/prettier/plugin-ruby/compare/v1.5.3...v1.5.4 | ||
[1.5.3]: https://github.com/prettier/plugin-ruby/compare/v1.5.2...v1.5.3 | ||
[1.5.2]: https://github.com/prettier/plugin-ruby/compare/v1.5.1...v1.5.2 | ||
@@ -1092,0 +1102,0 @@ [1.5.1]: https://github.com/prettier/plugin-ruby/compare/v1.5.0...v1.5.1 |
{ | ||
"name": "@prettier/plugin-ruby", | ||
"version": "1.5.3", | ||
"version": "1.5.4", | ||
"description": "prettier plugin for the Ruby programming language", | ||
@@ -25,3 +25,3 @@ "main": "src/plugin.js", | ||
"devDependencies": { | ||
"eslint": "^7.21.0", | ||
"eslint": "^7.22.0", | ||
"eslint-config-prettier": "^8.0.0", | ||
@@ -28,0 +28,0 @@ "husky": "^5.0.9", |
@@ -131,14 +131,16 @@ <div align="center"> | ||
| API Option | CLI Option | Default | Description | | ||
| ------------------ | ---------------------- | :-----: | ------------------------------------------------------------------------------------------------------------------------------------ | | ||
| `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). | | ||
| `requirePragma` | `--require-pragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)). | | ||
| `rubyArrayLiteral` | `--ruby-array-literal` | `true` | When possible, favor the use of string and symbol array literals. | | ||
| `rubyHashLabel` | `--ruby-hash-label` | `true` | When possible, uses the shortened hash key syntax, as opposed to hash rockets. | | ||
| `rubyModifier` | `--ruby-modifier` | `true` | When it fits on one line, allows while and until statements to use the modifier form. | | ||
| `rubySingleQuote` | `--ruby-single-quote` | `true` | When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals. | | ||
| `rubyToProc` | `--ruby-to-proc` | `false` | When possible, convert blocks to the more concise `Symbol#to_proc` syntax. | | ||
| `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). | | ||
| `trailingComma` | `--trailing-comma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#trailing-comma)). `"es5"` is equivalent to `true`. | | ||
| API Option | CLI Option | Default | Description | | ||
| ------------------- | ----------------------- | :-----: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). | | ||
| `requirePragma` | `--require-pragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)). | | ||
| `rubyArrayLiteral` | `--ruby-array-literal` | `true` | When possible, favor the use of string and symbol array literals. | | ||
| `rubyHashLabel` | `--ruby-hash-label` | `true` | When possible, uses the shortened hash key syntax, as opposed to hash rockets. | | ||
| `rubyModifier` | `--ruby-modifier` | `true` | When it fits on one line, allows while and until statements to use the modifier form. | | ||
| `rubyNetcatCommand` | `--ruby-netcat-command` | | The prefix of the command to execute to communicate between the node.js process and the Ruby process. (For example, `"nc -U"` or `"telnet -u"`) Normally you should not set this option. | | ||
| `rubySingleQuote` | `--ruby-single-quote` | `true` | When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals. | | ||
| `rubyToProc` | `--ruby-to-proc` | `false` | When possible, convert blocks to the more concise `Symbol#to_proc` syntax. | | ||
| `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). | | ||
| `trailingComma` | `--trailing-comma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#trailing-comma)). `"es5"` is equivalent to `true`. | | ||
Any of these can be added to your existing [prettier configuration | ||
@@ -167,2 +169,4 @@ file](https://prettier.io/docs/en/configuration.html). For example: | ||
#### Ruby gem | ||
```yaml | ||
@@ -173,2 +177,9 @@ inherit_gem: | ||
#### `npm` package | ||
```yaml | ||
inherit_from: | ||
- node_modules/@prettier/plugin-ruby/rubocop.yml | ||
``` | ||
## Contributing | ||
@@ -175,0 +186,0 @@ |
const parseSync = require("../parser/parseSync"); | ||
const parse = (text, _parsers, _opts) => { | ||
return parseSync("haml", text); | ||
const parse = (text, _parsers, opts) => { | ||
return parseSync("haml", text, opts); | ||
}; | ||
@@ -6,0 +6,0 @@ |
@@ -19,33 +19,40 @@ const { spawnSync } = require("child_process"); | ||
// these by likelihood of being found so we can avoid some shell-outs. | ||
function getCommandAndArg() { | ||
function getCommandAndArgs() { | ||
if (hasCommand("nc")) { | ||
return ["nc", "-U"]; | ||
return ["nc", ["-U"]]; | ||
} | ||
if (hasCommand("telnet")) { | ||
return ["telnet", "-u"]; | ||
return ["telnet", ["-u"]]; | ||
} | ||
if (hasCommand("ncat")) { | ||
return ["ncat", "-U"]; | ||
return ["ncat", ["-U"]]; | ||
} | ||
if (hasCommand("socat")) { | ||
return ["socat", "-"]; | ||
return ["socat", ["-"]]; | ||
} | ||
return ["node", require.resolve("./netcat.js")]; | ||
return ["node", [require.resolve("./netcat.js")]]; | ||
} | ||
let command; | ||
let arg; | ||
let args; | ||
function getNetcat() { | ||
function getNetcat(opts) { | ||
if (!command) { | ||
[command, arg] = getCommandAndArg(); | ||
if (opts.rubyNetcatCommand) { | ||
const splits = opts.rubyNetcatCommand.split(" "); | ||
command = splits[0]; | ||
args = splits.slice(1); | ||
} else { | ||
[command, args] = getCommandAndArgs(); | ||
} | ||
} | ||
return { command, arg }; | ||
return { command, args }; | ||
} | ||
module.exports = getNetcat; |
@@ -8,9 +8,7 @@ // A simple fallback when no netcat-compatible adapter is found on the system. | ||
const sock = process.argv[process.argv.length - 1]; | ||
const client = createConnection(sock, () => process.stdin.pipe(client)); | ||
client.on("data", (data) => process.stdout.write(data)); | ||
client.on("error", (error) => { | ||
console.error(error); | ||
}); |
@@ -7,5 +7,20 @@ const requestParse = require("./requestParse"); | ||
// requests. | ||
function parseSync(parser, source) { | ||
const { stdout, stderr, status } = requestParse(parser, source); | ||
function parseSync(parser, source, opts) { | ||
const { stdout, stderr, status } = requestParse(parser, source, opts); | ||
// We need special handling in case the user's version of nc doesn't support | ||
// using unix sockets. | ||
if (stderr.includes("invalid option -- U")) { | ||
throw new Error(` | ||
@prettier/plugin-ruby uses netcat to communicate over unix sockets between | ||
the node.js process running prettier and an underlying Ruby process used | ||
for parsing. Unfortunately the version of netcat that you have installed | ||
(GNU netcat) does not support unix sockets. To solve this either uninstall | ||
GNU netcat and use a different implementation, or change the value of the | ||
rubyNetcatCommand option in your prettier configuration. | ||
`); | ||
} | ||
// If we didn't receive anything over stdout or we have a bad exit status, | ||
// then throw whatever we can. | ||
if (stdout.length === 0 || (status !== null && status !== 0)) { | ||
@@ -12,0 +27,0 @@ throw new Error(stderr || "An unknown error occurred"); |
@@ -57,7 +57,7 @@ const { spawn, spawnSync, execSync } = require("child_process"); | ||
// Sends a request to the parse server to parse the given content. | ||
function requestParse(parser, source) { | ||
function requestParse(parser, source, opts) { | ||
ensureParseServer(); | ||
const { command, arg } = getNetcat(); | ||
const { stdout, stderr, status } = spawnSync(command, [arg, sockfile], { | ||
const { command, args } = getNetcat(opts); | ||
const { stdout, stderr, status } = spawnSync(command, args.concat(sockfile), { | ||
input: `${parser}|${source}`, | ||
@@ -64,0 +64,0 @@ maxBuffer: 15 * 1024 * 1024 |
@@ -122,2 +122,8 @@ const rubyPrinter = require("./ruby/printer"); | ||
}, | ||
rubyNetcatCommand: { | ||
type: "string", | ||
category: "Ruby", | ||
description: | ||
'The prefix of the command to execute to communicate between the node.js process and the Ruby process. (For example, "nc -U" or "telnet -u") Normally you should not set this option.' | ||
}, | ||
rubySingleQuote: { | ||
@@ -124,0 +130,0 @@ type: "boolean", |
@@ -7,4 +7,4 @@ const parseSync = require("../parser/parseSync"); | ||
// process of parser.rb and reading JSON off STDOUT. | ||
function parse(text, _parsers, _opts) { | ||
return parseSync("rbs", text); | ||
function parse(text, _parsers, opts) { | ||
return parseSync("rbs", text, opts); | ||
} | ||
@@ -11,0 +11,0 @@ |
@@ -150,5 +150,12 @@ const { | ||
// | ||
// or if we have an array like: | ||
// | ||
// [ | ||
// *values # comment | ||
// ] | ||
// | ||
// 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]]); | ||
const index = node.body[1].comments.filter(({ leading }) => leading).length; | ||
docs[1].parts[index] = concat(["*", docs[1].parts[index]]); | ||
} else { | ||
@@ -155,0 +162,0 @@ // If we don't have any comments, we can just prepend the operator |
@@ -7,4 +7,4 @@ const parseSync = require("../parser/parseSync"); | ||
// process of parser.rb and reading JSON off STDOUT. | ||
function parse(text, _parsers, _opts) { | ||
return parseSync("ruby", text); | ||
function parse(text, _parsers, opts) { | ||
return parseSync("ruby", text, opts); | ||
} | ||
@@ -11,0 +11,0 @@ |
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
349553
4513
207