prettier 1.0.0.pre.rc1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2bdbafe8bc7bd8ebc0f77727584bfa80773721ca5e77f820df84b8e7c7e0951
4
- data.tar.gz: 53e157e6880b56e642690fb90f6244ad669739a2e5fb697cde0c8082facc2c20
3
+ metadata.gz: c97988d5dd7fe35aa5fd73777f31f8217809ea0eee189cab7ac70c266569857b
4
+ data.tar.gz: 478c15e6cbd8d8efb16fc37e028afb8c88f3671aa77f36d3df0cd115b239c83a
5
5
  SHA512:
6
- metadata.gz: 854c61aa25de0a708606f89cb4bd3dde7dee10ecec89cfc7660bf03722ea12603bbb4dbf5f8d8b25f14359de55b419f2758522198cae9926d03fe77fab7aa001
7
- data.tar.gz: d9c821b5367084de39bbe51c60a58642210caa5da04757c6fafbabec6e204adfdd9d7b656e34c3a94e50af26d5c6ceda9236edf68e96c98ed1e941957fe47c4a
6
+ metadata.gz: 38ae06510c4872ba7f4ede36dc6b5f4aae3c7183c9c48b4e515733074e9ce27d2ddb4b189c25600d1daf123b8f5eccbb8b12c953e5192a62e08a63cb9716298e
7
+ data.tar.gz: 9456c53fe9ad823defb3d69fd4dd4504ee1e9d4af5d522fd8352141d61a5d975aa6043b62d78dd077f000258e400ee98fce8131ada5dac066021bb27e9f40de5
@@ -6,6 +6,55 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.0] - 2020-12-26
10
+
11
+ ### Added
12
+
13
+ - [@kddeisz] - Support for the `fndptn` node for Ruby 3.0 pattern matching.
14
+ - [@kddeisz] - Support for Ruby 3.0+ single-line method definitions.
15
+
16
+ ## [1.1.0] - 2020-12-20
17
+
18
+ ### Added
19
+
20
+ - [@kddeisz] - Now that the comments are all fixed up, we can support `# prettier-ignore` comments.
21
+
22
+ ### Changed
23
+
24
+ - [@rindek], [@kddeisz] - Do not remove parentheses when receiver looks like a constant.
25
+ - [@rindek], [@kddeisz] - Do not remove parentheses when using the special `call` syntax with no arguments.
26
+ - [@ykpythemind] - Do not change regexp bounds if the body has certain content.
27
+ - [@karanmandal], [@kddeisz] - Correctly print for loops.
28
+ - [@rafbm], [@kddeisz] - If there are method chains with arguments only at the end, we should group the method chain and the method args.
29
+
30
+ ## [1.0.1] - 2020-12-12
31
+
32
+ ### Changed
33
+
34
+ - [@steobrien], [@kddeisz] - Ensure leading comments in empty array and hash literals do not duplicate.
35
+
36
+ ## [1.0.0] - 2020-12-11
37
+
38
+ ### Changed
39
+
40
+ - [@kddeisz] - Do not unescape double quotes in a single quote string.
41
+ - [@kddeisz] - Only force braces on regexp for spaces and equals if it's inside a command or command_call.
42
+ - [@kddeisz] - Leave Sorbet type annotations in place.
43
+ - [@kddeisz] - Don't group hash contents, just allow them to break with their parent node.
44
+ - [@kddeisz] - Honor the UTF-8 lang passed in through ENV vars.
45
+
46
+ ## [1.0.0-rc2] - 2020-12-10
47
+
48
+ ### Changed
49
+
50
+ - [@kddeisz] - Print hashes with consistent keys (e.g., if one key cannot be a hash label, use all hash rockets).
51
+ - [@kddeisz] - Respect using `o` or not using `o` for octal numbers.
52
+ - [@kddeisz] - Ensure `when` clauses with multiple predicates that can be split into multiple lines are split correctly.
53
+ - [@kddeisz] - Ensure hash literal is split correctly when only its contents would fit on one line.
54
+ - [@kddeisz] - Simplify `toProc` checks by not calling if the option is disabled.
55
+ - [@johncsnyder], [@kddeisz] - Add `method_add_block` to the potential like of method calls that can be chained.
56
+ - [@kddeisz] - Add the `rubyArrayLiteral` option for disabling automatically turning into array literals.
57
+
9
58
  ## [1.0.0-rc1] - 2020-12-09
10
59
 
11
60
  ### Changed
@@ -240,7 +289,8 @@ will now be printed as:
240
289
  ```ruby
241
290
  Config::Download.new(
242
291
  'prettier',
243
- filename: 'prettier.yml', url: 'https://raw.githubusercontent.com/...'
292
+ filename: 'prettier.yml',
293
+ url: 'https://raw.githubusercontent.com/...'
244
294
  ).perform
245
295
  ```
246
296
 
@@ -928,7 +978,11 @@ would previously result in `array[]`, but now prints properly.
928
978
 
929
979
  - Initial release 🎉
930
980
 
931
- [unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc1...HEAD
981
+ [unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.1.0...HEAD
982
+ [1.1.0]: https://github.com/prettier/plugin-ruby/compare/v1.0.1...v1.1.0
983
+ [1.0.1]: https://github.com/prettier/plugin-ruby/compare/v1.0.0...v1.0.1
984
+ [1.0.0]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc2...v1.0.0
985
+ [1.0.0-rc2]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc1...v1.0.0-rc2
932
986
  [1.0.0-rc1]: https://github.com/prettier/plugin-ruby/compare/v0.22.0...v1.0.0-rc1
933
987
  [0.22.0]: https://github.com/prettier/plugin-ruby/compare/v0.21.0...v0.22.0
934
988
  [0.21.0]: https://github.com/prettier/plugin-ruby/compare/v0.20.1...v0.21.0
@@ -1013,6 +1067,7 @@ would previously result in `array[]`, but now prints properly.
1013
1067
  [@jpickwell]: https://github.com/jpickwell
1014
1068
  [@jrdioko]: https://github.com/jrdioko
1015
1069
  [@jviney]: https://github.com/jviney
1070
+ [@karanmandal]: https://github.com/karanmandal
1016
1071
  [@kddeisz]: https://github.com/kddeisz
1017
1072
  [@kmcq]: https://github.com/kmcq
1018
1073
  [@krachtstefan]: https://github.com/krachtstefan
@@ -1027,6 +1082,8 @@ would previously result in `array[]`, but now prints properly.
1027
1082
  [@overload119]: https://github.com/Overload119
1028
1083
  [@petevk]: https://github.com/petevk
1029
1084
  [@pje]: https://github.com/pje
1085
+ [@rafbm]: https://github.com/rafbm
1086
+ [@rindek]: https://github.com/rindek
1030
1087
  [@rosskinsella]: https://github.com/RossKinsella
1031
1088
  [@rsullivan00]: https://github.com/Rsullivan00
1032
1089
  [@ryan-hunter-pc]: https://github.com/ryan-hunter-pc
@@ -1036,4 +1093,5 @@ would previously result in `array[]`, but now prints properly.
1036
1093
  [@tobyndockerill]: https://github.com/tobyndockerill
1037
1094
  [@uri]: https://github.com/uri
1038
1095
  [@xipgroc]: https://github.com/xipgroc
1096
+ [@ykpythemind]: https://github.com/ykpythemind
1039
1097
  [@yuki24]: https://github.com/yuki24
data/README.md CHANGED
@@ -122,16 +122,17 @@ The `prettier` executable is now installed and ready for use:
122
122
 
123
123
  Below are the options (from [`src/ruby.js`](src/ruby.js)) that `@prettier/plugin-ruby` currently supports:
124
124
 
125
- | API Option | CLI Option | Default | Description |
126
- | ----------------- | --------------------- | :-----: | ------------------------------------------------------------------------------------------------------------------------------------ |
127
- | `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). |
128
- | `requirePragma` | `--require-pragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)). |
129
- | `rubyHashLabel` | `--ruby-hash-label` | `true` | When possible, uses the shortened hash key syntax, as opposed to hash rockets. |
130
- | `rubyModifier` | `--ruby-modifier` | `true` | When it fits on one line, allows while and until statements to use the modifier form. |
131
- | `rubySingleQuote` | `--ruby-single-quote` | `true` | When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals. |
132
- | `rubyToProc` | `--ruby-to-proc` | `false` | When possible, convert blocks to the more concise `Symbol#to_proc` syntax. |
133
- | `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |
134
- | `trailingComma` | `--trailing-comma` | `"es5"` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#trailing-comma)). `"es5"` is equivalent to `true`. |
125
+ | API Option | CLI Option | Default | Description |
126
+ | ------------------ | ---------------------- | :-----: | ------------------------------------------------------------------------------------------------------------------------------------ |
127
+ | `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). |
128
+ | `requirePragma` | `--require-pragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)). |
129
+ | `rubyArrayLiteral` | `--ruby-array-literal` | `true` | When possible, favor the use of string and symbol array literals. |
130
+ | `rubyHashLabel` | `--ruby-hash-label` | `true` | When possible, uses the shortened hash key syntax, as opposed to hash rockets. |
131
+ | `rubyModifier` | `--ruby-modifier` | `true` | When it fits on one line, allows while and until statements to use the modifier form. |
132
+ | `rubySingleQuote` | `--ruby-single-quote` | `true` | When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals. |
133
+ | `rubyToProc` | `--ruby-to-proc` | `false` | When possible, convert blocks to the more concise `Symbol#to_proc` syntax. |
134
+ | `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |
135
+ | `trailingComma` | `--trailing-comma` | `"es5"` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#trailing-comma)). `"es5"` is equivalent to `true`. |
135
136
 
136
137
  Any of these can be added to your existing [prettier configuration
137
138
  file](https://prettier.io/docs/en/configuration.html). For example:
@@ -226,6 +227,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
226
227
  <tr>
227
228
  <td align="center"><a href="https://github.com/mmcnl"><img src="https://avatars2.githubusercontent.com/u/1498727?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Matt McNeil</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Ammcnl" title="Bug reports">🐛</a></td>
228
229
  <td align="center"><a href="https://github.com/johncsnyder"><img src="https://avatars2.githubusercontent.com/u/9882099?v=4?s=100" width="100px;" alt=""/><br /><sub><b>John Snyder</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Ajohncsnyder" title="Bug reports">🐛</a></td>
230
+ <td align="center"><a href="https://github.com/rindek"><img src="https://avatars1.githubusercontent.com/u/881209?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jacek Jakubik</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Arindek" title="Bug reports">🐛</a></td>
231
+ <td align="center"><a href="https://twitter.com/ykpythemind"><img src="https://avatars2.githubusercontent.com/u/22209702?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Yukito Ito</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Aykpythemind" title="Bug reports">🐛</a> <a href="https://github.com/prettier/plugin-ruby/commits?author=ykpythemind" title="Code">💻</a></td>
232
+ <td align="center"><a href="https://studyfied.com/"><img src="https://avatars2.githubusercontent.com/u/45869605?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Karan Mandal</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Akaranmandal" title="Bug reports">🐛</a></td>
229
233
  </tr>
230
234
  </table>
231
235
 
@@ -5249,19 +5249,19 @@ var errors = {
5249
5249
  UndefinedParserError
5250
5250
  };
5251
5251
 
5252
- /*! *****************************************************************************
5253
- Copyright (c) Microsoft Corporation.
5254
-
5255
- Permission to use, copy, modify, and/or distribute this software for any
5256
- purpose with or without fee is hereby granted.
5257
-
5258
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
5259
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
5260
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
5261
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
5262
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
5263
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
5264
- PERFORMANCE OF THIS SOFTWARE.
5252
+ /*! *****************************************************************************
5253
+ Copyright (c) Microsoft Corporation.
5254
+
5255
+ Permission to use, copy, modify, and/or distribute this software for any
5256
+ purpose with or without fee is hereby granted.
5257
+
5258
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
5259
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
5260
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
5261
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
5262
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
5263
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
5264
+ PERFORMANCE OF THIS SOFTWARE.
5265
5265
  ***************************************************************************** */
5266
5266
 
5267
5267
  /* global Reflect, Promise */
@@ -14638,7 +14638,6 @@ function printAstToDoc(ast, options, alignmentSize = 0) {
14638
14638
  } // We let JSXElement print its comments itself because it adds () around
14639
14639
  // UnionTypeAnnotation has to align the child without the comments
14640
14640
 
14641
-
14642
14641
  let res;
14643
14642
 
14644
14643
  if (printer.willPrintOwnComments && printer.willPrintOwnComments(path, options)) {
@@ -14675,6 +14674,7 @@ function printPrettierIgnoredNode(node, options) {
14675
14674
  locStart,
14676
14675
  locEnd
14677
14676
  } = options;
14677
+
14678
14678
  const start = locStart(node);
14679
14679
  const end = locEnd(node);
14680
14680
 
@@ -24808,11 +24808,11 @@ var ini = createCommonjsModule(function (module, exports) {
24808
24808
  });
24809
24809
 
24810
24810
  var fs = __importStar(fs__default['default']);
24811
- /**
24812
- * define the possible values:
24813
- * section: [section]
24814
- * param: key=value
24815
- * comment: ;this is a comment
24811
+ /**
24812
+ * define the possible values:
24813
+ * section: [section]
24814
+ * param: key=value
24815
+ * comment: ;this is a comment
24816
24816
  */
24817
24817
 
24818
24818
 
@@ -24821,9 +24821,9 @@ var ini = createCommonjsModule(function (module, exports) {
24821
24821
  param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
24822
24822
  comment: /^\s*[#;].*$/
24823
24823
  };
24824
- /**
24825
- * Parses an .ini file
24826
- * @param file The location of the .ini file
24824
+ /**
24825
+ * Parses an .ini file
24826
+ * @param file The location of the .ini file
24827
24827
  */
24828
24828
 
24829
24829
  function parse(file) {
@@ -29644,8 +29644,8 @@ var path_1 = createCommonjsModule(function (module, exports) {
29644
29644
  const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
29645
29645
 
29646
29646
  const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;
29647
- /**
29648
- * Designed to work only with simple paths: `dir\\file`.
29647
+ /**
29648
+ * Designed to work only with simple paths: `dir\\file`.
29649
29649
  */
29650
29650
 
29651
29651
  function unixify(filepath) {
@@ -34268,17 +34268,17 @@ var pattern = createCommonjsModule(function (module, exports) {
34268
34268
  exports.isStaticPattern = isStaticPattern;
34269
34269
 
34270
34270
  function isDynamicPattern(pattern, options = {}) {
34271
- /**
34272
- * A special case with an empty string is necessary for matching patterns that start with a forward slash.
34273
- * An empty string cannot be a dynamic pattern.
34274
- * For example, the pattern `/lib/*` will be spread into parts: '', 'lib', '*'.
34271
+ /**
34272
+ * A special case with an empty string is necessary for matching patterns that start with a forward slash.
34273
+ * An empty string cannot be a dynamic pattern.
34274
+ * For example, the pattern `/lib/*` will be spread into parts: '', 'lib', '*'.
34275
34275
  */
34276
34276
  if (pattern === '') {
34277
34277
  return false;
34278
34278
  }
34279
- /**
34280
- * When the `caseSensitiveMatch` option is disabled, all patterns must be marked as dynamic, because we cannot check
34281
- * filepath directly (without read directory).
34279
+ /**
34280
+ * When the `caseSensitiveMatch` option is disabled, all patterns must be marked as dynamic, because we cannot check
34281
+ * filepath directly (without read directory).
34282
34282
  */
34283
34283
 
34284
34284
 
@@ -34389,17 +34389,17 @@ var pattern = createCommonjsModule(function (module, exports) {
34389
34389
  } = picomatch$1.scan(pattern, Object.assign(Object.assign({}, options), {
34390
34390
  parts: true
34391
34391
  }));
34392
- /**
34393
- * The scan method returns an empty array in some cases.
34394
- * See micromatch/picomatch#58 for more details.
34392
+ /**
34393
+ * The scan method returns an empty array in some cases.
34394
+ * See micromatch/picomatch#58 for more details.
34395
34395
  */
34396
34396
 
34397
34397
  if (parts.length === 0) {
34398
34398
  parts = [pattern];
34399
34399
  }
34400
- /**
34401
- * The scan method does not return an empty part for the pattern with a forward slash.
34402
- * This is another part of micromatch/picomatch#58.
34400
+ /**
34401
+ * The scan method does not return an empty part for the pattern with a forward slash.
34402
+ * This is another part of micromatch/picomatch#58.
34403
34403
  */
34404
34404
 
34405
34405
 
@@ -34804,8 +34804,8 @@ var constants$5 = createCommonjsModule(function (module, exports) {
34804
34804
  const SUPPORTED_MINOR_VERSION = 10;
34805
34805
  const IS_MATCHED_BY_MAJOR = MAJOR_VERSION > SUPPORTED_MAJOR_VERSION;
34806
34806
  const IS_MATCHED_BY_MAJOR_AND_MINOR = MAJOR_VERSION === SUPPORTED_MAJOR_VERSION && MINOR_VERSION >= SUPPORTED_MINOR_VERSION;
34807
- /**
34808
- * IS `true` for Node.js 10.10 and greater.
34807
+ /**
34808
+ * IS `true` for Node.js 10.10 and greater.
34809
34809
  */
34810
34810
 
34811
34811
  exports.IS_SUPPORT_READDIR_WITH_FILE_TYPES = IS_MATCHED_BY_MAJOR || IS_MATCHED_BY_MAJOR_AND_MINOR;
@@ -35894,9 +35894,9 @@ var matcher = createCommonjsModule(function (module, exports) {
35894
35894
  }
35895
35895
 
35896
35896
  _fillStorage() {
35897
- /**
35898
- * The original pattern may include `{,*,**,a/*}`, which will lead to problems with matching (unresolved level).
35899
- * So, before expand patterns with brace expansion into separated patterns.
35897
+ /**
35898
+ * The original pattern may include `{,*,**,a/*}`, which will lead to problems with matching (unresolved level).
35899
+ * So, before expand patterns with brace expansion into separated patterns.
35900
35900
  */
35901
35901
  const patterns = utils$3.pattern.expandPatternsWithBraceExpansion(this._patterns);
35902
35902
 
@@ -35958,12 +35958,12 @@ var partial = createCommonjsModule(function (module, exports) {
35958
35958
 
35959
35959
  for (const pattern of patterns) {
35960
35960
  const section = pattern.sections[0];
35961
- /**
35962
- * In this case, the pattern has a globstar and we must read all directories unconditionally,
35963
- * but only if the level has reached the end of the first group.
35964
- *
35965
- * fixtures/{a,b}/**
35966
- * ^ true/false ^ always true
35961
+ /**
35962
+ * In this case, the pattern has a globstar and we must read all directories unconditionally,
35963
+ * but only if the level has reached the end of the first group.
35964
+ *
35965
+ * fixtures/{a,b}/**
35966
+ * ^ true/false ^ always true
35967
35967
  */
35968
35968
 
35969
35969
  if (!pattern.complete && levels > section.length) {
@@ -36045,8 +36045,8 @@ var deep = createCommonjsModule(function (module, exports) {
36045
36045
  }
36046
36046
 
36047
36047
  _isSkippedByDeep(basePath, entryPath) {
36048
- /**
36049
- * Avoid unnecessary depth calculations when it doesn't matter.
36048
+ /**
36049
+ * Avoid unnecessary depth calculations when it doesn't matter.
36050
36050
  */
36051
36051
  if (this._settings.deep === Infinity) {
36052
36052
  return false;
@@ -36534,10 +36534,10 @@ async function FastGlob(source, options) {
36534
36534
  function stream(source, options) {
36535
36535
  assertPatternsInput(source);
36536
36536
  const works = getWorks(source, stream$5.default, options);
36537
- /**
36538
- * The stream returned by the provider cannot work with an asynchronous iterator.
36539
- * To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams.
36540
- * This affects performance (+25%). I don't see best solution right now.
36537
+ /**
36538
+ * The stream returned by the provider cannot work with an asynchronous iterator.
36539
+ * To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams.
36540
+ * This affects performance (+25%). I don't see best solution right now.
36541
36541
  */
36542
36542
 
36543
36543
  return utils$3.stream.merge(works);
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "1.0.0-rc1",
3
+ "version": "1.2.0",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "src/ruby.js",
6
6
  "scripts": {
7
+ "check-format": "prettier --check '**/*'",
7
8
  "lint": "eslint --cache .",
8
- "print": "prettier --plugin=.",
9
9
  "test": "jest"
10
10
  },
11
11
  "repository": {
@@ -25,9 +25,9 @@
25
25
  "all-contributors-cli": "^6.14.1",
26
26
  "eslint": "^7.8.1",
27
27
  "eslint-config-prettier": "^7.0.0",
28
- "husky": "^5.0.4",
28
+ "husky": "^4.3.5",
29
29
  "jest": "^26.0.0",
30
- "pretty-quick": "^3.0.0"
30
+ "pretty-quick": "^3.1.0"
31
31
  },
32
32
  "eslintConfig": {
33
33
  "extends": [
@@ -50,6 +50,8 @@
50
50
  }
51
51
  },
52
52
  "jest": {
53
+ "globalSetup": "./test/js/globalSetup.js",
54
+ "globalTeardown": "./test/js/globalTeardown.js",
53
55
  "setupFilesAfterEnv": [
54
56
  "./test/js/setupTests.js"
55
57
  ],
@@ -61,6 +63,9 @@
61
63
  }
62
64
  },
63
65
  "prettier": {
64
- "trailingComma": "none"
66
+ "trailingComma": "none",
67
+ "plugins": [
68
+ "."
69
+ ]
65
70
  }
66
71
  }
@@ -67,7 +67,11 @@ const embed = (path, print, textToDoc, _opts) => {
67
67
  path.call(print, "beging"),
68
68
  lineSuffix(
69
69
  group(
70
- concat([indent(markAsRoot(formatted)), literalLineNoBreak, ending])
70
+ concat([
71
+ indent(markAsRoot(formatted)),
72
+ literalLineNoBreak,
73
+ ending.trim()
74
+ ])
71
75
  )
72
76
  )
73
77
  ]);
@@ -78,7 +82,7 @@ const embed = (path, print, textToDoc, _opts) => {
78
82
  return markAsRoot(
79
83
  concat([
80
84
  path.call(print, "beging"),
81
- lineSuffix(group(concat([formatted, literalLineNoBreak, ending])))
85
+ lineSuffix(group(concat([formatted, literalLineNoBreak, ending.trim()])))
82
86
  ])
83
87
  );
84
88
  };
@@ -9,80 +9,56 @@ const {
9
9
  } = require("../prettier");
10
10
 
11
11
  const toProc = require("../toProc");
12
- const { docLength, getTrailingComma } = require("../utils");
13
-
14
- module.exports = {
15
- arg_paren: (path, opts, print) => {
16
- const argsNode = path.getValue().body[0];
17
-
18
- if (argsNode === null) {
19
- return "";
20
- }
21
-
22
- // Here we can skip the entire rest of the method by just checking if it's
23
- // an args_forward node, as we're guaranteed that there are no other arg
24
- // nodes.
25
- if (argsNode.type === "args_forward") {
26
- return group(
12
+ const { getTrailingComma } = require("../utils");
13
+
14
+ function printArgParen(path, opts, print) {
15
+ const argsNode = path.getValue().body[0];
16
+
17
+ if (argsNode === null) {
18
+ return "";
19
+ }
20
+
21
+ // Here we can skip the entire rest of the method by just checking if it's
22
+ // an args_forward node, as we're guaranteed that there are no other arg
23
+ // nodes.
24
+ if (argsNode.type === "args_forward") {
25
+ return group(
26
+ concat([
27
+ "(",
28
+ indent(concat([softline, path.call(print, "body", 0)])),
29
+ softline,
30
+ ")"
31
+ ])
32
+ );
33
+ }
34
+
35
+ const args = path.call(print, "body", 0);
36
+ const hasBlock = argsNode.type === "args_add_block" && argsNode.body[1];
37
+
38
+ // Now here we return a doc that represents the whole grouped expression,
39
+ // including the surrouding parentheses.
40
+ return group(
41
+ concat([
42
+ "(",
43
+ indent(
27
44
  concat([
28
- "(",
29
- indent(concat([softline, path.call(print, "body", 0)])),
30
45
  softline,
31
- ")"
46
+ join(concat([",", line]), args),
47
+ getTrailingComma(opts) && !hasBlock ? ifBreak(",", "") : ""
32
48
  ])
33
- );
34
- }
35
-
36
- const args = path.call(print, "body", 0);
37
- const hasBlock = argsNode.type === "args_add_block" && argsNode.body[1];
38
-
39
- // These are the docs representing the actual arguments, without any
40
- // parentheses or surrounding lines yet added.
41
- let argsDocs = [
42
- join(concat([",", line]), args),
43
- getTrailingComma(opts) && !hasBlock ? ifBreak(",", "") : ""
44
- ];
45
-
46
- // Here we're going to make a determination on whether or not we should put
47
- // a newline before the first argument. In some cases this makes the
48
- // appearance a little better. For example, instead of taking this input:
49
- //
50
- // foo(arg1, arg2).bar(arg1, arg2).baz(arg1)
51
- //
52
- // and transforming it into this:
53
- //
54
- // foo(arg1, arg2).bar(arg1, arg2).baz(
55
- // arg1
56
- // )
57
- //
58
- // it instead gets transformed into this:
59
- //
60
- // foo(arg1, arg2).bar(arg1, arg2)
61
- // .baz(arg1)
62
- //
63
- const maxDocLength = 15;
64
- const firstArgDoc = args[0];
65
-
66
- // prettier-ignore
67
- const shouldWrapLine =
68
- (args.reduce((sum, arg) => sum + docLength(arg), 0) > maxDocLength) ||
69
- (args.length == 1 && firstArgDoc.type === "group" && docLength(firstArgDoc) > maxDocLength) ||
70
- (firstArgDoc.type === "concat" && firstArgDoc.parts.some((part) => part.type === "group"));
71
-
72
- // Here we're going to get all of the docs representing the doc that's
73
- // inside the parentheses.
74
- if (shouldWrapLine) {
75
- argsDocs = [indent(concat([softline].concat(argsDocs))), softline];
76
- } else {
77
- argsDocs = [indent(concat(argsDocs))];
78
- }
79
-
80
- // Now here we return a doc that represents the whole grouped expression,
81
- // including the surrouding parentheses.
82
- return group(concat(["("].concat(argsDocs).concat(")")));
83
- },
84
- args: (path, opts, print) => {
85
- const args = path.map(print, "body");
49
+ ),
50
+ softline,
51
+ ")"
52
+ ])
53
+ );
54
+ }
55
+
56
+ function printArgs(path, { rubyToProc }, print) {
57
+ const args = path.map(print, "body");
58
+
59
+ // Don't bother trying to do any kind of fancy toProc transform if the
60
+ // option is disabled.
61
+ if (rubyToProc) {
86
62
  let blockNode = null;
87
63
 
88
64
  // Look up the chain to see if these arguments are contained within a
@@ -99,21 +75,26 @@ module.exports = {
99
75
  return blockNode;
100
76
  });
101
77
 
102
- const proc = blockNode && toProc(path, opts, blockNode);
78
+ const proc = blockNode && toProc(path, blockNode);
103
79
 
104
- // If we have a successful to_proc transformation, but we're part of an aref
105
- // node, that means it's something to the effect of
80
+ // If we have a successful to_proc transformation, but we're part of an
81
+ // aref node, that means it's something to the effect of
106
82
  //
107
83
  // foo[:bar].each(&:to_s)
108
84
  //
109
- // In this case we need to just return regular arguments, otherwise we would
110
- // end up putting &:to_s inside the brackets accidentally.
85
+ // In this case we need to just return regular arguments, otherwise we
86
+ // would end up putting &:to_s inside the brackets accidentally.
111
87
  if (proc && path.getParentNode(1).type !== "aref") {
112
88
  args.push(proc);
113
89
  }
90
+ }
114
91
 
115
- return args;
116
- },
92
+ return args;
93
+ }
94
+
95
+ module.exports = {
96
+ arg_paren: printArgParen,
97
+ args: printArgs,
117
98
  args_add_block: (path, opts, print) => {
118
99
  const parts = path.call(print, "body", 0);
119
100