@prettier/plugin-ruby
Advanced tools
Comparing version 0.12.1 to 0.12.2
{ | ||
"extends": "airbnb-base", | ||
"extends": ["airbnb-base", "prettier"], | ||
"env": { | ||
@@ -8,17 +8,11 @@ "jest": true, | ||
"rules": { | ||
"arrow-body-style": ["error", "as-needed"], | ||
"arrow-parens": ["error", "as-needed"], | ||
"comma-dangle": ["error", "never"], | ||
"global-require": "off", | ||
"no-unused-vars": ["error", { | ||
"argsIgnorePattern": "^_", | ||
"varsIgnorePattern": "^_" | ||
}], | ||
"object-curly-newline": "off", | ||
"prefer-spread": "off", | ||
"quotes": "off" | ||
}, | ||
"globals": { | ||
"runCase": "readonly" | ||
"no-unused-vars": [ | ||
"error", | ||
{ | ||
"argsIgnorePattern": "^_", | ||
"varsIgnorePattern": "^_" | ||
} | ||
], | ||
"prefer-spread": "off" | ||
} | ||
} |
@@ -9,4 +9,13 @@ # Changelog | ||
## [0.12.2] - 2019-04-30 | ||
### Changed | ||
- When symbol literal hash keys end with `=`, they cannot be transformed into hash labels. | ||
- Fixed when blocks on methods with no arguments are transformed into `to_proc` syntax. (Thanks to @xipgroc for the report.) | ||
## [0.12.1] - 2019-04-22 | ||
### Changed | ||
- If a lambda literal is nested under a `command` or `command_call` node anywhere in the heirarchy, then it needs to use the higher-precedence `{ ... }` braces as opposed to the `do ... end` delimiters. | ||
@@ -17,7 +26,11 @@ - Calling `super` with a block and no args was causing the parser to fail when attempting to inspect lambda nodes. (Thanks to @jpickwell for the report.) | ||
## [0.12.0] - 2019-04-18 | ||
### Added | ||
- Automatically convert `lambda { ... }` method calls into `-> { ... }` literals. | ||
## [0.11.0] - 2019-04-18 | ||
### Added | ||
- Support for parsing things with a ruby shebang (e.g., `#!/usr/bin/env ruby` or `#!/usr/bin/ruby`). | ||
@@ -33,2 +46,3 @@ - [INTERNAL] Big tests refactor. | ||
### Changed | ||
- Fixed support for dynamic string hash keys. (Thanks to @deecewan.) | ||
@@ -46,3 +60,5 @@ - [INTERNAL] Moved `case/when` into its own file and added better documentation. | ||
## [0.10.0] - 2019-03-25 | ||
### Added | ||
- Support for block-local variables. | ||
@@ -52,2 +68,3 @@ - Support for dyna-symbols that are using single quotes. | ||
### Changed | ||
- Force method calls after arrays, blocks, hashes, and xstrings to hang onto the end of the previous nodes. | ||
@@ -57,3 +74,5 @@ - Check before anything else for an invalid ruby version. | ||
## [0.9.1] - 2019-03-24 | ||
### Changed | ||
- Better support string quotes by favoring what the user chose if the string contains escape patterns. | ||
@@ -63,3 +82,5 @@ - Better support heredocs within method calls. | ||
## [0.9.0] - 2019-03-18 | ||
### Added | ||
- Support the `hasPragma` function. | ||
@@ -69,6 +90,9 @@ - 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 | ||
### Added | ||
- [INTERNAL] Add `eslint` and fix up existing violations. | ||
@@ -80,2 +104,3 @@ - Add the infra for the `prettier` ruby gem. (Thanks to @AlanFoster.) | ||
### Changed | ||
- Fix string escaping for hex digit bit patterns when there's only one character after the "x". | ||
@@ -91,6 +116,9 @@ - Don't allow line breaks between brace block params. (Thanks to @AlanFoster.) | ||
### Removed | ||
- All instances of the spread (`...`) operator so that we can support older versions of node. | ||
## [0.7.0] - 2019-02-24 | ||
### Changed | ||
- Support checking for escaping within strings to force double quotes (e.g., "\n"). | ||
@@ -114,3 +142,5 @@ - Handle cases with empty class and module declarations that need to break. (Thanks to @RossKinsella for the report.) | ||
## [0.6.3] - 2019-02-18 | ||
### Changed | ||
- [INTERNAL] Switch over `binary` fixture to minitest. | ||
@@ -122,3 +152,5 @@ - [INTERNAL] Reconfigure parser into multiple layer modules so that it's easier to understand and manage. | ||
## [0.6.2] - 2019-02-17 | ||
### Changed | ||
- Handle regexp suffixes. (Thanks to @AlanFoster.) | ||
@@ -131,3 +163,5 @@ - [INTERNAL] Add support for testing the test fixtures with minitest. | ||
## [0.6.1] - 2019-02-15 | ||
### Changed | ||
- Fix Ruby 2.5 inline comments on `args_add_block` nodes. (Thanks to @meleyal for the report.) | ||
@@ -137,3 +171,5 @@ - Support passing `super()` explicitly with no arguments. (Thanks to @meleyal for the report.) | ||
## [0.6.0] - 2019-02-14 | ||
### Added | ||
- Handle non UTF-8 comments. | ||
@@ -146,2 +182,3 @@ - Handle non UTF-8 identifiers. | ||
### Changed | ||
- Use `JSON::fast_generate` to get the s-expressions back from the parser. | ||
@@ -151,7 +188,11 @@ - Handle broken lambdas from within `command` and `command_call` nodes. (Thanks to @NoahTheDuke for the report.) | ||
## [0.5.2] - 2019-02-13 | ||
### Changed | ||
- Support embedded expressions within strings that contain only keywords, as in `"#{super}"`. | ||
## [0.5.1] - 2019-02-13 | ||
### Changed | ||
- Force `do` blocks that we know have to be `do` blocks to break. (Thanks to @yuki24 for the report.) | ||
@@ -162,3 +203,5 @@ - Handle `command` and `command_call` nodes `do` blocks by forcing them to break. (Thanks to @kmcq for the report.) | ||
## [0.5.0] - 2019-02-13 | ||
### Added | ||
- Automatically convert arrays of all string literals to %w arrays. | ||
@@ -168,2 +211,3 @@ - Automatically convert arrays of all symbol literals to %i arrays. | ||
### Changed | ||
- [INTERNAL] Move the `args_add` and `args_new` handling into the parser. | ||
@@ -174,3 +218,5 @@ - Change `command_call` nodes to properly indent when broken and to not add a trailing comma. (Thanks to @uri for the report.) | ||
## [0.4.1] - 2019-02-12 | ||
### Changed | ||
- [INTERNAL] Provide the `makeList` utility for the nodes that are lists from within ripper. | ||
@@ -181,10 +227,15 @@ - Again, this time for real, properly escape strings. (Thanks to @awinograd for the report.) | ||
## [0.4.0] - 2019-02-12 | ||
### Added | ||
- Support the `trailingComma` configuration option (defaults to `false`). (Thanks to @Overload119 for the request.) | ||
### Changed | ||
- Pass the code to be formatted over `stdin`. (Thanks to @NoahTheDuke for the report.) | ||
## [0.3.7] - 2019-02-11 | ||
### Changed | ||
- Split up statements even if they started on the same line with `;`s unless they are within an embedded expression. | ||
@@ -194,3 +245,5 @@ - Properly handle escaped quotes within strings. | ||
## [0.3.6] - 2019-02-10 | ||
### Changed | ||
- Support the `not` operator properly. (Thanks to @AlanFoster for the report.) | ||
@@ -200,7 +253,11 @@ - Handle comments properly inside `if`, `unless`, and `when` nodes. (Thanks to @AlanFoster for the report.) | ||
## [0.3.5] - 2019-02-09 | ||
### Changed | ||
- Handle lonely operators in Ruby `2.5`. | ||
## [0.3.4] - 2019-02-09 | ||
### Changed | ||
- Comments are now properly attached inside `defs` nodes. | ||
@@ -214,3 +271,5 @@ - Support multiple inline comments on nodes. | ||
## [0.3.3] - 2019-02-09 | ||
### Changed | ||
- Command nodes within conditionals now break parents to disallow them from being turned into ternary expressions. (Thanks to @bugthing for the report.) | ||
@@ -220,3 +279,5 @@ - Properly escape double quotes when using `preferSingleQuotes: false`. (Thanks to @awinograd for the report.) | ||
## [0.3.2] - 2019-02-09 | ||
### Changed | ||
- [INTERNAL] Don't define duplicated methods in the parser. | ||
@@ -227,3 +288,5 @@ - Let prettier know about `.rb` and `.rake` files so you don't have to specify the parser when running. | ||
## [0.3.1] - 2019-02-07 | ||
### Changed | ||
- Automatically add parens to method declarations. | ||
@@ -235,3 +298,5 @@ - Handle comments on bare hash assocs. | ||
## [0.3.0] - 2019-02-07 | ||
### Added | ||
- Support squiggly heredocs. | ||
@@ -241,2 +306,3 @@ - Support straight heredocs. | ||
### Changed | ||
- Ignore current indentation when creating embdocs so that `=begin` is always at the beginning of the line. | ||
@@ -250,3 +316,5 @@ - [INTERNAL] Move `regexp_add` and `regexp_new` handling into the parser. | ||
## [0.2.1] - 2019-02-06 | ||
### Changed | ||
- Handle brace blocks on commands properly. | ||
@@ -257,3 +325,5 @@ - Break parent and return `do` blocks when called from a `command` node. | ||
## [0.2.0] - 2019-02-06 | ||
### Added | ||
- Handle `methref` nodes from Ruby `2.7`. | ||
@@ -263,2 +333,3 @@ - Allow `module` nodes to shorten using `;` when the block is empty. | ||
### Changed | ||
- Handle splat within an array, as in `[1, 2, *foo]`. | ||
@@ -275,7 +346,11 @@ - Disallow comments from being attached to intermediary regex nodes. | ||
## [0.1.2] - 2019-02-05 | ||
### Changed | ||
- Handle guard clauses that return with no parens. | ||
## [0.1.1] - 2019-02-05 | ||
### Changed | ||
- Handle class method calls with the `::` operator. | ||
@@ -288,6 +363,9 @@ - Handle strings with apostrophes when using `preferSingleQuote`. | ||
## [0.1.0] - 2019-02-04 | ||
### Added | ||
- Initial release 🎉 | ||
[Unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.12.1...HEAD | ||
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.12.2...HEAD | ||
[0.12.2]: https://github.com/prettier/plugin-ruby/compare/v0.12.1...v0.12.2 | ||
[0.12.1]: https://github.com/prettier/plugin-ruby/compare/v0.12.0...v0.12.1 | ||
@@ -294,0 +372,0 @@ [0.12.0]: https://github.com/prettier/plugin-ruby/compare/v0.11.0...v0.12.0 |
@@ -17,18 +17,18 @@ # Contributor Covenant Code of Conduct | ||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
- Using welcoming and inclusive language | ||
- Being respectful of differing viewpoints and experiences | ||
- Gracefully accepting constructive criticism | ||
- Focusing on what is best for the community | ||
- Showing empathy towards other community members | ||
Examples of unacceptable behavior by participants include: | ||
* The use of sexualized language or imagery and unwelcome sexual attention or | ||
advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic | ||
address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
- The use of sexualized language or imagery and unwelcome sexual attention or | ||
advances | ||
- Trolling, insulting/derogatory comments, and personal or political attacks | ||
- Public or private harassment | ||
- Publishing others' private information, such as a physical or electronic | ||
address, without explicit permission | ||
- Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
@@ -35,0 +35,0 @@ ## Our Responsibilities |
@@ -17,2 +17,3 @@ # Contributing | ||
<!-- prettier-ignore --> | ||
```ruby | ||
@@ -28,2 +29,3 @@ $ irb | ||
<!-- prettier-ignore --> | ||
```ruby | ||
@@ -30,0 +32,0 @@ $ irb |
{ | ||
"name": "@prettier/plugin-ruby", | ||
"version": "0.12.1", | ||
"version": "0.12.2", | ||
"description": "prettier plugin for the Ruby programming language", | ||
"main": "src/ruby.js", | ||
"scripts": { | ||
"build": "pkg --output pkg/prettier --targets=linux,macos,win node_modules/prettier/bin-prettier.js", | ||
"lint": "eslint --cache .", | ||
@@ -30,5 +29,5 @@ "print": "prettier --plugin=.", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-config-prettier": "^4.1.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"jest": "^24.0.0", | ||
"pkg": "^4.3.7" | ||
"jest": "^24.0.0" | ||
}, | ||
@@ -35,0 +34,0 @@ "jest": { |
@@ -31,2 +31,3 @@ <div align="center"> | ||
<!-- prettier-ignore --> | ||
```ruby | ||
@@ -52,12 +53,12 @@ d=[30644250780,9003106878, | ||
d = [ | ||
30644250780, | ||
9003106878, | ||
30636278846, | ||
66641217692, | ||
4501790980, | ||
30_644_250_780, | ||
9_003_106_878, | ||
30_636_278_846, | ||
66_641_217_692, | ||
4_501_790_980, | ||
671_24_603036, | ||
131_61973916, | ||
66_606629_920, | ||
30642677916, | ||
30643069058 | ||
30_642_677_916, | ||
30_643_069_058 | ||
] | ||
@@ -148,3 +149,3 @@ a, s = [], $*[0] | ||
<!-- prettier-ignore --> | ||
<table><tr><td align="center"><a href="https://kevindeisz.com"><img src="https://avatars2.githubusercontent.com/u/5093358?v=4" width="100px;" alt="Kevin Deisz"/><br /><sub><b>Kevin Deisz</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Code">💻</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Documentation">📖</a> <a href="#maintenance-kddeisz" title="Maintenance">🚧</a> <a href="#review-kddeisz" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Tests">⚠️</a></td><td align="center"><a href="https://www.alanfoster.me/"><img src="https://avatars2.githubusercontent.com/u/1271782?v=4" width="100px;" alt="Alan Foster"/><br /><sub><b>Alan Foster</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Code">💻</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Documentation">📖</a> <a href="#review-AlanFoster" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/johnschoeman"><img src="https://avatars0.githubusercontent.com/u/16049495?v=4" width="100px;" alt="johnschoeman"/><br /><sub><b>johnschoeman</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=johnschoeman" title="Tests">⚠️</a></td><td align="center"><a href="https://twitter.com/aaronjensen"><img src="https://avatars3.githubusercontent.com/u/8588?v=4" width="100px;" alt="Aaron Jensen"/><br /><sub><b>Aaron Jensen</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=aaronjensen" title="Documentation">📖</a></td><td align="center"><a href="http://cameronbothner.com"><img src="https://avatars1.githubusercontent.com/u/4642599?v=4" width="100px;" alt="Cameron Bothner"/><br /><sub><b>Cameron Bothner</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=cbothner" title="Code">💻</a></td><td align="center"><a href="https://localhost.dev"><img src="https://avatars3.githubusercontent.com/u/47308085?v=4" width="100px;" alt="localhost.dev"/><br /><sub><b>localhost.dev</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Alocalhostdotdev" title="Bug reports">🐛</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=localhostdotdev" title="Code">💻</a></td><td align="center"><a href="https://deecewan.github.io"><img src="https://avatars0.githubusercontent.com/u/4755785?v=4" width="100px;" alt="David Buchan-Swanson"/><br /><sub><b>David Buchan-Swanson</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Adeecewan" title="Bug reports">🐛</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=deecewan" title="Code">💻</a></td></tr><tr><td align="center"><a href="https://github.com/jpickwell"><img src="https://avatars1.githubusercontent.com/u/4682321?v=4" width="100px;" alt="Jordan Pickwell"/><br /><sub><b>Jordan Pickwell</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Ajpickwell" title="Bug reports">🐛</a></td><td align="center"><a href="http://codingitwrong.com"><img src="https://avatars0.githubusercontent.com/u/15832198?v=4" width="100px;" alt="Josh Justice"/><br /><sub><b>Josh Justice</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3ACodingItWrong" title="Bug reports">🐛</a></td></tr></table> | ||
<table><tr><td align="center"><a href="https://kevindeisz.com"><img src="https://avatars2.githubusercontent.com/u/5093358?v=4" width="100px;" alt="Kevin Deisz"/><br /><sub><b>Kevin Deisz</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Code">💻</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Documentation">📖</a> <a href="#maintenance-kddeisz" title="Maintenance">🚧</a> <a href="#review-kddeisz" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Tests">⚠️</a></td><td align="center"><a href="https://www.alanfoster.me/"><img src="https://avatars2.githubusercontent.com/u/1271782?v=4" width="100px;" alt="Alan Foster"/><br /><sub><b>Alan Foster</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Code">💻</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Documentation">📖</a> <a href="#review-AlanFoster" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/johnschoeman"><img src="https://avatars0.githubusercontent.com/u/16049495?v=4" width="100px;" alt="johnschoeman"/><br /><sub><b>johnschoeman</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=johnschoeman" title="Tests">⚠️</a></td><td align="center"><a href="https://twitter.com/aaronjensen"><img src="https://avatars3.githubusercontent.com/u/8588?v=4" width="100px;" alt="Aaron Jensen"/><br /><sub><b>Aaron Jensen</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=aaronjensen" title="Documentation">📖</a></td><td align="center"><a href="http://cameronbothner.com"><img src="https://avatars1.githubusercontent.com/u/4642599?v=4" width="100px;" alt="Cameron Bothner"/><br /><sub><b>Cameron Bothner</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=cbothner" title="Code">💻</a></td><td align="center"><a href="https://localhost.dev"><img src="https://avatars3.githubusercontent.com/u/47308085?v=4" width="100px;" alt="localhost.dev"/><br /><sub><b>localhost.dev</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Alocalhostdotdev" title="Bug reports">🐛</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=localhostdotdev" title="Code">💻</a></td><td align="center"><a href="https://deecewan.github.io"><img src="https://avatars0.githubusercontent.com/u/4755785?v=4" width="100px;" alt="David Buchan-Swanson"/><br /><sub><b>David Buchan-Swanson</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Adeecewan" title="Bug reports">🐛</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=deecewan" title="Code">💻</a></td></tr><tr><td align="center"><a href="https://github.com/jpickwell"><img src="https://avatars1.githubusercontent.com/u/4682321?v=4" width="100px;" alt="Jordan Pickwell"/><br /><sub><b>Jordan Pickwell</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Ajpickwell" title="Bug reports">🐛</a></td><td align="center"><a href="http://codingitwrong.com"><img src="https://avatars0.githubusercontent.com/u/15832198?v=4" width="100px;" alt="Josh Justice"/><br /><sub><b>Josh Justice</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3ACodingItWrong" title="Bug reports">🐛</a></td><td align="center"><a href="https://github.com/xipgroc"><img src="https://avatars0.githubusercontent.com/u/28561131?v=4" width="100px;" alt="xipgroc"/><br /><sub><b>xipgroc</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Axipgroc" title="Bug reports">🐛</a></td></tr></table> | ||
@@ -151,0 +152,0 @@ <!-- ALL-CONTRIBUTORS-LIST:END --> |
346
src/nodes.js
@@ -1,6 +0,31 @@ | ||
const { align, breakParent, concat, dedent, group, hardline, ifBreak, indent, join, line, literalline, markAsRoot, softline, trim } = require("prettier").doc.builders; | ||
const { removeLines } = require("prettier").doc.utils; | ||
const { | ||
align, | ||
breakParent, | ||
concat, | ||
dedent, | ||
group, | ||
hardline, | ||
ifBreak, | ||
indent, | ||
join, | ||
line, | ||
literalline, | ||
markAsRoot, | ||
removeLines, | ||
softline, | ||
trim | ||
} = require("./builders"); | ||
const toProc = require("./toProc"); | ||
const { concatBody, empty, first, literal, makeArgs, makeCall, makeList, prefix, skipAssignIndent } = require("./utils"); | ||
const { | ||
concatBody, | ||
empty, | ||
first, | ||
literal, | ||
makeArgs, | ||
makeCall, | ||
makeList, | ||
prefix, | ||
skipAssignIndent | ||
} = require("./utils"); | ||
@@ -21,3 +46,7 @@ const nodes = { | ||
if (!body.startsWith("0") && body.length >= 4 && !body.includes("_")) { | ||
return ` ${body}`.slice((body.length + 2) % 3).match(/.{3}/g).join("_").trim(); | ||
return ` ${body}` | ||
.slice((body.length + 2) % 3) | ||
.match(/.{3}/g) | ||
.join("_") | ||
.trim(); | ||
} | ||
@@ -47,11 +76,15 @@ | ||
const parenDoc = group(concat([ | ||
"(", | ||
indent(concat([ | ||
softline, | ||
join(concat([",", line]), args), | ||
addTrailingCommas && !hasBlock ? ifBreak(",", "") : "" | ||
])), | ||
concat([softline, ")"]) | ||
])); | ||
const parenDoc = group( | ||
concat([ | ||
"(", | ||
indent( | ||
concat([ | ||
softline, | ||
join(concat([",", line]), args), | ||
addTrailingCommas && !hasBlock ? ifBreak(",", "") : "" | ||
]) | ||
), | ||
concat([softline, ")"]) | ||
]) | ||
); | ||
@@ -70,3 +103,6 @@ if (heredocs.length === 1) { | ||
const parentNode = path.getParentNode(parent); | ||
blockNode = parentNode && parentNode.type === "method_add_block" && parentNode.body[1]; | ||
blockNode = | ||
parentNode && | ||
parentNode.type === "method_add_block" && | ||
parentNode.body[1]; | ||
return blockNode; | ||
@@ -93,3 +129,5 @@ }); | ||
const printed = path.map(print, "body"); | ||
const parts = printed[0].concat([concat(["*", printed[1]])]).concat(printed.slice(2)); | ||
const parts = printed[0] | ||
.concat([concat(["*", printed[1]])]) | ||
.concat(printed.slice(2)); | ||
@@ -103,3 +141,7 @@ return parts; | ||
if (["mrhs_add_star", "mrhs_new_from_args"].includes(path.getValue().body[1].type)) { | ||
if ( | ||
["mrhs_add_star", "mrhs_new_from_args"].includes( | ||
path.getValue().body[1].type | ||
) | ||
) { | ||
adjustedValue = group(join(concat([",", line]), printedValue)); | ||
@@ -112,7 +154,5 @@ } | ||
return group(concat([ | ||
printedTarget, | ||
" =", | ||
indent(concat([line, adjustedValue])) | ||
])); | ||
return group( | ||
concat([printedTarget, " =", indent(concat([line, adjustedValue]))]) | ||
); | ||
}, | ||
@@ -126,7 +166,11 @@ assign_error: (_path, _opts, _print) => { | ||
return group(concat([ | ||
concat([path.call(print, "body", 0), useNoSpace ? "" : " "]), | ||
operator, | ||
indent(concat([useNoSpace ? softline : line, path.call(print, "body", 2)])) | ||
])); | ||
return group( | ||
concat([ | ||
concat([path.call(print, "body", 0), useNoSpace ? "" : " "]), | ||
operator, | ||
indent( | ||
concat([useNoSpace ? softline : line, path.call(print, "body", 2)]) | ||
) | ||
]) | ||
); | ||
}, | ||
@@ -155,3 +199,6 @@ block_var: (path, opts, print) => { | ||
// Before Ruby 2.6, this piece of bodystmt was an explicit "else" node | ||
const stmts = elseClause.type === "else" ? path.call(print, "body", 2, "body", 0) : path.call(print, "body", 2); | ||
const stmts = | ||
elseClause.type === "else" | ||
? path.call(print, "body", 2, "body", 0) | ||
: path.call(print, "body", 2); | ||
@@ -175,3 +222,6 @@ parts.push(concat([dedent(concat([hardline, "else"])), hardline, stmts])); | ||
if (content.body[0].body[0].type === "paren") { | ||
return concat(["break ", path.call(print, "body", 0, "body", 0, "body", 0, "body", 0)]); | ||
return concat([ | ||
"break ", | ||
path.call(print, "body", 0, "body", 0, "body", 0, "body", 0) | ||
]); | ||
} | ||
@@ -195,7 +245,9 @@ | ||
return group(concat([ | ||
concat(parts), | ||
indent(concat([hardline, path.call(print, "body", 2)])), | ||
concat([hardline, "end"]) | ||
])); | ||
return group( | ||
concat([ | ||
concat(parts), | ||
indent(concat([hardline, path.call(print, "body", 2)])), | ||
concat([hardline, "end"]) | ||
]) | ||
); | ||
}, | ||
@@ -208,17 +260,22 @@ class_name_error: (_path, _opts, _print) => { | ||
const_ref: first, | ||
defined: (path, opts, print) => group(concat([ | ||
"defined?(", | ||
indent(concat([softline, path.call(print, "body", 0)])), | ||
concat([softline, ")"]) | ||
])), | ||
dot2: (path, opts, print) => concat([ | ||
path.call(print, "body", 0), | ||
"..", | ||
path.getValue().body[1] ? path.call(print, "body", 1) : "" | ||
]), | ||
dot3: (path, opts, print) => concat([ | ||
path.call(print, "body", 0), | ||
"...", | ||
path.getValue().body[1] ? path.call(print, "body", 1) : "" | ||
]), | ||
defined: (path, opts, print) => | ||
group( | ||
concat([ | ||
"defined?(", | ||
indent(concat([softline, path.call(print, "body", 0)])), | ||
concat([softline, ")"]) | ||
]) | ||
), | ||
dot2: (path, opts, print) => | ||
concat([ | ||
path.call(print, "body", 0), | ||
"..", | ||
path.getValue().body[1] ? path.call(print, "body", 1) : "" | ||
]), | ||
dot3: (path, opts, print) => | ||
concat([ | ||
path.call(print, "body", 0), | ||
"...", | ||
path.getValue().body[1] ? path.call(print, "body", 1) : "" | ||
]), | ||
dyna_symbol: (path, opts, print) => { | ||
@@ -233,3 +290,5 @@ const { quote } = path.getValue().body[0]; | ||
return concat([ | ||
stmts.body.length === 1 && stmts.body[0].type === "command" ? breakParent : "", | ||
stmts.body.length === 1 && stmts.body[0].type === "command" | ||
? breakParent | ||
: "", | ||
"else", | ||
@@ -242,18 +301,27 @@ indent(concat([softline, path.call(print, "body", 0)])) | ||
fcall: concatBody, | ||
field: (path, opts, print) => group(concat([ | ||
path.call(print, "body", 0), | ||
concat([makeCall(path, opts, print), path.call(print, "body", 2)]) | ||
])), | ||
field: (path, opts, print) => | ||
group( | ||
concat([ | ||
path.call(print, "body", 0), | ||
concat([makeCall(path, opts, print), path.call(print, "body", 2)]) | ||
]) | ||
), | ||
massign: (path, opts, print) => { | ||
let right = path.call(print, "body", 1); | ||
if (["mrhs_add_star", "mrhs_new_from_args"].includes(path.getValue().body[1].type)) { | ||
if ( | ||
["mrhs_add_star", "mrhs_new_from_args"].includes( | ||
path.getValue().body[1].type | ||
) | ||
) { | ||
right = group(join(concat([",", line]), right)); | ||
} | ||
return group(concat([ | ||
group(join(concat([",", line]), path.call(print, "body", 0))), | ||
" =", | ||
indent(concat([line, right])) | ||
])); | ||
return group( | ||
concat([ | ||
group(join(concat([",", line]), path.call(print, "body", 0))), | ||
" =", | ||
indent(concat([line, right])) | ||
]) | ||
); | ||
}, | ||
@@ -273,5 +341,16 @@ method_add_arg: (path, opts, print) => { | ||
method_add_block: (path, opts, print) => { | ||
const [_method, block] = path.getValue().body; | ||
const [method, block] = path.getValue().body; | ||
const proc = toProc(block); | ||
if (toProc(block)) { | ||
if (proc && method.type === "call") { | ||
return group( | ||
concat([ | ||
path.call(print, "body", 0), | ||
"(", | ||
indent(concat([softline, proc])), | ||
concat([softline, ")"]) | ||
]) | ||
); | ||
} | ||
if (proc) { | ||
return path.call(print, "body", 0); | ||
@@ -283,10 +362,12 @@ } | ||
mlhs: makeList, | ||
mlhs_add_post: (path, opts, print) => ( | ||
path.call(print, "body", 0).concat(path.call(print, "body", 1)) | ||
), | ||
mlhs_add_star: (path, opts, print) => ( | ||
path.call(print, "body", 0).concat([ | ||
path.getValue().body[1] ? concat(["*", path.call(print, "body", 1)]) : "*" | ||
]) | ||
), | ||
mlhs_add_post: (path, opts, print) => | ||
path.call(print, "body", 0).concat(path.call(print, "body", 1)), | ||
mlhs_add_star: (path, opts, print) => | ||
path | ||
.call(print, "body", 0) | ||
.concat([ | ||
path.getValue().body[1] | ||
? concat(["*", path.call(print, "body", 1)]) | ||
: "*" | ||
]), | ||
mlhs_paren: (path, opts, print) => { | ||
@@ -300,12 +381,20 @@ if (["massign", "mlhs_paren"].includes(path.getParentNode().type)) { | ||
return group(concat([ | ||
"(", | ||
indent(concat([softline, join(concat([",", line]), path.call(print, "body", 0))])), | ||
concat([softline, ")"]) | ||
])); | ||
return group( | ||
concat([ | ||
"(", | ||
indent( | ||
concat([ | ||
softline, | ||
join(concat([",", line]), path.call(print, "body", 0)) | ||
]) | ||
), | ||
concat([softline, ")"]) | ||
]) | ||
); | ||
}, | ||
mrhs: makeList, | ||
mrhs_add_star: (path, opts, print) => ( | ||
path.call(print, "body", 0).concat([concat(["*", path.call(print, "body", 1)])]) | ||
), | ||
mrhs_add_star: (path, opts, print) => | ||
path | ||
.call(print, "body", 0) | ||
.concat([concat(["*", path.call(print, "body", 1)])]), | ||
mrhs_new_from_args: (path, opts, print) => { | ||
@@ -329,7 +418,9 @@ const parts = path.call(print, "body", 0); | ||
return group(concat([ | ||
declaration, | ||
indent(concat([hardline, path.call(print, "body", 1)])), | ||
concat([hardline, "end"]) | ||
])); | ||
return group( | ||
concat([ | ||
declaration, | ||
indent(concat([hardline, path.call(print, "body", 1)])), | ||
concat([hardline, "end"]) | ||
]) | ||
); | ||
}, | ||
@@ -345,3 +436,6 @@ next: (path, opts, print) => { | ||
// Ignoring the parens node and just going straight to the content | ||
return concat(["next ", path.call(print, "body", 0, "body", 0, "body", 0, "body", 0)]); | ||
return concat([ | ||
"next ", | ||
path.call(print, "body", 0, "body", 0, "body", 0, "body", 0) | ||
]); | ||
} | ||
@@ -352,8 +446,11 @@ | ||
number_arg: first, | ||
opassign: (path, opts, print) => group(concat([ | ||
path.call(print, "body", 0), | ||
" ", | ||
path.call(print, "body", 1), | ||
indent(concat([line, path.call(print, "body", 2)])) | ||
])), | ||
opassign: (path, opts, print) => | ||
group( | ||
concat([ | ||
path.call(print, "body", 0), | ||
" ", | ||
path.call(print, "body", 1), | ||
indent(concat([line, path.call(print, "body", 2)])) | ||
]) | ||
), | ||
paren: (path, opts, print) => { | ||
@@ -366,16 +463,22 @@ if (!path.getValue().body[0]) { | ||
if (["args", "args_add_star", "args_add_block"].includes(path.getValue().body[0].type)) { | ||
if ( | ||
["args", "args_add_star", "args_add_block"].includes( | ||
path.getValue().body[0].type | ||
) | ||
) { | ||
content = join(concat([",", line]), content); | ||
} | ||
return group(concat([ | ||
"(", | ||
indent(concat([softline, content])), | ||
concat([softline, ")"]) | ||
])); | ||
return group( | ||
concat([ | ||
"(", | ||
indent(concat([softline, content])), | ||
concat([softline, ")"]) | ||
]) | ||
); | ||
}, | ||
program: (path, opts, print) => markAsRoot(concat([ | ||
join(literalline, path.map(print, "body")), | ||
literalline | ||
])), | ||
program: (path, opts, print) => | ||
markAsRoot( | ||
concat([join(literalline, path.map(print, "body")), literalline]) | ||
), | ||
return: (path, opts, print) => { | ||
@@ -390,3 +493,6 @@ const args = path.getValue().body[0].body[0]; | ||
// Ignoring the parens node and just going straight to the content | ||
return concat(["return ", path.call(print, "body", 0, "body", 0, "body", 0, "body", 0)]); | ||
return concat([ | ||
"return ", | ||
path.call(print, "body", 0, "body", 0, "body", 0, "body", 0) | ||
]); | ||
} | ||
@@ -397,7 +503,10 @@ | ||
return0: literal("return"), | ||
sclass: (path, opts, print) => group(concat([ | ||
concat(["class << ", path.call(print, "body", 0)]), | ||
indent(concat([hardline, path.call(print, "body", 1)])), | ||
concat([hardline, "end"]) | ||
])), | ||
sclass: (path, opts, print) => | ||
group( | ||
concat([ | ||
concat(["class << ", path.call(print, "body", 0)]), | ||
indent(concat([hardline, path.call(print, "body", 1)])), | ||
concat([hardline, "end"]) | ||
]) | ||
), | ||
stmts: (path, opts, print) => { | ||
@@ -417,5 +526,11 @@ const stmts = path.getValue().body; | ||
parts.push(printed); | ||
} else if (stmt.start - lineNo > 1 || [stmt.type, stmts[index - 1].type].includes("access_ctrl")) { | ||
} else if ( | ||
stmt.start - lineNo > 1 || | ||
[stmt.type, stmts[index - 1].type].includes("access_ctrl") | ||
) { | ||
parts.push(hardline, hardline, printed); | ||
} else if (stmt.start !== lineNo || path.getParentNode().type !== "string_embexpr") { | ||
} else if ( | ||
stmt.start !== lineNo || | ||
path.getParentNode().type !== "string_embexpr" | ||
) { | ||
parts.push(hardline, printed); | ||
@@ -459,9 +574,12 @@ } else { | ||
}, | ||
undef: (path, opts, print) => group(concat([ | ||
"undef ", | ||
align( | ||
"undef ".length, | ||
join(concat([",", line]), path.map(print, "body", 0)) | ||
) | ||
])), | ||
undef: (path, opts, print) => | ||
group( | ||
concat([ | ||
"undef ", | ||
align( | ||
"undef ".length, | ||
join(concat([",", line]), path.map(print, "body", 0)) | ||
) | ||
]) | ||
), | ||
var_field: concatBody, | ||
@@ -468,0 +586,0 @@ var_ref: first, |
@@ -1,2 +0,2 @@ | ||
const { concat, join } = require("prettier").doc.builders; | ||
const { concat, join } = require("../builders"); | ||
@@ -8,5 +8,4 @@ const usingSymbols = path => { | ||
const identFromSymbol = (path, print, index) => ( | ||
path.call(print, "body", index, "body", 0, "body", 0) | ||
); | ||
const identFromSymbol = (path, print, index) => | ||
path.call(print, "body", index, "body", 0, "body", 0); | ||
@@ -19,3 +18,6 @@ const aliasError = (_path, _opts, _print) => { | ||
if (usingSymbols(path)) { | ||
return join(" ", [identFromSymbol(path, print, 0), identFromSymbol(path, print, 1)]); | ||
return join(" ", [ | ||
identFromSymbol(path, print, 0), | ||
identFromSymbol(path, print, 1) | ||
]); | ||
} | ||
@@ -25,3 +27,4 @@ return join(" ", path.map(print, "body")); | ||
const alias = (path, opts, print) => concat(["alias ", aliasVars(path, opts, print)]); | ||
const alias = (path, opts, print) => | ||
concat(["alias ", aliasVars(path, opts, print)]); | ||
@@ -28,0 +31,0 @@ module.exports = { |
@@ -1,38 +0,56 @@ | ||
const { concat, group, ifBreak, indent, join, line, literalline, softline } = require("prettier").doc.builders; | ||
const { | ||
concat, | ||
group, | ||
ifBreak, | ||
indent, | ||
join, | ||
line, | ||
literalline, | ||
softline | ||
} = require("../builders"); | ||
const isStringArray = args => args.body.every(arg => ( | ||
arg.type === "string_literal" | ||
&& arg.body[0].body.length === 1 | ||
&& arg.body[0].body[0].type === "@tstring_content" | ||
&& !arg.body[0].body[0].body.includes(" ") | ||
)); | ||
const isStringArray = args => | ||
args.body.every( | ||
arg => | ||
arg.type === "string_literal" && | ||
arg.body[0].body.length === 1 && | ||
arg.body[0].body[0].type === "@tstring_content" && | ||
!arg.body[0].body[0].body.includes(" ") | ||
); | ||
const isSymbolArray = args => args.body.every(arg => ( | ||
arg.type === "symbol_literal" | ||
)); | ||
const isSymbolArray = args => | ||
args.body.every(arg => arg.type === "symbol_literal"); | ||
const makeArray = start => (path, opts, print) => ( | ||
[start].concat(path.map(print, "body")) | ||
); | ||
const makeArray = start => (path, opts, print) => | ||
[start].concat(path.map(print, "body")); | ||
const getSpecialArrayParts = (path, print, args) => args.body.map((_arg, index) => ( | ||
path.call(print, "body", 0, "body", index, "body", 0, "body", 0) | ||
)); | ||
const getSpecialArrayParts = (path, print, args) => | ||
args.body.map((_arg, index) => | ||
path.call(print, "body", 0, "body", index, "body", 0, "body", 0) | ||
); | ||
const printAref = (path, opts, print) => group(concat([ | ||
path.call(print, "body", 0), | ||
"[", | ||
indent(concat([ | ||
softline, | ||
join(concat([",", line]), path.call(print, "body", 1)) | ||
])), | ||
concat([softline, "]"]) | ||
])); | ||
const printAref = (path, opts, print) => | ||
group( | ||
concat([ | ||
path.call(print, "body", 0), | ||
"[", | ||
indent( | ||
concat([ | ||
softline, | ||
join(concat([",", line]), path.call(print, "body", 1)) | ||
]) | ||
), | ||
concat([softline, "]"]) | ||
]) | ||
); | ||
const printSpecialArray = parts => group(concat([ | ||
parts[0], | ||
"[", | ||
indent(concat([softline, join(line, parts.slice(1))])), | ||
concat([softline, "]"]) | ||
])); | ||
const printSpecialArray = parts => | ||
group( | ||
concat([ | ||
parts[0], | ||
"[", | ||
indent(concat([softline, join(line, parts.slice(1))])), | ||
concat([softline, "]"]) | ||
]) | ||
); | ||
@@ -75,7 +93,11 @@ // Extract out the actual elements, taking into account nesting with | ||
if (isStringArray(args)) { | ||
return printSpecialArray(["%w"].concat(getSpecialArrayParts(path, print, args))); | ||
return printSpecialArray( | ||
["%w"].concat(getSpecialArrayParts(path, print, args)) | ||
); | ||
} | ||
if (isSymbolArray(args)) { | ||
return printSpecialArray(["%i"].concat(getSpecialArrayParts(path, print, args))); | ||
return printSpecialArray( | ||
["%i"].concat(getSpecialArrayParts(path, print, args)) | ||
); | ||
} | ||
@@ -99,3 +121,4 @@ | ||
const isStraightHeredoc = element.type === "heredoc"; | ||
const isSquigglyHeredoc = element.type === "string_literal" && element.body[0].type === "heredoc"; | ||
const isSquigglyHeredoc = | ||
element.type === "string_literal" && element.body[0].type === "heredoc"; | ||
@@ -112,3 +135,3 @@ if (isStraightHeredoc || isSquigglyHeredoc) { | ||
heredocNode.beging, | ||
(isInner || addTrailingCommas) ? "," : "", | ||
isInner || addTrailingCommas ? "," : "", | ||
literalline, | ||
@@ -130,7 +153,9 @@ concat(path.map.apply(path, heredocPath.concat("body"))), | ||
return group(concat([ | ||
"[", | ||
indent(concat([softline].concat(normalDocs))), | ||
concat([softline, "]"]) | ||
])); | ||
return group( | ||
concat([ | ||
"[", | ||
indent(concat([softline].concat(normalDocs))), | ||
concat([softline, "]"]) | ||
]) | ||
); | ||
}, | ||
@@ -137,0 +162,0 @@ qsymbols: makeArray("%i"), |
@@ -1,2 +0,9 @@ | ||
const { breakParent, concat, group, ifBreak, indent, softline } = require("prettier").doc.builders; | ||
const { | ||
breakParent, | ||
concat, | ||
group, | ||
ifBreak, | ||
indent, | ||
softline | ||
} = require("../builders"); | ||
const { hasAncestor } = require("../utils"); | ||
@@ -6,3 +13,4 @@ | ||
const [variables, statements] = path.getValue().body; | ||
const stmts = statements.type === "stmts" ? statements.body : statements.body[0].body; | ||
const stmts = | ||
statements.type === "stmts" ? statements.body : statements.body[0].body; | ||
@@ -30,3 +38,6 @@ let doBlockBody = ""; | ||
// comment. | ||
if (stmts.length > 1 && stmts.filter(stmt => stmt.type !== "@comment").length === 1) { | ||
if ( | ||
stmts.length > 1 && | ||
stmts.filter(stmt => stmt.type !== "@comment").length === 1 | ||
) { | ||
return concat([breakParent, doBlock]); | ||
@@ -44,3 +55,3 @@ } | ||
" {", | ||
(hasBody || variables) ? " " : "", | ||
hasBody || variables ? " " : "", | ||
variables ? path.call(print, "body", 0) : "", | ||
@@ -47,0 +58,0 @@ path.call(print, "body", 1), |
@@ -1,10 +0,5 @@ | ||
const { concat, group, indent, softline } = require("prettier").doc.builders; | ||
const { concat, group, indent, softline } = require("../builders"); | ||
const { makeCall } = require("../utils"); | ||
const noIndent = [ | ||
"array", | ||
"hash", | ||
"method_add_block", | ||
"xstring_literal" | ||
]; | ||
const noIndent = ["array", "hash", "method_add_block", "xstring_literal"]; | ||
@@ -29,4 +24,6 @@ module.exports = { | ||
return group(concat([receiver, indent(concat([softline, operator, name]))])); | ||
return group( | ||
concat([receiver, indent(concat([softline, operator, name]))]) | ||
); | ||
} | ||
}; |
@@ -1,2 +0,10 @@ | ||
const { align, concat, fill, group, hardline, indent, line } = require("prettier").doc.builders; | ||
const { | ||
align, | ||
concat, | ||
fill, | ||
group, | ||
hardline, | ||
indent, | ||
line | ||
} = require("../builders"); | ||
@@ -13,8 +21,5 @@ module.exports = { | ||
return concat(statement.concat([ | ||
hardline, | ||
path.call(print, "body", 1), | ||
hardline, | ||
"end" | ||
])); | ||
return concat( | ||
statement.concat([hardline, path.call(print, "body", 1), hardline, "end"]) | ||
); | ||
}, | ||
@@ -26,8 +31,11 @@ when: (path, opts, print) => { | ||
// line breaks. This is so it can loop through and determine where to break. | ||
const preds = fill(path.call(print, "body", 0).reduce( | ||
(accum, pred, index) => ( | ||
index === 0 ? [pred] : accum.concat([",", line, pred]) | ||
), | ||
null | ||
)); | ||
const preds = fill( | ||
path | ||
.call(print, "body", 0) | ||
.reduce( | ||
(accum, pred, index) => | ||
index === 0 ? [pred] : accum.concat([",", line, pred]), | ||
null | ||
) | ||
); | ||
@@ -34,0 +42,0 @@ const stmts = path.call(print, "body", 1); |
@@ -1,9 +0,8 @@ | ||
const { align, concat, group, ifBreak, join, line } = require("prettier").doc.builders; | ||
const { align, concat, group, ifBreak, join, line } = require("../builders"); | ||
const { docLength, makeArgs, makeCall } = require("../utils"); | ||
const hasDef = node => ( | ||
node.body[1].type === "args_add_block" | ||
&& node.body[1].body[0].type === "args" | ||
&& node.body[1].body[0].body[0].type === "def" | ||
); | ||
const hasDef = node => | ||
node.body[1].type === "args_add_block" && | ||
node.body[1].body[0].type === "args" && | ||
node.body[1].body[0].body[0].type === "def"; | ||
@@ -20,8 +19,12 @@ module.exports = { | ||
const joinedArgs = join(concat([",", line]), args); | ||
const breakArgs = hasDef(path.getValue()) ? joinedArgs : align(command.length + 1, joinedArgs); | ||
const breakArgs = hasDef(path.getValue()) | ||
? joinedArgs | ||
: align(command.length + 1, joinedArgs); | ||
const commandDoc = group(ifBreak( | ||
concat([command, " ", breakArgs]), | ||
concat([command, " ", joinedArgs]) | ||
)); | ||
const commandDoc = group( | ||
ifBreak( | ||
concat([command, " ", breakArgs]), | ||
concat([command, " ", joinedArgs]) | ||
) | ||
); | ||
@@ -53,10 +56,10 @@ if (heredocs.length === 1) { | ||
const joinedArgs = join(concat([",", line]), args); | ||
const breakArgs = path.getValue().body[2].body === "to" | ||
? joinedArgs | ||
: align(docLength(concat(parts)), joinedArgs); | ||
const breakArgs = | ||
path.getValue().body[2].body === "to" | ||
? joinedArgs | ||
: align(docLength(concat(parts)), joinedArgs); | ||
const commandDoc = group(ifBreak( | ||
concat(parts.concat(breakArgs)), | ||
concat(parts.concat(joinedArgs)) | ||
)); | ||
const commandDoc = group( | ||
ifBreak(concat(parts.concat(breakArgs)), concat(parts.concat(joinedArgs))) | ||
); | ||
@@ -63,0 +66,0 @@ if (heredocs.length === 1) { |
@@ -1,2 +0,11 @@ | ||
const { align, breakParent, concat, hardline, group, ifBreak, indent, softline } = require("prettier").doc.builders; | ||
const { | ||
align, | ||
breakParent, | ||
concat, | ||
hardline, | ||
group, | ||
ifBreak, | ||
indent, | ||
softline | ||
} = require("../builders"); | ||
@@ -31,10 +40,11 @@ const noTernary = [ | ||
const printWithAddition = (keyword, path, print, { breaking = false } = {}) => concat([ | ||
`${keyword} `, | ||
align(keyword.length - 1, path.call(print, "body", 0)), | ||
indent(concat([softline, path.call(print, "body", 1)])), | ||
concat([softline, path.call(print, "body", 2)]), | ||
concat([softline, "end"]), | ||
breaking ? breakParent : "" | ||
]); | ||
const printWithAddition = (keyword, path, print, { breaking = false } = {}) => | ||
concat([ | ||
`${keyword} `, | ||
align(keyword.length - 1, path.call(print, "body", 0)), | ||
indent(concat([softline, path.call(print, "body", 1)])), | ||
concat([softline, path.call(print, "body", 2)]), | ||
concat([softline, "end"]), | ||
breaking ? breakParent : "" | ||
]); | ||
@@ -46,5 +56,4 @@ const printTernaryConditions = (keyword, truthyValue, falsyValue) => { | ||
const canTernary = stmts => ( | ||
stmts.body.length === 1 && !noTernary.includes(stmts.body[0].type) | ||
); | ||
const canTernary = stmts => | ||
stmts.body.length === 1 && !noTernary.includes(stmts.body[0].type); | ||
@@ -61,17 +70,26 @@ const printConditional = keyword => (path, { inlineConditionals }, print) => { | ||
return group(ifBreak( | ||
concat([ | ||
`${keyword} `, | ||
path.call(print, "body", 0), | ||
indent(concat([softline, path.call(print, "body", 1)])), | ||
concat([softline, "else"]), | ||
indent(concat([softline, path.call(print, "body", 2)])), | ||
concat([softline, "end"]) | ||
]), | ||
concat(parts.concat(printTernaryConditions(keyword, truthyValue, falsyValue))) | ||
)); | ||
return group( | ||
ifBreak( | ||
concat([ | ||
`${keyword} `, | ||
path.call(print, "body", 0), | ||
indent(concat([softline, path.call(print, "body", 1)])), | ||
concat([softline, "else"]), | ||
indent(concat([softline, path.call(print, "body", 2)])), | ||
concat([softline, "end"]) | ||
]), | ||
concat( | ||
parts.concat(printTernaryConditions(keyword, truthyValue, falsyValue)) | ||
) | ||
) | ||
); | ||
} | ||
// If there is an else and only an else, attempt to shorten to a ternary | ||
if (addition && addition.type === "else" && canTernary(stmts) && canTernary(addition.body[0])) { | ||
if ( | ||
addition && | ||
addition.type === "else" && | ||
canTernary(stmts) && | ||
canTernary(addition.body[0]) | ||
) { | ||
const ternary = printTernaryConditions( | ||
@@ -83,6 +101,8 @@ keyword, | ||
return group(ifBreak( | ||
printWithAddition(keyword, path, print), | ||
concat([path.call(print, "body", 0), " ? "].concat(ternary)) | ||
)); | ||
return group( | ||
ifBreak( | ||
printWithAddition(keyword, path, print), | ||
concat([path.call(print, "body", 0), " ? "].concat(ternary)) | ||
) | ||
); | ||
} | ||
@@ -96,16 +116,18 @@ | ||
// If it's short enough, favor the inline conditional | ||
return group(ifBreak( | ||
concat([ | ||
`${keyword} `, | ||
align(keyword.length - 1, path.call(print, "body", 0)), | ||
indent(concat([softline, path.call(print, "body", 1)])), | ||
concat([softline, "end"]) | ||
]), | ||
concat([ | ||
inlineConditionals ? "" : breakParent, | ||
path.call(print, "body", 1), | ||
` ${keyword} `, | ||
path.call(print, "body", 0) | ||
]) | ||
)); | ||
return group( | ||
ifBreak( | ||
concat([ | ||
`${keyword} `, | ||
align(keyword.length - 1, path.call(print, "body", 0)), | ||
indent(concat([softline, path.call(print, "body", 1)])), | ||
concat([softline, "end"]) | ||
]), | ||
concat([ | ||
inlineConditionals ? "" : breakParent, | ||
path.call(print, "body", 1), | ||
` ${keyword} `, | ||
path.call(print, "body", 0) | ||
]) | ||
) | ||
); | ||
}; | ||
@@ -117,3 +139,8 @@ | ||
const parts = [ | ||
group(concat(["elsif ", align("elsif".length - 1, path.call(print, "body", 0))])), | ||
group( | ||
concat([ | ||
"elsif ", | ||
align("elsif".length - 1, path.call(print, "body", 0)) | ||
]) | ||
), | ||
indent(concat([hardline, path.call(print, "body", 1)])) | ||
@@ -120,0 +147,0 @@ ]; |
@@ -1,2 +0,10 @@ | ||
const { concat, group, ifBreak, indent, join, line, literalline } = require("prettier").doc.builders; | ||
const { | ||
concat, | ||
group, | ||
ifBreak, | ||
indent, | ||
join, | ||
line, | ||
literalline | ||
} = require("../builders"); | ||
const { skipAssignIndent } = require("../utils"); | ||
@@ -24,8 +32,17 @@ | ||
return `:${labelDoc.slice(0, labelDoc.length - 1)} =>`; | ||
case "symbol_literal": | ||
if (preferHashLabels && labelNode.body.length === 1) { | ||
case "symbol_literal": { | ||
// You can have a symbol literal as a key in a hash that ends with an = | ||
// character, which breaks when you use hash labels. | ||
const endsInEquals = labelNode.body[0].body[0].body.endsWith("="); | ||
if (preferHashLabels && labelNode.body.length === 1 && !endsInEquals) { | ||
const symbolSteps = steps.concat("body", 0, "body", 0); | ||
return concat([path.call.apply(path, [print].concat(symbolSteps)), ":"]); | ||
return concat([ | ||
path.call.apply(path, [print].concat(symbolSteps)), | ||
":" | ||
]); | ||
} | ||
return concat([labelDoc, " =>"]); | ||
} | ||
case "dyna_symbol": | ||
@@ -65,6 +82,10 @@ if (preferHashLabels) { | ||
const isStraightHeredoc = valueNode.type === "heredoc"; | ||
const isSquigglyHeredoc = valueNode.type === "string_literal" && valueNode.body[0].type === "heredoc"; | ||
const isSquigglyHeredoc = | ||
valueNode.type === "string_literal" && | ||
valueNode.body[0].type === "heredoc"; | ||
if (isStraightHeredoc || isSquigglyHeredoc) { | ||
const heredocSteps = isStraightHeredoc ? ["body", 1] : ["body", 1, "body", 0]; | ||
const heredocSteps = isStraightHeredoc | ||
? ["body", 1] | ||
: ["body", 1, "body", 0]; | ||
const { beging, ending } = nodeDive(assocNode, heredocSteps); | ||
@@ -76,5 +97,10 @@ | ||
beging, | ||
(isInner || addTrailingCommas) ? "," : "", | ||
isInner || addTrailingCommas ? "," : "", | ||
literalline, | ||
concat(path.map.apply(path, [print, "body", 0, index].concat(heredocSteps).concat("body"))), | ||
concat( | ||
path.map.apply( | ||
path, | ||
[print, "body", 0, index].concat(heredocSteps).concat("body") | ||
) | ||
), | ||
ending, | ||
@@ -96,5 +122,4 @@ isInner ? line : "" | ||
}, | ||
bare_assoc_hash: (path, opts, print) => group( | ||
join(concat([",", line]), path.map(print, "body", 0)) | ||
), | ||
bare_assoc_hash: (path, opts, print) => | ||
group(join(concat([",", line]), path.map(print, "body", 0))), | ||
hash: (path, opts, print) => { | ||
@@ -105,8 +130,10 @@ if (path.getValue().body[0] === null) { | ||
return group(concat([ | ||
"{", | ||
indent(concat([line, concat(path.map(print, "body"))])), | ||
concat([line, "}"]) | ||
])); | ||
return group( | ||
concat([ | ||
"{", | ||
indent(concat([line, concat(path.map(print, "body"))])), | ||
concat([line, "}"]) | ||
]) | ||
); | ||
} | ||
}; |
@@ -1,8 +0,11 @@ | ||
const { concat, group, indent, line } = require("prettier").doc.builders; | ||
const { concat, group, indent, line } = require("../builders"); | ||
const printHook = name => (path, opts, print) => group(concat([ | ||
`${name} {`, | ||
indent(concat([line, path.call(print, "body", 0)])), | ||
concat([line, "}"]) | ||
])); | ||
const printHook = name => (path, opts, print) => | ||
group( | ||
concat([ | ||
`${name} {`, | ||
indent(concat([line, path.call(print, "body", 0)])), | ||
concat([line, "}"]) | ||
]) | ||
); | ||
@@ -9,0 +12,0 @@ module.exports = { |
@@ -1,4 +0,10 @@ | ||
const { concat, group, ifBreak, indent, line, softline } = require("prettier").doc.builders; | ||
const { removeLines } = require("prettier").doc.utils; | ||
const { | ||
concat, | ||
group, | ||
ifBreak, | ||
indent, | ||
line, | ||
removeLines, | ||
softline | ||
} = require("../builders"); | ||
const { hasAncestor } = require("../utils"); | ||
@@ -14,3 +20,3 @@ | ||
} else { | ||
([params] = params.body); | ||
[params] = params.body; | ||
paramsConcat = path.call(print, "body", 0, "body", 0); | ||
@@ -29,23 +35,27 @@ } | ||
if (hasAncestor(path, ["command", "command_call"])) { | ||
return group(ifBreak( | ||
return group( | ||
ifBreak( | ||
concat([ | ||
"lambda {", | ||
noParams ? "" : concat([" |", removeLines(paramsConcat), "|"]), | ||
indent(concat([line, path.call(print, "body", 1)])), | ||
concat([line, "}"]) | ||
]), | ||
inlineLambda | ||
) | ||
); | ||
} | ||
return group( | ||
ifBreak( | ||
concat([ | ||
"lambda {", | ||
"lambda do", | ||
noParams ? "" : concat([" |", removeLines(paramsConcat), "|"]), | ||
indent(concat([line, path.call(print, "body", 1)])), | ||
concat([line, "}"]) | ||
indent(concat([softline, path.call(print, "body", 1)])), | ||
concat([softline, "end"]) | ||
]), | ||
inlineLambda | ||
)); | ||
} | ||
return group(ifBreak( | ||
concat([ | ||
"lambda do", | ||
noParams ? "" : concat([" |", removeLines(paramsConcat), "|"]), | ||
indent(concat([softline, path.call(print, "body", 1)])), | ||
concat([softline, "end"]) | ||
]), | ||
inlineLambda | ||
)); | ||
) | ||
); | ||
} | ||
}; |
@@ -1,25 +0,39 @@ | ||
const { breakParent, concat, group, hardline, ifBreak, indent, softline } = require("prettier").doc.builders; | ||
const { | ||
breakParent, | ||
concat, | ||
group, | ||
hardline, | ||
ifBreak, | ||
indent, | ||
softline | ||
} = require("../builders"); | ||
const printLoop = keyword => (path, { inlineLoops }, print) => group(ifBreak( | ||
concat([ | ||
concat([`${keyword} `, path.call(print, "body", 0)]), | ||
indent(concat([softline, path.call(print, "body", 1)])), | ||
concat([softline, "end"]) | ||
]), | ||
concat([ | ||
inlineLoops ? "" : breakParent, | ||
path.call(print, "body", 1), | ||
` ${keyword} `, | ||
path.call(print, "body", 0) | ||
]) | ||
)); | ||
const printLoop = keyword => (path, { inlineLoops }, print) => | ||
group( | ||
ifBreak( | ||
concat([ | ||
concat([`${keyword} `, path.call(print, "body", 0)]), | ||
indent(concat([softline, path.call(print, "body", 1)])), | ||
concat([softline, "end"]) | ||
]), | ||
concat([ | ||
inlineLoops ? "" : breakParent, | ||
path.call(print, "body", 1), | ||
` ${keyword} `, | ||
path.call(print, "body", 0) | ||
]) | ||
) | ||
); | ||
const printFor = (path, opts, print) => group(concat([ | ||
path.call(print, "body", 1), | ||
".each do |", | ||
path.call(print, "body", 0), | ||
"|", | ||
indent(concat([hardline, path.call(print, "body", 2)])), | ||
concat([hardline, "end"]) | ||
])); | ||
const printFor = (path, opts, print) => | ||
group( | ||
concat([ | ||
path.call(print, "body", 1), | ||
".each do |", | ||
path.call(print, "body", 0), | ||
"|", | ||
indent(concat([hardline, path.call(print, "body", 2)])), | ||
concat([hardline, "end"]) | ||
]) | ||
); | ||
@@ -26,0 +40,0 @@ module.exports = { |
@@ -1,2 +0,2 @@ | ||
const { concat, group, hardline, indent } = require("prettier").doc.builders; | ||
const { concat, group, hardline, indent } = require("../builders"); | ||
@@ -14,3 +14,4 @@ const printMethod = offset => (path, opts, print) => { | ||
// In case there are no parens but there are arguments | ||
const parens = params.type === "params" && params.body.some(paramType => paramType); | ||
const parens = | ||
params.type === "params" && params.body.some(paramType => paramType); | ||
@@ -30,7 +31,9 @@ declaration.push( | ||
return group(concat([ | ||
group(concat(declaration)), | ||
indent(concat([hardline, path.call(print, "body", offset + 2)])), | ||
group(concat([hardline, "end"])) | ||
])); | ||
return group( | ||
concat([ | ||
group(concat(declaration)), | ||
indent(concat([hardline, path.call(print, "body", offset + 2)])), | ||
group(concat([hardline, "end"])) | ||
]) | ||
); | ||
}; | ||
@@ -37,0 +40,0 @@ |
@@ -1,9 +0,18 @@ | ||
const { concat, group, join, line } = require("prettier").doc.builders; | ||
const { concat, group, join, line } = require("../builders"); | ||
const printGenericRestParam = symbol => (path, opts, print) => ( | ||
path.getValue().body[0] ? concat([symbol, path.call(print, "body", 0)]) : symbol | ||
); | ||
const printGenericRestParam = symbol => (path, opts, print) => | ||
path.getValue().body[0] | ||
? concat([symbol, path.call(print, "body", 0)]) | ||
: symbol; | ||
const printParams = (path, opts, print) => { | ||
const [reqs, optls, rest, post, kwargs, kwargRest, block] = path.getValue().body; | ||
const [ | ||
reqs, | ||
optls, | ||
rest, | ||
post, | ||
kwargs, | ||
kwargRest, | ||
block | ||
] = path.getValue().body; | ||
let parts = []; | ||
@@ -16,7 +25,11 @@ | ||
if (optls) { | ||
parts = parts.concat(optls.map((_, index) => concat([ | ||
path.call(print, "body", 1, index, 0), | ||
" = ", | ||
path.call(print, "body", 1, index, 1) | ||
]))); | ||
parts = parts.concat( | ||
optls.map((_, index) => | ||
concat([ | ||
path.call(print, "body", 1, index, 0), | ||
" = ", | ||
path.call(print, "body", 1, index, 1) | ||
]) | ||
) | ||
); | ||
} | ||
@@ -33,8 +46,10 @@ | ||
if (kwargs) { | ||
parts = parts.concat(kwargs.map(([, value], index) => { | ||
if (!value) { | ||
return path.call(print, "body", 4, index, 0); | ||
} | ||
return group(join(" ", path.map(print, "body", 4, index))); | ||
})); | ||
parts = parts.concat( | ||
kwargs.map(([, value], index) => { | ||
if (!value) { | ||
return path.call(print, "body", 4, index, 0); | ||
} | ||
return group(join(" ", path.map(print, "body", 4, index))); | ||
}) | ||
); | ||
} | ||
@@ -41,0 +56,0 @@ |
@@ -1,2 +0,2 @@ | ||
const { concat } = require("prettier").doc.builders; | ||
const { concat } = require("../builders"); | ||
const { makeList } = require("../utils"); | ||
@@ -9,4 +9,8 @@ | ||
const useBraces = contents.some(content => typeof content === "string" && content.includes("/")); | ||
const parts = [useBraces ? "%r{" : "/"].concat(contents).concat([useBraces ? "}" : "/", ending.slice(1)]); | ||
const useBraces = contents.some( | ||
content => typeof content === "string" && content.includes("/") | ||
); | ||
const parts = [useBraces ? "%r{" : "/"] | ||
.concat(contents) | ||
.concat([useBraces ? "}" : "/", ending.slice(1)]); | ||
@@ -13,0 +17,0 @@ return concat(parts); |
@@ -1,15 +0,25 @@ | ||
const { align, concat, group, hardline, indent, join, line } = require("prettier").doc.builders; | ||
const { | ||
align, | ||
concat, | ||
group, | ||
hardline, | ||
indent, | ||
join, | ||
line | ||
} = require("../builders"); | ||
const { literal } = require("../utils"); | ||
module.exports = { | ||
begin: (path, opts, print) => concat([ | ||
"begin", | ||
indent(concat([hardline, concat(path.map(print, "body"))])), | ||
hardline, | ||
"end" | ||
]), | ||
ensure: (path, opts, print) => concat([ | ||
"ensure", | ||
indent(concat([hardline, concat(path.map(print, "body"))])) | ||
]), | ||
begin: (path, opts, print) => | ||
concat([ | ||
"begin", | ||
indent(concat([hardline, concat(path.map(print, "body"))])), | ||
hardline, | ||
"end" | ||
]), | ||
ensure: (path, opts, print) => | ||
concat([ | ||
"ensure", | ||
indent(concat([hardline, concat(path.map(print, "body"))])) | ||
]), | ||
redo: literal("redo"), | ||
@@ -56,12 +66,13 @@ rescue: (path, opts, print) => { | ||
}, | ||
rescue_mod: (path, opts, print) => concat([ | ||
"begin", | ||
indent(concat([hardline, path.call(print, "body", 0)])), | ||
hardline, | ||
"rescue StandardError", | ||
indent(concat([hardline, path.call(print, "body", 1)])), | ||
hardline, | ||
"end" | ||
]), | ||
rescue_mod: (path, opts, print) => | ||
concat([ | ||
"begin", | ||
indent(concat([hardline, path.call(print, "body", 0)])), | ||
hardline, | ||
"rescue StandardError", | ||
indent(concat([hardline, path.call(print, "body", 1)])), | ||
hardline, | ||
"end" | ||
]), | ||
retry: literal("retry") | ||
}; |
@@ -1,2 +0,10 @@ | ||
const { concat, group, hardline, indent, join, literalline, softline } = require("prettier").doc.builders; | ||
const { | ||
concat, | ||
group, | ||
hardline, | ||
indent, | ||
join, | ||
literalline, | ||
softline | ||
} = require("../builders"); | ||
const { concatBody, empty, makeList, surround } = require("../utils"); | ||
@@ -10,13 +18,15 @@ const escapePattern = require("../escapePattern"); | ||
// single quotes would deactivate it.) | ||
const isQuoteLocked = string => string.body.some(part => ( | ||
part.type === "@tstring_content" && ( | ||
escapePattern.test(part.body) || part.body.includes("#{") | ||
) | ||
)); | ||
const isQuoteLocked = string => | ||
string.body.some( | ||
part => | ||
part.type === "@tstring_content" && | ||
(escapePattern.test(part.body) || part.body.includes("#{")) | ||
); | ||
// A string is considered to be able to use single quotes if it contains only | ||
// plain string content and that content does not contain a single quote. | ||
const isSingleQuotable = string => string.body.every(part => ( | ||
part.type === "@tstring_content" && !part.body.includes("'") | ||
)); | ||
const isSingleQuotable = string => | ||
string.body.every( | ||
part => part.type === "@tstring_content" && !part.body.includes("'") | ||
); | ||
@@ -28,3 +38,3 @@ const getStringQuote = (string, preferSingleQuotes) => { | ||
return preferSingleQuotes && isSingleQuotable(string) ? "'" : "\""; | ||
return preferSingleQuotes && isSingleQuotable(string) ? "'" : '"'; | ||
}; | ||
@@ -35,3 +45,3 @@ | ||
const makeString = (content, enclosingQuote) => { | ||
const otherQuote = enclosingQuote === "\"" ? "'" : enclosingQuote; | ||
const otherQuote = enclosingQuote === '"' ? "'" : enclosingQuote; | ||
@@ -65,3 +75,3 @@ // Escape and unescape single and double quotes as needed to be able to | ||
const quote = preferSingleQuotes ? "'" : "\""; | ||
const quote = preferSingleQuotes ? "'" : '"'; | ||
return body.length === 2 ? concat([quote, body.slice(1), quote]) : body; | ||
@@ -79,13 +89,19 @@ }, | ||
string: makeList, | ||
string_concat: (path, opts, print) => group(concat([ | ||
path.call(print, "body", 0), | ||
" \\", | ||
indent(concat([hardline, path.call(print, "body", 1)])) | ||
])), | ||
string_concat: (path, opts, print) => | ||
group( | ||
concat([ | ||
path.call(print, "body", 0), | ||
" \\", | ||
indent(concat([hardline, path.call(print, "body", 1)])) | ||
]) | ||
), | ||
string_dvar: surround("#{", "}"), | ||
string_embexpr: (path, opts, print) => group(concat([ | ||
"#{", | ||
indent(concat([softline, path.call(print, "body", 0)])), | ||
concat([softline, "}"]) | ||
])), | ||
string_embexpr: (path, opts, print) => | ||
group( | ||
concat([ | ||
"#{", | ||
indent(concat([softline, path.call(print, "body", 0)])), | ||
concat([softline, "}"]) | ||
]) | ||
), | ||
string_literal: (path, { preferSingleQuotes }, print) => { | ||
@@ -103,3 +119,3 @@ const string = path.getValue().body[0]; | ||
if (string.body.length === 0) { | ||
return preferSingleQuotes ? "''" : "\"\""; | ||
return preferSingleQuotes ? "''" : '""'; | ||
} | ||
@@ -125,7 +141,10 @@ | ||
xstring: makeList, | ||
xstring_literal: (path, opts, print) => group(concat([ | ||
"`", | ||
indent(concat([softline, join(softline, path.call(print, "body", 0))])), | ||
concat([softline, "`"]) | ||
])) | ||
xstring_literal: (path, opts, print) => | ||
group( | ||
concat([ | ||
"`", | ||
indent(concat([softline, join(softline, path.call(print, "body", 0))])), | ||
concat([softline, "`"]) | ||
]) | ||
) | ||
}; |
@@ -5,3 +5,5 @@ const { spawnSync } = require("child_process"); | ||
module.exports = (text, _parsers, _opts) => { | ||
const child = spawnSync("ruby", [path.join(__dirname, "./ripper.rb")], { input: text }); | ||
const child = spawnSync("ruby", [path.join(__dirname, "./ripper.rb")], { | ||
input: text | ||
}); | ||
@@ -8,0 +10,0 @@ const error = child.stderr.toString(); |
@@ -20,3 +20,5 @@ const { printComments } = require("./utils"); | ||
throw new Error(`Unsupported node encountered: ${type}\n${JSON.stringify(body, null, 2)}`); | ||
throw new Error( | ||
`Unsupported node encountered: ${type}\n${JSON.stringify(body, null, 2)}` | ||
); | ||
}; |
139
src/ruby.js
@@ -14,66 +14,62 @@ const parse = require("./parse"); | ||
module.exports = { | ||
languages: [{ | ||
name: "Ruby", | ||
parsers: ["ruby"], | ||
extensions: [ | ||
".arb", | ||
".axlsx", | ||
".builder", | ||
".eye", | ||
".fcgi", | ||
".gemfile", | ||
".gemspec", | ||
".god", | ||
".jb", | ||
".jbuilder", | ||
".mspec", | ||
".opal", | ||
".pluginspec", | ||
".podspec", | ||
".rabl", | ||
".rake", | ||
".rb", | ||
".rbuild", | ||
".rbw", | ||
".rbx", | ||
".ru", | ||
".ruby", | ||
".thor", | ||
".watchr" | ||
], | ||
filenames: [ | ||
".irbrc", | ||
".pryrc", | ||
"Appraisals", | ||
"Berksfile", | ||
"Brewfile", | ||
"Buildfile", | ||
"Capfile", | ||
"Cheffile", | ||
"Dangerfile", | ||
"Deliverfile", | ||
"Fastfile", | ||
"Gemfile", | ||
"Guardfile", | ||
"Jarfile", | ||
"Mavenfile", | ||
"Podfile", | ||
"Puppetfile", | ||
"Rakefile", | ||
"Snapfile", | ||
"Thorfile", | ||
"Vagabondfile", | ||
"Vagrantfile", | ||
"buildfile" | ||
], | ||
interpreters: [ | ||
"jruby", | ||
"macruby", | ||
"rake", | ||
"rbx", | ||
"ruby" | ||
], | ||
linguistLanguageId: 326, | ||
vscodeLanguageIds: ["ruby"] | ||
}], | ||
languages: [ | ||
{ | ||
name: "Ruby", | ||
parsers: ["ruby"], | ||
extensions: [ | ||
".arb", | ||
".axlsx", | ||
".builder", | ||
".eye", | ||
".fcgi", | ||
".gemfile", | ||
".gemspec", | ||
".god", | ||
".jb", | ||
".jbuilder", | ||
".mspec", | ||
".opal", | ||
".pluginspec", | ||
".podspec", | ||
".rabl", | ||
".rake", | ||
".rb", | ||
".rbuild", | ||
".rbw", | ||
".rbx", | ||
".ru", | ||
".ruby", | ||
".thor", | ||
".watchr" | ||
], | ||
filenames: [ | ||
".irbrc", | ||
".pryrc", | ||
"Appraisals", | ||
"Berksfile", | ||
"Brewfile", | ||
"Buildfile", | ||
"Capfile", | ||
"Cheffile", | ||
"Dangerfile", | ||
"Deliverfile", | ||
"Fastfile", | ||
"Gemfile", | ||
"Guardfile", | ||
"Jarfile", | ||
"Mavenfile", | ||
"Podfile", | ||
"Puppetfile", | ||
"Rakefile", | ||
"Snapfile", | ||
"Thorfile", | ||
"Vagabondfile", | ||
"Vagrantfile", | ||
"buildfile" | ||
], | ||
interpreters: ["jruby", "macruby", "rake", "rbx", "ruby"], | ||
linguistLanguageId: 326, | ||
vscodeLanguageIds: ["ruby"] | ||
} | ||
], | ||
parsers: { | ||
@@ -96,3 +92,4 @@ ruby: { | ||
default: false, | ||
description: "Adds a trailing comma to array literals, hash literals, and method calls." | ||
description: | ||
"Adds a trailing comma to array literals, hash literals, and method calls." | ||
}, | ||
@@ -103,3 +100,4 @@ inlineConditionals: { | ||
default: true, | ||
description: "When it fits on one line, allows if and unless statements to use the modifier form." | ||
description: | ||
"When it fits on one line, allows if and unless statements to use the modifier form." | ||
}, | ||
@@ -110,3 +108,4 @@ inlineLoops: { | ||
default: true, | ||
description: "When it fits on one line, allows while and until statements to use the modifier form." | ||
description: | ||
"When it fits on one line, allows while and until statements to use the modifier form." | ||
}, | ||
@@ -117,3 +116,4 @@ preferHashLabels: { | ||
default: true, | ||
description: "When possible, uses the shortened hash key syntax, as opposed to hash rockets." | ||
description: | ||
"When possible, uses the shortened hash key syntax, as opposed to hash rockets." | ||
}, | ||
@@ -124,3 +124,4 @@ preferSingleQuotes: { | ||
default: true, | ||
description: "When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals." | ||
description: | ||
"When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals." | ||
} | ||
@@ -127,0 +128,0 @@ }, |
@@ -30,3 +30,7 @@ const isCall = node => ["::", "."].includes(node) || node.type === "@period"; | ||
const otherParams = params.body.slice(1); | ||
if (!Array.isArray(reqParams) || reqParams.length !== 1 || otherParams.some(Boolean)) { | ||
if ( | ||
!Array.isArray(reqParams) || | ||
reqParams.length !== 1 || | ||
otherParams.some(Boolean) | ||
) { | ||
return null; | ||
@@ -67,7 +71,7 @@ } | ||
if ( | ||
varRef.type !== "var_ref" | ||
|| varRef.body[0].body !== reqParams[0].body | ||
|| !isCall(call) | ||
|| method.type !== "@ident" | ||
|| args | ||
varRef.type !== "var_ref" || | ||
varRef.body[0].body !== reqParams[0].body || | ||
!isCall(call) || | ||
method.type !== "@ident" || | ||
args | ||
) { | ||
@@ -74,0 +78,0 @@ return null; |
@@ -1,2 +0,8 @@ | ||
const { breakParent, concat, hardline, lineSuffix, literalline } = require("prettier").doc.builders; | ||
const { | ||
breakParent, | ||
concat, | ||
hardline, | ||
lineSuffix, | ||
literalline | ||
} = require("./builders"); | ||
@@ -62,3 +68,6 @@ const concatBody = (path, opts, print) => concat(path.map(print, "body")); | ||
heredoc = argNode; | ||
} else if (argNode.type === "string_literal" && argNode.body[0].type === "heredoc") { | ||
} else if ( | ||
argNode.type === "string_literal" && | ||
argNode.body[0].type === "heredoc" | ||
) { | ||
pattern = [index, "body", 0, "body"]; | ||
@@ -71,3 +80,5 @@ [heredoc] = argNode.body; | ||
const content = path.map.apply(path, argPattern.slice().concat(pattern)); | ||
heredocs.push(concat([literalline].concat(content).concat([heredoc.ending]))); | ||
heredocs.push( | ||
concat([literalline].concat(content).concat([heredoc.ending])) | ||
); | ||
args[index] = heredoc.beging; | ||
@@ -91,6 +102,4 @@ }); | ||
const prefix = value => (path, opts, print) => concat([ | ||
value, | ||
path.call(print, "body", 0) | ||
]); | ||
const prefix = value => (path, opts, print) => | ||
concat([value, path.call(print, "body", 0)]); | ||
@@ -120,13 +129,11 @@ const printComments = (printed, start, comments) => { | ||
const skipAssignIndent = node => ( | ||
["array", "hash", "heredoc", "lambda", "regexp_literal"].includes(node.type) | ||
|| (node.type === "call" && skipAssignIndent(node.body[0])) | ||
|| (node.type === "string_literal" && node.body[0].type === "heredoc") | ||
); | ||
const skipAssignIndent = node => | ||
["array", "hash", "heredoc", "lambda", "regexp_literal"].includes( | ||
node.type | ||
) || | ||
(node.type === "call" && skipAssignIndent(node.body[0])) || | ||
(node.type === "string_literal" && node.body[0].type === "heredoc"); | ||
const surround = (left, right) => (path, opts, print) => concat([ | ||
left, | ||
path.call(print, "body", 0), | ||
right | ||
]); | ||
const surround = (left, right) => (path, opts, print) => | ||
concat([left, path.call(print, "body", 0), right]); | ||
@@ -133,0 +140,0 @@ module.exports = { |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
175934
45
1963
152
2