@effect-app/eslint-shared-config 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/node_modules/@dprint/formatter/LICENSE +21 -0
  3. package/node_modules/@dprint/formatter/README.md +70 -0
  4. package/node_modules/@dprint/formatter/esm/_dnt.shims.d.ts +2 -0
  5. package/node_modules/@dprint/formatter/esm/_dnt.shims.d.ts.map +1 -0
  6. package/node_modules/@dprint/formatter/esm/_dnt.shims.js +57 -0
  7. package/node_modules/@dprint/formatter/esm/_dnt.test_shims.d.ts.map +1 -0
  8. package/node_modules/@dprint/formatter/esm/common.d.ts +80 -0
  9. package/node_modules/@dprint/formatter/esm/common.d.ts.map +1 -0
  10. package/node_modules/@dprint/formatter/esm/common.js +1 -0
  11. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert.d.ts.map +1 -0
  12. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_almost_equals.d.ts.map +1 -0
  13. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_array_includes.d.ts.map +1 -0
  14. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_equals.d.ts.map +1 -0
  15. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_exists.d.ts.map +1 -0
  16. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_false.d.ts.map +1 -0
  17. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_greater.d.ts.map +1 -0
  18. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_greater_or_equal.d.ts.map +1 -0
  19. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_instance_of.d.ts.map +1 -0
  20. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_is_error.d.ts.map +1 -0
  21. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_less.d.ts.map +1 -0
  22. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_less_or_equal.d.ts.map +1 -0
  23. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_match.d.ts.map +1 -0
  24. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_not_equals.d.ts.map +1 -0
  25. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_not_instance_of.d.ts.map +1 -0
  26. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_not_match.d.ts.map +1 -0
  27. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_not_strict_equals.d.ts.map +1 -0
  28. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_object_match.d.ts.map +1 -0
  29. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_rejects.d.ts.map +1 -0
  30. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_strict_equals.d.ts.map +1 -0
  31. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_string_includes.d.ts.map +1 -0
  32. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assert_throws.d.ts.map +1 -0
  33. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/assertion_error.d.ts.map +1 -0
  34. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/equal.d.ts.map +1 -0
  35. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/fail.d.ts.map +1 -0
  36. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/mod.d.ts.map +1 -0
  37. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/unimplemented.d.ts.map +1 -0
  38. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/assert/0.226.0/unreachable.d.ts.map +1 -0
  39. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/internal/1.0.0/build_message.d.ts.map +1 -0
  40. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/internal/1.0.0/diff.d.ts.map +1 -0
  41. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/internal/1.0.0/diff_str.d.ts.map +1 -0
  42. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/internal/1.0.0/format.d.ts.map +1 -0
  43. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/internal/1.0.0/mod.d.ts.map +1 -0
  44. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/internal/1.0.0/styles.d.ts.map +1 -0
  45. package/node_modules/@dprint/formatter/esm/deps/jsr.io/@std/internal/1.0.0/types.d.ts.map +1 -0
  46. package/node_modules/@dprint/formatter/esm/mod.d.ts +23 -0
  47. package/node_modules/@dprint/formatter/esm/mod.d.ts.map +1 -0
  48. package/node_modules/@dprint/formatter/esm/mod.js +84 -0
  49. package/node_modules/@dprint/formatter/esm/mod_test.d.ts.map +1 -0
  50. package/node_modules/@dprint/formatter/esm/package.json +3 -0
  51. package/node_modules/@dprint/formatter/esm/v3.d.ts +7 -0
  52. package/node_modules/@dprint/formatter/esm/v3.d.ts.map +1 -0
  53. package/node_modules/@dprint/formatter/esm/v3.js +216 -0
  54. package/node_modules/@dprint/formatter/esm/v4.d.ts +7 -0
  55. package/node_modules/@dprint/formatter/esm/v4.d.ts.map +1 -0
  56. package/node_modules/@dprint/formatter/esm/v4.js +198 -0
  57. package/node_modules/@dprint/formatter/package.json +38 -0
  58. package/node_modules/@dprint/formatter/script/_dnt.shims.d.ts +2 -0
  59. package/node_modules/@dprint/formatter/script/_dnt.shims.d.ts.map +1 -0
  60. package/node_modules/@dprint/formatter/script/_dnt.shims.js +60 -0
  61. package/node_modules/@dprint/formatter/script/_dnt.test_shims.d.ts.map +1 -0
  62. package/node_modules/@dprint/formatter/script/common.d.ts +80 -0
  63. package/node_modules/@dprint/formatter/script/common.d.ts.map +1 -0
  64. package/node_modules/@dprint/formatter/script/common.js +2 -0
  65. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert.d.ts.map +1 -0
  66. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_almost_equals.d.ts.map +1 -0
  67. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_array_includes.d.ts.map +1 -0
  68. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_equals.d.ts.map +1 -0
  69. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_exists.d.ts.map +1 -0
  70. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_false.d.ts.map +1 -0
  71. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_greater.d.ts.map +1 -0
  72. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_greater_or_equal.d.ts.map +1 -0
  73. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_instance_of.d.ts.map +1 -0
  74. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_is_error.d.ts.map +1 -0
  75. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_less.d.ts.map +1 -0
  76. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_less_or_equal.d.ts.map +1 -0
  77. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_match.d.ts.map +1 -0
  78. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_not_equals.d.ts.map +1 -0
  79. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_not_instance_of.d.ts.map +1 -0
  80. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_not_match.d.ts.map +1 -0
  81. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_not_strict_equals.d.ts.map +1 -0
  82. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_object_match.d.ts.map +1 -0
  83. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_rejects.d.ts.map +1 -0
  84. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_strict_equals.d.ts.map +1 -0
  85. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_string_includes.d.ts.map +1 -0
  86. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assert_throws.d.ts.map +1 -0
  87. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/assertion_error.d.ts.map +1 -0
  88. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/equal.d.ts.map +1 -0
  89. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/fail.d.ts.map +1 -0
  90. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/mod.d.ts.map +1 -0
  91. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/unimplemented.d.ts.map +1 -0
  92. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/assert/0.226.0/unreachable.d.ts.map +1 -0
  93. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/internal/1.0.0/build_message.d.ts.map +1 -0
  94. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/internal/1.0.0/diff.d.ts.map +1 -0
  95. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/internal/1.0.0/diff_str.d.ts.map +1 -0
  96. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/internal/1.0.0/format.d.ts.map +1 -0
  97. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/internal/1.0.0/mod.d.ts.map +1 -0
  98. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/internal/1.0.0/styles.d.ts.map +1 -0
  99. package/node_modules/@dprint/formatter/script/deps/jsr.io/@std/internal/1.0.0/types.d.ts.map +1 -0
  100. package/node_modules/@dprint/formatter/script/mod.d.ts +23 -0
  101. package/node_modules/@dprint/formatter/script/mod.d.ts.map +1 -0
  102. package/node_modules/@dprint/formatter/script/mod.js +113 -0
  103. package/node_modules/@dprint/formatter/script/mod_test.d.ts.map +1 -0
  104. package/node_modules/@dprint/formatter/script/package.json +3 -0
  105. package/node_modules/@dprint/formatter/script/v3.d.ts +7 -0
  106. package/node_modules/@dprint/formatter/script/v3.d.ts.map +1 -0
  107. package/node_modules/@dprint/formatter/script/v3.js +221 -0
  108. package/node_modules/@dprint/formatter/script/v4.d.ts +7 -0
  109. package/node_modules/@dprint/formatter/script/v4.d.ts.map +1 -0
  110. package/node_modules/@dprint/formatter/script/v4.js +226 -0
  111. package/node_modules/jsonc-parser/CHANGELOG.md +76 -0
  112. package/node_modules/jsonc-parser/LICENSE.md +21 -0
  113. package/node_modules/jsonc-parser/README.md +364 -0
  114. package/node_modules/jsonc-parser/SECURITY.md +41 -0
  115. package/node_modules/jsonc-parser/lib/esm/impl/edit.js +185 -0
  116. package/node_modules/jsonc-parser/lib/esm/impl/format.js +261 -0
  117. package/node_modules/jsonc-parser/lib/esm/impl/parser.js +659 -0
  118. package/node_modules/jsonc-parser/lib/esm/impl/scanner.js +443 -0
  119. package/node_modules/jsonc-parser/lib/esm/impl/string-intern.js +29 -0
  120. package/node_modules/jsonc-parser/lib/esm/main.d.ts +351 -0
  121. package/node_modules/jsonc-parser/lib/esm/main.js +178 -0
  122. package/node_modules/jsonc-parser/lib/umd/impl/edit.js +201 -0
  123. package/node_modules/jsonc-parser/lib/umd/impl/format.js +275 -0
  124. package/node_modules/jsonc-parser/lib/umd/impl/parser.js +682 -0
  125. package/node_modules/jsonc-parser/lib/umd/impl/scanner.js +456 -0
  126. package/node_modules/jsonc-parser/lib/umd/impl/string-intern.js +42 -0
  127. package/node_modules/jsonc-parser/lib/umd/main.d.ts +351 -0
  128. package/node_modules/jsonc-parser/lib/umd/main.js +194 -0
  129. package/node_modules/jsonc-parser/package.json +37 -0
  130. package/package.json +3 -1
@@ -0,0 +1,41 @@
1
+ <!-- BEGIN MICROSOFT SECURITY.MD V0.0.5 BLOCK -->
2
+
3
+ ## Security
4
+
5
+ Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
6
+
7
+ If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below.
8
+
9
+ ## Reporting Security Issues
10
+
11
+ **Please do not report security vulnerabilities through public GitHub issues.**
12
+
13
+ Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
14
+
15
+ If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
16
+
17
+ You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
18
+
19
+ Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20
+
21
+ * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22
+ * Full paths of source file(s) related to the manifestation of the issue
23
+ * The location of the affected source code (tag/branch/commit or direct URL)
24
+ * Any special configuration required to reproduce the issue
25
+ * Step-by-step instructions to reproduce the issue
26
+ * Proof-of-concept or exploit code (if possible)
27
+ * Impact of the issue, including how an attacker might exploit the issue
28
+
29
+ This information will help us triage your report more quickly.
30
+
31
+ If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs.
32
+
33
+ ## Preferred Languages
34
+
35
+ We prefer all communications to be in English.
36
+
37
+ ## Policy
38
+
39
+ Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
40
+
41
+ <!-- END MICROSOFT SECURITY.MD BLOCK -->
@@ -0,0 +1,185 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ 'use strict';
6
+ import { format, isEOL } from './format';
7
+ import { parseTree, findNodeAtLocation } from './parser';
8
+ export function removeProperty(text, path, options) {
9
+ return setProperty(text, path, void 0, options);
10
+ }
11
+ export function setProperty(text, originalPath, value, options) {
12
+ const path = originalPath.slice();
13
+ const errors = [];
14
+ const root = parseTree(text, errors);
15
+ let parent = void 0;
16
+ let lastSegment = void 0;
17
+ while (path.length > 0) {
18
+ lastSegment = path.pop();
19
+ parent = findNodeAtLocation(root, path);
20
+ if (parent === void 0 && value !== void 0) {
21
+ if (typeof lastSegment === 'string') {
22
+ value = { [lastSegment]: value };
23
+ }
24
+ else {
25
+ value = [value];
26
+ }
27
+ }
28
+ else {
29
+ break;
30
+ }
31
+ }
32
+ if (!parent) {
33
+ // empty document
34
+ if (value === void 0) { // delete
35
+ throw new Error('Can not delete in empty document');
36
+ }
37
+ return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
38
+ }
39
+ else if (parent.type === 'object' && typeof lastSegment === 'string' && Array.isArray(parent.children)) {
40
+ const existing = findNodeAtLocation(parent, [lastSegment]);
41
+ if (existing !== void 0) {
42
+ if (value === void 0) { // delete
43
+ if (!existing.parent) {
44
+ throw new Error('Malformed AST');
45
+ }
46
+ const propertyIndex = parent.children.indexOf(existing.parent);
47
+ let removeBegin;
48
+ let removeEnd = existing.parent.offset + existing.parent.length;
49
+ if (propertyIndex > 0) {
50
+ // remove the comma of the previous node
51
+ let previous = parent.children[propertyIndex - 1];
52
+ removeBegin = previous.offset + previous.length;
53
+ }
54
+ else {
55
+ removeBegin = parent.offset + 1;
56
+ if (parent.children.length > 1) {
57
+ // remove the comma of the next node
58
+ let next = parent.children[1];
59
+ removeEnd = next.offset;
60
+ }
61
+ }
62
+ return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: '' }, options);
63
+ }
64
+ else {
65
+ // set value of existing property
66
+ return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
67
+ }
68
+ }
69
+ else {
70
+ if (value === void 0) { // delete
71
+ return []; // property does not exist, nothing to do
72
+ }
73
+ const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
74
+ const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map(p => p.children[0].value)) : parent.children.length;
75
+ let edit;
76
+ if (index > 0) {
77
+ let previous = parent.children[index - 1];
78
+ edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
79
+ }
80
+ else if (parent.children.length === 0) {
81
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty };
82
+ }
83
+ else {
84
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty + ',' };
85
+ }
86
+ return withFormatting(text, edit, options);
87
+ }
88
+ }
89
+ else if (parent.type === 'array' && typeof lastSegment === 'number' && Array.isArray(parent.children)) {
90
+ const insertIndex = lastSegment;
91
+ if (insertIndex === -1) {
92
+ // Insert
93
+ const newProperty = `${JSON.stringify(value)}`;
94
+ let edit;
95
+ if (parent.children.length === 0) {
96
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty };
97
+ }
98
+ else {
99
+ const previous = parent.children[parent.children.length - 1];
100
+ edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
101
+ }
102
+ return withFormatting(text, edit, options);
103
+ }
104
+ else if (value === void 0 && parent.children.length >= 0) {
105
+ // Removal
106
+ const removalIndex = lastSegment;
107
+ const toRemove = parent.children[removalIndex];
108
+ let edit;
109
+ if (parent.children.length === 1) {
110
+ // only item
111
+ edit = { offset: parent.offset + 1, length: parent.length - 2, content: '' };
112
+ }
113
+ else if (parent.children.length - 1 === removalIndex) {
114
+ // last item
115
+ let previous = parent.children[removalIndex - 1];
116
+ let offset = previous.offset + previous.length;
117
+ let parentEndOffset = parent.offset + parent.length;
118
+ edit = { offset, length: parentEndOffset - 2 - offset, content: '' };
119
+ }
120
+ else {
121
+ edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: '' };
122
+ }
123
+ return withFormatting(text, edit, options);
124
+ }
125
+ else if (value !== void 0) {
126
+ let edit;
127
+ const newProperty = `${JSON.stringify(value)}`;
128
+ if (!options.isArrayInsertion && parent.children.length > lastSegment) {
129
+ const toModify = parent.children[lastSegment];
130
+ edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
131
+ }
132
+ else if (parent.children.length === 0 || lastSegment === 0) {
133
+ edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + ',' };
134
+ }
135
+ else {
136
+ const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
137
+ const previous = parent.children[index - 1];
138
+ edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
139
+ }
140
+ return withFormatting(text, edit, options);
141
+ }
142
+ else {
143
+ throw new Error(`Can not ${value === void 0 ? 'remove' : (options.isArrayInsertion ? 'insert' : 'modify')} Array index ${insertIndex} as length is not sufficient`);
144
+ }
145
+ }
146
+ else {
147
+ throw new Error(`Can not add ${typeof lastSegment !== 'number' ? 'index' : 'property'} to parent of type ${parent.type}`);
148
+ }
149
+ }
150
+ function withFormatting(text, edit, options) {
151
+ if (!options.formattingOptions) {
152
+ return [edit];
153
+ }
154
+ // apply the edit
155
+ let newText = applyEdit(text, edit);
156
+ // format the new text
157
+ let begin = edit.offset;
158
+ let end = edit.offset + edit.content.length;
159
+ if (edit.length === 0 || edit.content.length === 0) { // insert or remove
160
+ while (begin > 0 && !isEOL(newText, begin - 1)) {
161
+ begin--;
162
+ }
163
+ while (end < newText.length && !isEOL(newText, end)) {
164
+ end++;
165
+ }
166
+ }
167
+ const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
168
+ // apply the formatting edits and track the begin and end offsets of the changes
169
+ for (let i = edits.length - 1; i >= 0; i--) {
170
+ const edit = edits[i];
171
+ newText = applyEdit(newText, edit);
172
+ begin = Math.min(begin, edit.offset);
173
+ end = Math.max(end, edit.offset + edit.length);
174
+ end += edit.content.length - edit.length;
175
+ }
176
+ // create a single edit with all changes
177
+ const editLength = text.length - (newText.length - end) - begin;
178
+ return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
179
+ }
180
+ export function applyEdit(text, edit) {
181
+ return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
182
+ }
183
+ export function isWS(text, offset) {
184
+ return '\r\n \t'.indexOf(text.charAt(offset)) !== -1;
185
+ }
@@ -0,0 +1,261 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ 'use strict';
6
+ import { createScanner } from './scanner';
7
+ import { cachedSpaces, cachedBreakLinesWithSpaces, supportedEols } from './string-intern';
8
+ export function format(documentText, range, options) {
9
+ let initialIndentLevel;
10
+ let formatText;
11
+ let formatTextStart;
12
+ let rangeStart;
13
+ let rangeEnd;
14
+ if (range) {
15
+ rangeStart = range.offset;
16
+ rangeEnd = rangeStart + range.length;
17
+ formatTextStart = rangeStart;
18
+ while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
19
+ formatTextStart--;
20
+ }
21
+ let endOffset = rangeEnd;
22
+ while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
23
+ endOffset++;
24
+ }
25
+ formatText = documentText.substring(formatTextStart, endOffset);
26
+ initialIndentLevel = computeIndentLevel(formatText, options);
27
+ }
28
+ else {
29
+ formatText = documentText;
30
+ initialIndentLevel = 0;
31
+ formatTextStart = 0;
32
+ rangeStart = 0;
33
+ rangeEnd = documentText.length;
34
+ }
35
+ const eol = getEOL(options, documentText);
36
+ const eolFastPathSupported = supportedEols.includes(eol);
37
+ let numberLineBreaks = 0;
38
+ let indentLevel = 0;
39
+ let indentValue;
40
+ if (options.insertSpaces) {
41
+ indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
42
+ }
43
+ else {
44
+ indentValue = '\t';
45
+ }
46
+ const indentType = indentValue === '\t' ? '\t' : ' ';
47
+ let scanner = createScanner(formatText, false);
48
+ let hasError = false;
49
+ function newLinesAndIndent() {
50
+ if (numberLineBreaks > 1) {
51
+ return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
52
+ }
53
+ const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
54
+ if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
55
+ return eol + repeat(indentValue, initialIndentLevel + indentLevel);
56
+ }
57
+ if (amountOfSpaces <= 0) {
58
+ return eol;
59
+ }
60
+ return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
61
+ }
62
+ function scanNext() {
63
+ let token = scanner.scan();
64
+ numberLineBreaks = 0;
65
+ while (token === 15 /* SyntaxKind.Trivia */ || token === 14 /* SyntaxKind.LineBreakTrivia */) {
66
+ if (token === 14 /* SyntaxKind.LineBreakTrivia */ && options.keepLines) {
67
+ numberLineBreaks += 1;
68
+ }
69
+ else if (token === 14 /* SyntaxKind.LineBreakTrivia */) {
70
+ numberLineBreaks = 1;
71
+ }
72
+ token = scanner.scan();
73
+ }
74
+ hasError = token === 16 /* SyntaxKind.Unknown */ || scanner.getTokenError() !== 0 /* ScanError.None */;
75
+ return token;
76
+ }
77
+ const editOperations = [];
78
+ function addEdit(text, startOffset, endOffset) {
79
+ if (!hasError && (!range || (startOffset < rangeEnd && endOffset > rangeStart)) && documentText.substring(startOffset, endOffset) !== text) {
80
+ editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
81
+ }
82
+ }
83
+ let firstToken = scanNext();
84
+ if (options.keepLines && numberLineBreaks > 0) {
85
+ addEdit(repeat(eol, numberLineBreaks), 0, 0);
86
+ }
87
+ if (firstToken !== 17 /* SyntaxKind.EOF */) {
88
+ let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
89
+ let initialIndent = (indentValue.length * initialIndentLevel < 20) && options.insertSpaces
90
+ ? cachedSpaces[indentValue.length * initialIndentLevel]
91
+ : repeat(indentValue, initialIndentLevel);
92
+ addEdit(initialIndent, formatTextStart, firstTokenStart);
93
+ }
94
+ while (firstToken !== 17 /* SyntaxKind.EOF */) {
95
+ let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
96
+ let secondToken = scanNext();
97
+ let replaceContent = '';
98
+ let needsLineBreak = false;
99
+ while (numberLineBreaks === 0 && (secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */)) {
100
+ let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
101
+ addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
102
+ firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
103
+ needsLineBreak = secondToken === 12 /* SyntaxKind.LineCommentTrivia */;
104
+ replaceContent = needsLineBreak ? newLinesAndIndent() : '';
105
+ secondToken = scanNext();
106
+ }
107
+ if (secondToken === 2 /* SyntaxKind.CloseBraceToken */) {
108
+ if (firstToken !== 1 /* SyntaxKind.OpenBraceToken */) {
109
+ indentLevel--;
110
+ }
111
+ ;
112
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1 /* SyntaxKind.OpenBraceToken */) {
113
+ replaceContent = newLinesAndIndent();
114
+ }
115
+ else if (options.keepLines) {
116
+ replaceContent = cachedSpaces[1];
117
+ }
118
+ }
119
+ else if (secondToken === 4 /* SyntaxKind.CloseBracketToken */) {
120
+ if (firstToken !== 3 /* SyntaxKind.OpenBracketToken */) {
121
+ indentLevel--;
122
+ }
123
+ ;
124
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3 /* SyntaxKind.OpenBracketToken */) {
125
+ replaceContent = newLinesAndIndent();
126
+ }
127
+ else if (options.keepLines) {
128
+ replaceContent = cachedSpaces[1];
129
+ }
130
+ }
131
+ else {
132
+ switch (firstToken) {
133
+ case 3 /* SyntaxKind.OpenBracketToken */:
134
+ case 1 /* SyntaxKind.OpenBraceToken */:
135
+ indentLevel++;
136
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
137
+ replaceContent = newLinesAndIndent();
138
+ }
139
+ else {
140
+ replaceContent = cachedSpaces[1];
141
+ }
142
+ break;
143
+ case 5 /* SyntaxKind.CommaToken */:
144
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
145
+ replaceContent = newLinesAndIndent();
146
+ }
147
+ else {
148
+ replaceContent = cachedSpaces[1];
149
+ }
150
+ break;
151
+ case 12 /* SyntaxKind.LineCommentTrivia */:
152
+ replaceContent = newLinesAndIndent();
153
+ break;
154
+ case 13 /* SyntaxKind.BlockCommentTrivia */:
155
+ if (numberLineBreaks > 0) {
156
+ replaceContent = newLinesAndIndent();
157
+ }
158
+ else if (!needsLineBreak) {
159
+ replaceContent = cachedSpaces[1];
160
+ }
161
+ break;
162
+ case 6 /* SyntaxKind.ColonToken */:
163
+ if (options.keepLines && numberLineBreaks > 0) {
164
+ replaceContent = newLinesAndIndent();
165
+ }
166
+ else if (!needsLineBreak) {
167
+ replaceContent = cachedSpaces[1];
168
+ }
169
+ break;
170
+ case 10 /* SyntaxKind.StringLiteral */:
171
+ if (options.keepLines && numberLineBreaks > 0) {
172
+ replaceContent = newLinesAndIndent();
173
+ }
174
+ else if (secondToken === 6 /* SyntaxKind.ColonToken */ && !needsLineBreak) {
175
+ replaceContent = '';
176
+ }
177
+ break;
178
+ case 7 /* SyntaxKind.NullKeyword */:
179
+ case 8 /* SyntaxKind.TrueKeyword */:
180
+ case 9 /* SyntaxKind.FalseKeyword */:
181
+ case 11 /* SyntaxKind.NumericLiteral */:
182
+ case 2 /* SyntaxKind.CloseBraceToken */:
183
+ case 4 /* SyntaxKind.CloseBracketToken */:
184
+ if (options.keepLines && numberLineBreaks > 0) {
185
+ replaceContent = newLinesAndIndent();
186
+ }
187
+ else {
188
+ if ((secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */) && !needsLineBreak) {
189
+ replaceContent = cachedSpaces[1];
190
+ }
191
+ else if (secondToken !== 5 /* SyntaxKind.CommaToken */ && secondToken !== 17 /* SyntaxKind.EOF */) {
192
+ hasError = true;
193
+ }
194
+ }
195
+ break;
196
+ case 16 /* SyntaxKind.Unknown */:
197
+ hasError = true;
198
+ break;
199
+ }
200
+ if (numberLineBreaks > 0 && (secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */)) {
201
+ replaceContent = newLinesAndIndent();
202
+ }
203
+ }
204
+ if (secondToken === 17 /* SyntaxKind.EOF */) {
205
+ if (options.keepLines && numberLineBreaks > 0) {
206
+ replaceContent = newLinesAndIndent();
207
+ }
208
+ else {
209
+ replaceContent = options.insertFinalNewline ? eol : '';
210
+ }
211
+ }
212
+ const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
213
+ addEdit(replaceContent, firstTokenEnd, secondTokenStart);
214
+ firstToken = secondToken;
215
+ }
216
+ return editOperations;
217
+ }
218
+ function repeat(s, count) {
219
+ let result = '';
220
+ for (let i = 0; i < count; i++) {
221
+ result += s;
222
+ }
223
+ return result;
224
+ }
225
+ function computeIndentLevel(content, options) {
226
+ let i = 0;
227
+ let nChars = 0;
228
+ const tabSize = options.tabSize || 4;
229
+ while (i < content.length) {
230
+ let ch = content.charAt(i);
231
+ if (ch === cachedSpaces[1]) {
232
+ nChars++;
233
+ }
234
+ else if (ch === '\t') {
235
+ nChars += tabSize;
236
+ }
237
+ else {
238
+ break;
239
+ }
240
+ i++;
241
+ }
242
+ return Math.floor(nChars / tabSize);
243
+ }
244
+ function getEOL(options, text) {
245
+ for (let i = 0; i < text.length; i++) {
246
+ const ch = text.charAt(i);
247
+ if (ch === '\r') {
248
+ if (i + 1 < text.length && text.charAt(i + 1) === '\n') {
249
+ return '\r\n';
250
+ }
251
+ return '\r';
252
+ }
253
+ else if (ch === '\n') {
254
+ return '\n';
255
+ }
256
+ }
257
+ return (options && options.eol) || '\n';
258
+ }
259
+ export function isEOL(text, offset) {
260
+ return '\r\n'.indexOf(text.charAt(offset)) !== -1;
261
+ }