@dcf-micro/eslint-config 5.0.0

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 (46) hide show
  1. package/dist/chunks/eslint-plugin-prettier.mjs +1716 -0
  2. package/dist/chunks/index.mjs +1341 -0
  3. package/dist/chunks/index10.mjs +39595 -0
  4. package/dist/chunks/index11.mjs +24 -0
  5. package/dist/chunks/index12.mjs +75273 -0
  6. package/dist/chunks/index13.mjs +55129 -0
  7. package/dist/chunks/index14.mjs +24 -0
  8. package/dist/chunks/index15.mjs +1441 -0
  9. package/dist/chunks/index2.mjs +31864 -0
  10. package/dist/chunks/index3.mjs +8154 -0
  11. package/dist/chunks/index4.mjs +24 -0
  12. package/dist/chunks/index5.mjs +44093 -0
  13. package/dist/chunks/index6.mjs +10371 -0
  14. package/dist/chunks/index7.mjs +21890 -0
  15. package/dist/chunks/index8.mjs +14424 -0
  16. package/dist/chunks/index9.mjs +194 -0
  17. package/dist/chunks/jiti.mjs +320 -0
  18. package/dist/index.d.mts +3897 -0
  19. package/dist/index.d.ts +3897 -0
  20. package/dist/index.mjs +4 -0
  21. package/dist/shared/eslint-config.BDBLGvXj.mjs +5282 -0
  22. package/dist/shared/eslint-config.BEdqg1el.mjs +12256 -0
  23. package/dist/shared/eslint-config.BKmXKm8B.mjs +5533 -0
  24. package/dist/shared/eslint-config.BjUMgISS.mjs +9012 -0
  25. package/dist/shared/eslint-config.Bk-3rH6Y.mjs +1355 -0
  26. package/dist/shared/eslint-config.BytuZ0Ec.mjs +20 -0
  27. package/dist/shared/eslint-config.C1V0I4Np.mjs +16900 -0
  28. package/dist/shared/eslint-config.CGxZQKHV.mjs +2091 -0
  29. package/dist/shared/eslint-config.COweQ1RR.mjs +5 -0
  30. package/dist/shared/eslint-config.CSnk9Q4w.mjs +9339 -0
  31. package/dist/shared/eslint-config.CWvTq0mr.mjs +2914 -0
  32. package/dist/shared/eslint-config.Ca4PTK8E.mjs +646 -0
  33. package/dist/shared/eslint-config.CmPTszkJ.mjs +3583 -0
  34. package/dist/shared/eslint-config.CqEANaNA.mjs +139622 -0
  35. package/dist/shared/eslint-config.CsePEcYJ.mjs +71 -0
  36. package/dist/shared/eslint-config.Cw6mETSZ.mjs +2580 -0
  37. package/dist/shared/eslint-config.DTVnsecK.mjs +1751 -0
  38. package/dist/shared/eslint-config.DWoU09EE.mjs +6958 -0
  39. package/dist/shared/eslint-config.DZvqTQUU.mjs +3818 -0
  40. package/dist/shared/eslint-config.Dhg7lT0g.mjs +1807 -0
  41. package/dist/shared/eslint-config.Du5y5qmf.mjs +200673 -0
  42. package/dist/shared/eslint-config.FKVuBSa4.mjs +394 -0
  43. package/dist/shared/eslint-config.I8d-HnmI.mjs +2654 -0
  44. package/dist/shared/eslint-config.YntqsQY1.mjs +40 -0
  45. package/dist/shared/eslint-config.uGTBNMD0.mjs +687 -0
  46. package/package.json +56 -0
@@ -0,0 +1,1716 @@
1
+ import { a as getAugmentedNamespace, g as getDefaultExportFromCjs } from '../shared/eslint-config.BDBLGvXj.mjs';
2
+ import { r as requireLib } from '../shared/eslint-config.uGTBNMD0.mjs';
3
+
4
+ function _mergeNamespaces(n, m) {
5
+ for (var i = 0; i < m.length; i++) {
6
+ const e = m[i];
7
+ if (typeof e !== 'string' && !Array.isArray(e)) { for (const k in e) {
8
+ if (k !== 'default' && !(k in n)) {
9
+ n[k] = e[k];
10
+ }
11
+ } }
12
+ }
13
+ return n;
14
+ }
15
+
16
+ /**
17
+ * This library modifies the diff-patch-match library by Neil Fraser
18
+ * by removing the patch and match functionality and certain advanced
19
+ * options in the diff function. The original license is as follows:
20
+ *
21
+ * ===
22
+ *
23
+ * Diff Match and Patch
24
+ *
25
+ * Copyright 2006 Google Inc.
26
+ * http://code.google.com/p/google-diff-match-patch/
27
+ *
28
+ * Licensed under the Apache License, Version 2.0 (the "License");
29
+ * you may not use this file except in compliance with the License.
30
+ * You may obtain a copy of the License at
31
+ *
32
+ * http://www.apache.org/licenses/LICENSE-2.0
33
+ *
34
+ * Unless required by applicable law or agreed to in writing, software
35
+ * distributed under the License is distributed on an "AS IS" BASIS,
36
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37
+ * See the License for the specific language governing permissions and
38
+ * limitations under the License.
39
+ */
40
+
41
+ var diff_1;
42
+ var hasRequiredDiff;
43
+
44
+ function requireDiff () {
45
+ if (hasRequiredDiff) return diff_1;
46
+ hasRequiredDiff = 1;
47
+ /**
48
+ * The data structure representing a diff is an array of tuples:
49
+ * [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
50
+ * which means: delete 'Hello', add 'Goodbye' and keep ' world.'
51
+ */
52
+ var DIFF_DELETE = -1;
53
+ var DIFF_INSERT = 1;
54
+ var DIFF_EQUAL = 0;
55
+
56
+ /**
57
+ * Find the differences between two texts. Simplifies the problem by stripping
58
+ * any common prefix or suffix off the texts before diffing.
59
+ * @param {string} text1 Old string to be diffed.
60
+ * @param {string} text2 New string to be diffed.
61
+ * @param {Int|Object} [cursor_pos] Edit position in text1 or object with more info
62
+ * @param {boolean} [cleanup] Apply semantic cleanup before returning.
63
+ * @return {Array} Array of diff tuples.
64
+ */
65
+ function diff_main(text1, text2, cursor_pos, cleanup, _fix_unicode) {
66
+ // Check for equality
67
+ if (text1 === text2) {
68
+ if (text1) {
69
+ return [[DIFF_EQUAL, text1]];
70
+ }
71
+ return [];
72
+ }
73
+
74
+ if (cursor_pos != null) {
75
+ var editdiff = find_cursor_edit_diff(text1, text2, cursor_pos);
76
+ if (editdiff) {
77
+ return editdiff;
78
+ }
79
+ }
80
+
81
+ // Trim off common prefix (speedup).
82
+ var commonlength = diff_commonPrefix(text1, text2);
83
+ var commonprefix = text1.substring(0, commonlength);
84
+ text1 = text1.substring(commonlength);
85
+ text2 = text2.substring(commonlength);
86
+
87
+ // Trim off common suffix (speedup).
88
+ commonlength = diff_commonSuffix(text1, text2);
89
+ var commonsuffix = text1.substring(text1.length - commonlength);
90
+ text1 = text1.substring(0, text1.length - commonlength);
91
+ text2 = text2.substring(0, text2.length - commonlength);
92
+
93
+ // Compute the diff on the middle block.
94
+ var diffs = diff_compute_(text1, text2);
95
+
96
+ // Restore the prefix and suffix.
97
+ if (commonprefix) {
98
+ diffs.unshift([DIFF_EQUAL, commonprefix]);
99
+ }
100
+ if (commonsuffix) {
101
+ diffs.push([DIFF_EQUAL, commonsuffix]);
102
+ }
103
+ diff_cleanupMerge(diffs, _fix_unicode);
104
+ if (cleanup) {
105
+ diff_cleanupSemantic(diffs);
106
+ }
107
+ return diffs;
108
+ }
109
+
110
+ /**
111
+ * Find the differences between two texts. Assumes that the texts do not
112
+ * have any common prefix or suffix.
113
+ * @param {string} text1 Old string to be diffed.
114
+ * @param {string} text2 New string to be diffed.
115
+ * @return {Array} Array of diff tuples.
116
+ */
117
+ function diff_compute_(text1, text2) {
118
+ var diffs;
119
+
120
+ if (!text1) {
121
+ // Just add some text (speedup).
122
+ return [[DIFF_INSERT, text2]];
123
+ }
124
+
125
+ if (!text2) {
126
+ // Just delete some text (speedup).
127
+ return [[DIFF_DELETE, text1]];
128
+ }
129
+
130
+ var longtext = text1.length > text2.length ? text1 : text2;
131
+ var shorttext = text1.length > text2.length ? text2 : text1;
132
+ var i = longtext.indexOf(shorttext);
133
+ if (i !== -1) {
134
+ // Shorter text is inside the longer text (speedup).
135
+ diffs = [
136
+ [DIFF_INSERT, longtext.substring(0, i)],
137
+ [DIFF_EQUAL, shorttext],
138
+ [DIFF_INSERT, longtext.substring(i + shorttext.length)],
139
+ ];
140
+ // Swap insertions for deletions if diff is reversed.
141
+ if (text1.length > text2.length) {
142
+ diffs[0][0] = diffs[2][0] = DIFF_DELETE;
143
+ }
144
+ return diffs;
145
+ }
146
+
147
+ if (shorttext.length === 1) {
148
+ // Single character string.
149
+ // After the previous speedup, the character can't be an equality.
150
+ return [
151
+ [DIFF_DELETE, text1],
152
+ [DIFF_INSERT, text2],
153
+ ];
154
+ }
155
+
156
+ // Check to see if the problem can be split in two.
157
+ var hm = diff_halfMatch_(text1, text2);
158
+ if (hm) {
159
+ // A half-match was found, sort out the return data.
160
+ var text1_a = hm[0];
161
+ var text1_b = hm[1];
162
+ var text2_a = hm[2];
163
+ var text2_b = hm[3];
164
+ var mid_common = hm[4];
165
+ // Send both pairs off for separate processing.
166
+ var diffs_a = diff_main(text1_a, text2_a);
167
+ var diffs_b = diff_main(text1_b, text2_b);
168
+ // Merge the results.
169
+ return diffs_a.concat([[DIFF_EQUAL, mid_common]], diffs_b);
170
+ }
171
+
172
+ return diff_bisect_(text1, text2);
173
+ }
174
+
175
+ /**
176
+ * Find the 'middle snake' of a diff, split the problem in two
177
+ * and return the recursively constructed diff.
178
+ * See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
179
+ * @param {string} text1 Old string to be diffed.
180
+ * @param {string} text2 New string to be diffed.
181
+ * @return {Array} Array of diff tuples.
182
+ * @private
183
+ */
184
+ function diff_bisect_(text1, text2) {
185
+ // Cache the text lengths to prevent multiple calls.
186
+ var text1_length = text1.length;
187
+ var text2_length = text2.length;
188
+ var max_d = Math.ceil((text1_length + text2_length) / 2);
189
+ var v_offset = max_d;
190
+ var v_length = 2 * max_d;
191
+ var v1 = new Array(v_length);
192
+ var v2 = new Array(v_length);
193
+ // Setting all elements to -1 is faster in Chrome & Firefox than mixing
194
+ // integers and undefined.
195
+ for (var x = 0; x < v_length; x++) {
196
+ v1[x] = -1;
197
+ v2[x] = -1;
198
+ }
199
+ v1[v_offset + 1] = 0;
200
+ v2[v_offset + 1] = 0;
201
+ var delta = text1_length - text2_length;
202
+ // If the total number of characters is odd, then the front path will collide
203
+ // with the reverse path.
204
+ var front = delta % 2 !== 0;
205
+ // Offsets for start and end of k loop.
206
+ // Prevents mapping of space beyond the grid.
207
+ var k1start = 0;
208
+ var k1end = 0;
209
+ var k2start = 0;
210
+ var k2end = 0;
211
+ for (var d = 0; d < max_d; d++) {
212
+ // Walk the front path one step.
213
+ for (var k1 = -d + k1start; k1 <= d - k1end; k1 += 2) {
214
+ var k1_offset = v_offset + k1;
215
+ var x1;
216
+ if (k1 === -d || (k1 !== d && v1[k1_offset - 1] < v1[k1_offset + 1])) {
217
+ x1 = v1[k1_offset + 1];
218
+ } else {
219
+ x1 = v1[k1_offset - 1] + 1;
220
+ }
221
+ var y1 = x1 - k1;
222
+ while (
223
+ x1 < text1_length &&
224
+ y1 < text2_length &&
225
+ text1.charAt(x1) === text2.charAt(y1)
226
+ ) {
227
+ x1++;
228
+ y1++;
229
+ }
230
+ v1[k1_offset] = x1;
231
+ if (x1 > text1_length) {
232
+ // Ran off the right of the graph.
233
+ k1end += 2;
234
+ } else if (y1 > text2_length) {
235
+ // Ran off the bottom of the graph.
236
+ k1start += 2;
237
+ } else if (front) {
238
+ var k2_offset = v_offset + delta - k1;
239
+ if (k2_offset >= 0 && k2_offset < v_length && v2[k2_offset] !== -1) {
240
+ // Mirror x2 onto top-left coordinate system.
241
+ var x2 = text1_length - v2[k2_offset];
242
+ if (x1 >= x2) {
243
+ // Overlap detected.
244
+ return diff_bisectSplit_(text1, text2, x1, y1);
245
+ }
246
+ }
247
+ }
248
+ }
249
+
250
+ // Walk the reverse path one step.
251
+ for (var k2 = -d + k2start; k2 <= d - k2end; k2 += 2) {
252
+ var k2_offset = v_offset + k2;
253
+ var x2;
254
+ if (k2 === -d || (k2 !== d && v2[k2_offset - 1] < v2[k2_offset + 1])) {
255
+ x2 = v2[k2_offset + 1];
256
+ } else {
257
+ x2 = v2[k2_offset - 1] + 1;
258
+ }
259
+ var y2 = x2 - k2;
260
+ while (
261
+ x2 < text1_length &&
262
+ y2 < text2_length &&
263
+ text1.charAt(text1_length - x2 - 1) ===
264
+ text2.charAt(text2_length - y2 - 1)
265
+ ) {
266
+ x2++;
267
+ y2++;
268
+ }
269
+ v2[k2_offset] = x2;
270
+ if (x2 > text1_length) {
271
+ // Ran off the left of the graph.
272
+ k2end += 2;
273
+ } else if (y2 > text2_length) {
274
+ // Ran off the top of the graph.
275
+ k2start += 2;
276
+ } else if (!front) {
277
+ var k1_offset = v_offset + delta - k2;
278
+ if (k1_offset >= 0 && k1_offset < v_length && v1[k1_offset] !== -1) {
279
+ var x1 = v1[k1_offset];
280
+ var y1 = v_offset + x1 - k1_offset;
281
+ // Mirror x2 onto top-left coordinate system.
282
+ x2 = text1_length - x2;
283
+ if (x1 >= x2) {
284
+ // Overlap detected.
285
+ return diff_bisectSplit_(text1, text2, x1, y1);
286
+ }
287
+ }
288
+ }
289
+ }
290
+ }
291
+ // Diff took too long and hit the deadline or
292
+ // number of diffs equals number of characters, no commonality at all.
293
+ return [
294
+ [DIFF_DELETE, text1],
295
+ [DIFF_INSERT, text2],
296
+ ];
297
+ }
298
+
299
+ /**
300
+ * Given the location of the 'middle snake', split the diff in two parts
301
+ * and recurse.
302
+ * @param {string} text1 Old string to be diffed.
303
+ * @param {string} text2 New string to be diffed.
304
+ * @param {number} x Index of split point in text1.
305
+ * @param {number} y Index of split point in text2.
306
+ * @return {Array} Array of diff tuples.
307
+ */
308
+ function diff_bisectSplit_(text1, text2, x, y) {
309
+ var text1a = text1.substring(0, x);
310
+ var text2a = text2.substring(0, y);
311
+ var text1b = text1.substring(x);
312
+ var text2b = text2.substring(y);
313
+
314
+ // Compute both diffs serially.
315
+ var diffs = diff_main(text1a, text2a);
316
+ var diffsb = diff_main(text1b, text2b);
317
+
318
+ return diffs.concat(diffsb);
319
+ }
320
+
321
+ /**
322
+ * Determine the common prefix of two strings.
323
+ * @param {string} text1 First string.
324
+ * @param {string} text2 Second string.
325
+ * @return {number} The number of characters common to the start of each
326
+ * string.
327
+ */
328
+ function diff_commonPrefix(text1, text2) {
329
+ // Quick check for common null cases.
330
+ if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) {
331
+ return 0;
332
+ }
333
+ // Binary search.
334
+ // Performance analysis: http://neil.fraser.name/news/2007/10/09/
335
+ var pointermin = 0;
336
+ var pointermax = Math.min(text1.length, text2.length);
337
+ var pointermid = pointermax;
338
+ var pointerstart = 0;
339
+ while (pointermin < pointermid) {
340
+ if (
341
+ text1.substring(pointerstart, pointermid) ==
342
+ text2.substring(pointerstart, pointermid)
343
+ ) {
344
+ pointermin = pointermid;
345
+ pointerstart = pointermin;
346
+ } else {
347
+ pointermax = pointermid;
348
+ }
349
+ pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
350
+ }
351
+
352
+ if (is_surrogate_pair_start(text1.charCodeAt(pointermid - 1))) {
353
+ pointermid--;
354
+ }
355
+
356
+ return pointermid;
357
+ }
358
+
359
+ /**
360
+ * Determine if the suffix of one string is the prefix of another.
361
+ * @param {string} text1 First string.
362
+ * @param {string} text2 Second string.
363
+ * @return {number} The number of characters common to the end of the first
364
+ * string and the start of the second string.
365
+ * @private
366
+ */
367
+ function diff_commonOverlap_(text1, text2) {
368
+ // Cache the text lengths to prevent multiple calls.
369
+ var text1_length = text1.length;
370
+ var text2_length = text2.length;
371
+ // Eliminate the null case.
372
+ if (text1_length == 0 || text2_length == 0) {
373
+ return 0;
374
+ }
375
+ // Truncate the longer string.
376
+ if (text1_length > text2_length) {
377
+ text1 = text1.substring(text1_length - text2_length);
378
+ } else if (text1_length < text2_length) {
379
+ text2 = text2.substring(0, text1_length);
380
+ }
381
+ var text_length = Math.min(text1_length, text2_length);
382
+ // Quick check for the worst case.
383
+ if (text1 == text2) {
384
+ return text_length;
385
+ }
386
+
387
+ // Start by looking for a single character match
388
+ // and increase length until no match is found.
389
+ // Performance analysis: http://neil.fraser.name/news/2010/11/04/
390
+ var best = 0;
391
+ var length = 1;
392
+ while (true) {
393
+ var pattern = text1.substring(text_length - length);
394
+ var found = text2.indexOf(pattern);
395
+ if (found == -1) {
396
+ return best;
397
+ }
398
+ length += found;
399
+ if (
400
+ found == 0 ||
401
+ text1.substring(text_length - length) == text2.substring(0, length)
402
+ ) {
403
+ best = length;
404
+ length++;
405
+ }
406
+ }
407
+ }
408
+
409
+ /**
410
+ * Determine the common suffix of two strings.
411
+ * @param {string} text1 First string.
412
+ * @param {string} text2 Second string.
413
+ * @return {number} The number of characters common to the end of each string.
414
+ */
415
+ function diff_commonSuffix(text1, text2) {
416
+ // Quick check for common null cases.
417
+ if (!text1 || !text2 || text1.slice(-1) !== text2.slice(-1)) {
418
+ return 0;
419
+ }
420
+ // Binary search.
421
+ // Performance analysis: http://neil.fraser.name/news/2007/10/09/
422
+ var pointermin = 0;
423
+ var pointermax = Math.min(text1.length, text2.length);
424
+ var pointermid = pointermax;
425
+ var pointerend = 0;
426
+ while (pointermin < pointermid) {
427
+ if (
428
+ text1.substring(text1.length - pointermid, text1.length - pointerend) ==
429
+ text2.substring(text2.length - pointermid, text2.length - pointerend)
430
+ ) {
431
+ pointermin = pointermid;
432
+ pointerend = pointermin;
433
+ } else {
434
+ pointermax = pointermid;
435
+ }
436
+ pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
437
+ }
438
+
439
+ if (is_surrogate_pair_end(text1.charCodeAt(text1.length - pointermid))) {
440
+ pointermid--;
441
+ }
442
+
443
+ return pointermid;
444
+ }
445
+
446
+ /**
447
+ * Do the two texts share a substring which is at least half the length of the
448
+ * longer text?
449
+ * This speedup can produce non-minimal diffs.
450
+ * @param {string} text1 First string.
451
+ * @param {string} text2 Second string.
452
+ * @return {Array.<string>} Five element Array, containing the prefix of
453
+ * text1, the suffix of text1, the prefix of text2, the suffix of
454
+ * text2 and the common middle. Or null if there was no match.
455
+ */
456
+ function diff_halfMatch_(text1, text2) {
457
+ var longtext = text1.length > text2.length ? text1 : text2;
458
+ var shorttext = text1.length > text2.length ? text2 : text1;
459
+ if (longtext.length < 4 || shorttext.length * 2 < longtext.length) {
460
+ return null; // Pointless.
461
+ }
462
+
463
+ /**
464
+ * Does a substring of shorttext exist within longtext such that the substring
465
+ * is at least half the length of longtext?
466
+ * Closure, but does not reference any external variables.
467
+ * @param {string} longtext Longer string.
468
+ * @param {string} shorttext Shorter string.
469
+ * @param {number} i Start index of quarter length substring within longtext.
470
+ * @return {Array.<string>} Five element Array, containing the prefix of
471
+ * longtext, the suffix of longtext, the prefix of shorttext, the suffix
472
+ * of shorttext and the common middle. Or null if there was no match.
473
+ * @private
474
+ */
475
+ function diff_halfMatchI_(longtext, shorttext, i) {
476
+ // Start with a 1/4 length substring at position i as a seed.
477
+ var seed = longtext.substring(i, i + Math.floor(longtext.length / 4));
478
+ var j = -1;
479
+ var best_common = "";
480
+ var best_longtext_a, best_longtext_b, best_shorttext_a, best_shorttext_b;
481
+ while ((j = shorttext.indexOf(seed, j + 1)) !== -1) {
482
+ var prefixLength = diff_commonPrefix(
483
+ longtext.substring(i),
484
+ shorttext.substring(j)
485
+ );
486
+ var suffixLength = diff_commonSuffix(
487
+ longtext.substring(0, i),
488
+ shorttext.substring(0, j)
489
+ );
490
+ if (best_common.length < suffixLength + prefixLength) {
491
+ best_common =
492
+ shorttext.substring(j - suffixLength, j) +
493
+ shorttext.substring(j, j + prefixLength);
494
+ best_longtext_a = longtext.substring(0, i - suffixLength);
495
+ best_longtext_b = longtext.substring(i + prefixLength);
496
+ best_shorttext_a = shorttext.substring(0, j - suffixLength);
497
+ best_shorttext_b = shorttext.substring(j + prefixLength);
498
+ }
499
+ }
500
+ if (best_common.length * 2 >= longtext.length) {
501
+ return [
502
+ best_longtext_a,
503
+ best_longtext_b,
504
+ best_shorttext_a,
505
+ best_shorttext_b,
506
+ best_common,
507
+ ];
508
+ } else {
509
+ return null;
510
+ }
511
+ }
512
+
513
+ // First check if the second quarter is the seed for a half-match.
514
+ var hm1 = diff_halfMatchI_(
515
+ longtext,
516
+ shorttext,
517
+ Math.ceil(longtext.length / 4)
518
+ );
519
+ // Check again based on the third quarter.
520
+ var hm2 = diff_halfMatchI_(
521
+ longtext,
522
+ shorttext,
523
+ Math.ceil(longtext.length / 2)
524
+ );
525
+ var hm;
526
+ if (!hm1 && !hm2) {
527
+ return null;
528
+ } else if (!hm2) {
529
+ hm = hm1;
530
+ } else if (!hm1) {
531
+ hm = hm2;
532
+ } else {
533
+ // Both matched. Select the longest.
534
+ hm = hm1[4].length > hm2[4].length ? hm1 : hm2;
535
+ }
536
+
537
+ // A half-match was found, sort out the return data.
538
+ var text1_a, text1_b, text2_a, text2_b;
539
+ if (text1.length > text2.length) {
540
+ text1_a = hm[0];
541
+ text1_b = hm[1];
542
+ text2_a = hm[2];
543
+ text2_b = hm[3];
544
+ } else {
545
+ text2_a = hm[0];
546
+ text2_b = hm[1];
547
+ text1_a = hm[2];
548
+ text1_b = hm[3];
549
+ }
550
+ var mid_common = hm[4];
551
+ return [text1_a, text1_b, text2_a, text2_b, mid_common];
552
+ }
553
+
554
+ /**
555
+ * Reduce the number of edits by eliminating semantically trivial equalities.
556
+ * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
557
+ */
558
+ function diff_cleanupSemantic(diffs) {
559
+ var changes = false;
560
+ var equalities = []; // Stack of indices where equalities are found.
561
+ var equalitiesLength = 0; // Keeping our own length var is faster in JS.
562
+ /** @type {?string} */
563
+ var lastequality = null;
564
+ // Always equal to diffs[equalities[equalitiesLength - 1]][1]
565
+ var pointer = 0; // Index of current position.
566
+ // Number of characters that changed prior to the equality.
567
+ var length_insertions1 = 0;
568
+ var length_deletions1 = 0;
569
+ // Number of characters that changed after the equality.
570
+ var length_insertions2 = 0;
571
+ var length_deletions2 = 0;
572
+ while (pointer < diffs.length) {
573
+ if (diffs[pointer][0] == DIFF_EQUAL) {
574
+ // Equality found.
575
+ equalities[equalitiesLength++] = pointer;
576
+ length_insertions1 = length_insertions2;
577
+ length_deletions1 = length_deletions2;
578
+ length_insertions2 = 0;
579
+ length_deletions2 = 0;
580
+ lastequality = diffs[pointer][1];
581
+ } else {
582
+ // An insertion or deletion.
583
+ if (diffs[pointer][0] == DIFF_INSERT) {
584
+ length_insertions2 += diffs[pointer][1].length;
585
+ } else {
586
+ length_deletions2 += diffs[pointer][1].length;
587
+ }
588
+ // Eliminate an equality that is smaller or equal to the edits on both
589
+ // sides of it.
590
+ if (
591
+ lastequality &&
592
+ lastequality.length <=
593
+ Math.max(length_insertions1, length_deletions1) &&
594
+ lastequality.length <= Math.max(length_insertions2, length_deletions2)
595
+ ) {
596
+ // Duplicate record.
597
+ diffs.splice(equalities[equalitiesLength - 1], 0, [
598
+ DIFF_DELETE,
599
+ lastequality,
600
+ ]);
601
+ // Change second copy to insert.
602
+ diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
603
+ // Throw away the equality we just deleted.
604
+ equalitiesLength--;
605
+ // Throw away the previous equality (it needs to be reevaluated).
606
+ equalitiesLength--;
607
+ pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1;
608
+ length_insertions1 = 0; // Reset the counters.
609
+ length_deletions1 = 0;
610
+ length_insertions2 = 0;
611
+ length_deletions2 = 0;
612
+ lastequality = null;
613
+ changes = true;
614
+ }
615
+ }
616
+ pointer++;
617
+ }
618
+
619
+ // Normalize the diff.
620
+ if (changes) {
621
+ diff_cleanupMerge(diffs);
622
+ }
623
+ diff_cleanupSemanticLossless(diffs);
624
+
625
+ // Find any overlaps between deletions and insertions.
626
+ // e.g: <del>abcxxx</del><ins>xxxdef</ins>
627
+ // -> <del>abc</del>xxx<ins>def</ins>
628
+ // e.g: <del>xxxabc</del><ins>defxxx</ins>
629
+ // -> <ins>def</ins>xxx<del>abc</del>
630
+ // Only extract an overlap if it is as big as the edit ahead or behind it.
631
+ pointer = 1;
632
+ while (pointer < diffs.length) {
633
+ if (
634
+ diffs[pointer - 1][0] == DIFF_DELETE &&
635
+ diffs[pointer][0] == DIFF_INSERT
636
+ ) {
637
+ var deletion = diffs[pointer - 1][1];
638
+ var insertion = diffs[pointer][1];
639
+ var overlap_length1 = diff_commonOverlap_(deletion, insertion);
640
+ var overlap_length2 = diff_commonOverlap_(insertion, deletion);
641
+ if (overlap_length1 >= overlap_length2) {
642
+ if (
643
+ overlap_length1 >= deletion.length / 2 ||
644
+ overlap_length1 >= insertion.length / 2
645
+ ) {
646
+ // Overlap found. Insert an equality and trim the surrounding edits.
647
+ diffs.splice(pointer, 0, [
648
+ DIFF_EQUAL,
649
+ insertion.substring(0, overlap_length1),
650
+ ]);
651
+ diffs[pointer - 1][1] = deletion.substring(
652
+ 0,
653
+ deletion.length - overlap_length1
654
+ );
655
+ diffs[pointer + 1][1] = insertion.substring(overlap_length1);
656
+ pointer++;
657
+ }
658
+ } else {
659
+ if (
660
+ overlap_length2 >= deletion.length / 2 ||
661
+ overlap_length2 >= insertion.length / 2
662
+ ) {
663
+ // Reverse overlap found.
664
+ // Insert an equality and swap and trim the surrounding edits.
665
+ diffs.splice(pointer, 0, [
666
+ DIFF_EQUAL,
667
+ deletion.substring(0, overlap_length2),
668
+ ]);
669
+ diffs[pointer - 1][0] = DIFF_INSERT;
670
+ diffs[pointer - 1][1] = insertion.substring(
671
+ 0,
672
+ insertion.length - overlap_length2
673
+ );
674
+ diffs[pointer + 1][0] = DIFF_DELETE;
675
+ diffs[pointer + 1][1] = deletion.substring(overlap_length2);
676
+ pointer++;
677
+ }
678
+ }
679
+ pointer++;
680
+ }
681
+ pointer++;
682
+ }
683
+ }
684
+
685
+ var nonAlphaNumericRegex_ = /[^a-zA-Z0-9]/;
686
+ var whitespaceRegex_ = /\s/;
687
+ var linebreakRegex_ = /[\r\n]/;
688
+ var blanklineEndRegex_ = /\n\r?\n$/;
689
+ var blanklineStartRegex_ = /^\r?\n\r?\n/;
690
+
691
+ /**
692
+ * Look for single edits surrounded on both sides by equalities
693
+ * which can be shifted sideways to align the edit to a word boundary.
694
+ * e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.
695
+ * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
696
+ */
697
+ function diff_cleanupSemanticLossless(diffs) {
698
+ /**
699
+ * Given two strings, compute a score representing whether the internal
700
+ * boundary falls on logical boundaries.
701
+ * Scores range from 6 (best) to 0 (worst).
702
+ * Closure, but does not reference any external variables.
703
+ * @param {string} one First string.
704
+ * @param {string} two Second string.
705
+ * @return {number} The score.
706
+ * @private
707
+ */
708
+ function diff_cleanupSemanticScore_(one, two) {
709
+ if (!one || !two) {
710
+ // Edges are the best.
711
+ return 6;
712
+ }
713
+
714
+ // Each port of this function behaves slightly differently due to
715
+ // subtle differences in each language's definition of things like
716
+ // 'whitespace'. Since this function's purpose is largely cosmetic,
717
+ // the choice has been made to use each language's native features
718
+ // rather than force total conformity.
719
+ var char1 = one.charAt(one.length - 1);
720
+ var char2 = two.charAt(0);
721
+ var nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex_);
722
+ var nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex_);
723
+ var whitespace1 = nonAlphaNumeric1 && char1.match(whitespaceRegex_);
724
+ var whitespace2 = nonAlphaNumeric2 && char2.match(whitespaceRegex_);
725
+ var lineBreak1 = whitespace1 && char1.match(linebreakRegex_);
726
+ var lineBreak2 = whitespace2 && char2.match(linebreakRegex_);
727
+ var blankLine1 = lineBreak1 && one.match(blanklineEndRegex_);
728
+ var blankLine2 = lineBreak2 && two.match(blanklineStartRegex_);
729
+
730
+ if (blankLine1 || blankLine2) {
731
+ // Five points for blank lines.
732
+ return 5;
733
+ } else if (lineBreak1 || lineBreak2) {
734
+ // Four points for line breaks.
735
+ return 4;
736
+ } else if (nonAlphaNumeric1 && !whitespace1 && whitespace2) {
737
+ // Three points for end of sentences.
738
+ return 3;
739
+ } else if (whitespace1 || whitespace2) {
740
+ // Two points for whitespace.
741
+ return 2;
742
+ } else if (nonAlphaNumeric1 || nonAlphaNumeric2) {
743
+ // One point for non-alphanumeric.
744
+ return 1;
745
+ }
746
+ return 0;
747
+ }
748
+
749
+ var pointer = 1;
750
+ // Intentionally ignore the first and last element (don't need checking).
751
+ while (pointer < diffs.length - 1) {
752
+ if (
753
+ diffs[pointer - 1][0] == DIFF_EQUAL &&
754
+ diffs[pointer + 1][0] == DIFF_EQUAL
755
+ ) {
756
+ // This is a single edit surrounded by equalities.
757
+ var equality1 = diffs[pointer - 1][1];
758
+ var edit = diffs[pointer][1];
759
+ var equality2 = diffs[pointer + 1][1];
760
+
761
+ // First, shift the edit as far left as possible.
762
+ var commonOffset = diff_commonSuffix(equality1, edit);
763
+ if (commonOffset) {
764
+ var commonString = edit.substring(edit.length - commonOffset);
765
+ equality1 = equality1.substring(0, equality1.length - commonOffset);
766
+ edit = commonString + edit.substring(0, edit.length - commonOffset);
767
+ equality2 = commonString + equality2;
768
+ }
769
+
770
+ // Second, step character by character right, looking for the best fit.
771
+ var bestEquality1 = equality1;
772
+ var bestEdit = edit;
773
+ var bestEquality2 = equality2;
774
+ var bestScore =
775
+ diff_cleanupSemanticScore_(equality1, edit) +
776
+ diff_cleanupSemanticScore_(edit, equality2);
777
+ while (edit.charAt(0) === equality2.charAt(0)) {
778
+ equality1 += edit.charAt(0);
779
+ edit = edit.substring(1) + equality2.charAt(0);
780
+ equality2 = equality2.substring(1);
781
+ var score =
782
+ diff_cleanupSemanticScore_(equality1, edit) +
783
+ diff_cleanupSemanticScore_(edit, equality2);
784
+ // The >= encourages trailing rather than leading whitespace on edits.
785
+ if (score >= bestScore) {
786
+ bestScore = score;
787
+ bestEquality1 = equality1;
788
+ bestEdit = edit;
789
+ bestEquality2 = equality2;
790
+ }
791
+ }
792
+
793
+ if (diffs[pointer - 1][1] != bestEquality1) {
794
+ // We have an improvement, save it back to the diff.
795
+ if (bestEquality1) {
796
+ diffs[pointer - 1][1] = bestEquality1;
797
+ } else {
798
+ diffs.splice(pointer - 1, 1);
799
+ pointer--;
800
+ }
801
+ diffs[pointer][1] = bestEdit;
802
+ if (bestEquality2) {
803
+ diffs[pointer + 1][1] = bestEquality2;
804
+ } else {
805
+ diffs.splice(pointer + 1, 1);
806
+ pointer--;
807
+ }
808
+ }
809
+ }
810
+ pointer++;
811
+ }
812
+ }
813
+
814
+ /**
815
+ * Reorder and merge like edit sections. Merge equalities.
816
+ * Any edit section can move as long as it doesn't cross an equality.
817
+ * @param {Array} diffs Array of diff tuples.
818
+ * @param {boolean} fix_unicode Whether to normalize to a unicode-correct diff
819
+ */
820
+ function diff_cleanupMerge(diffs, fix_unicode) {
821
+ diffs.push([DIFF_EQUAL, ""]); // Add a dummy entry at the end.
822
+ var pointer = 0;
823
+ var count_delete = 0;
824
+ var count_insert = 0;
825
+ var text_delete = "";
826
+ var text_insert = "";
827
+ var commonlength;
828
+ while (pointer < diffs.length) {
829
+ if (pointer < diffs.length - 1 && !diffs[pointer][1]) {
830
+ diffs.splice(pointer, 1);
831
+ continue;
832
+ }
833
+ switch (diffs[pointer][0]) {
834
+ case DIFF_INSERT:
835
+ count_insert++;
836
+ text_insert += diffs[pointer][1];
837
+ pointer++;
838
+ break;
839
+ case DIFF_DELETE:
840
+ count_delete++;
841
+ text_delete += diffs[pointer][1];
842
+ pointer++;
843
+ break;
844
+ case DIFF_EQUAL:
845
+ var previous_equality = pointer - count_insert - count_delete - 1;
846
+ if (fix_unicode) {
847
+ // prevent splitting of unicode surrogate pairs. when fix_unicode is true,
848
+ // we assume that the old and new text in the diff are complete and correct
849
+ // unicode-encoded JS strings, but the tuple boundaries may fall between
850
+ // surrogate pairs. we fix this by shaving off stray surrogates from the end
851
+ // of the previous equality and the beginning of this equality. this may create
852
+ // empty equalities or a common prefix or suffix. for example, if AB and AC are
853
+ // emojis, `[[0, 'A'], [-1, 'BA'], [0, 'C']]` would turn into deleting 'ABAC' and
854
+ // inserting 'AC', and then the common suffix 'AC' will be eliminated. in this
855
+ // particular case, both equalities go away, we absorb any previous inequalities,
856
+ // and we keep scanning for the next equality before rewriting the tuples.
857
+ if (
858
+ previous_equality >= 0 &&
859
+ ends_with_pair_start(diffs[previous_equality][1])
860
+ ) {
861
+ var stray = diffs[previous_equality][1].slice(-1);
862
+ diffs[previous_equality][1] = diffs[previous_equality][1].slice(
863
+ 0,
864
+ -1
865
+ );
866
+ text_delete = stray + text_delete;
867
+ text_insert = stray + text_insert;
868
+ if (!diffs[previous_equality][1]) {
869
+ // emptied out previous equality, so delete it and include previous delete/insert
870
+ diffs.splice(previous_equality, 1);
871
+ pointer--;
872
+ var k = previous_equality - 1;
873
+ if (diffs[k] && diffs[k][0] === DIFF_INSERT) {
874
+ count_insert++;
875
+ text_insert = diffs[k][1] + text_insert;
876
+ k--;
877
+ }
878
+ if (diffs[k] && diffs[k][0] === DIFF_DELETE) {
879
+ count_delete++;
880
+ text_delete = diffs[k][1] + text_delete;
881
+ k--;
882
+ }
883
+ previous_equality = k;
884
+ }
885
+ }
886
+ if (starts_with_pair_end(diffs[pointer][1])) {
887
+ var stray = diffs[pointer][1].charAt(0);
888
+ diffs[pointer][1] = diffs[pointer][1].slice(1);
889
+ text_delete += stray;
890
+ text_insert += stray;
891
+ }
892
+ }
893
+ if (pointer < diffs.length - 1 && !diffs[pointer][1]) {
894
+ // for empty equality not at end, wait for next equality
895
+ diffs.splice(pointer, 1);
896
+ break;
897
+ }
898
+ if (text_delete.length > 0 || text_insert.length > 0) {
899
+ // note that diff_commonPrefix and diff_commonSuffix are unicode-aware
900
+ if (text_delete.length > 0 && text_insert.length > 0) {
901
+ // Factor out any common prefixes.
902
+ commonlength = diff_commonPrefix(text_insert, text_delete);
903
+ if (commonlength !== 0) {
904
+ if (previous_equality >= 0) {
905
+ diffs[previous_equality][1] += text_insert.substring(
906
+ 0,
907
+ commonlength
908
+ );
909
+ } else {
910
+ diffs.splice(0, 0, [
911
+ DIFF_EQUAL,
912
+ text_insert.substring(0, commonlength),
913
+ ]);
914
+ pointer++;
915
+ }
916
+ text_insert = text_insert.substring(commonlength);
917
+ text_delete = text_delete.substring(commonlength);
918
+ }
919
+ // Factor out any common suffixes.
920
+ commonlength = diff_commonSuffix(text_insert, text_delete);
921
+ if (commonlength !== 0) {
922
+ diffs[pointer][1] =
923
+ text_insert.substring(text_insert.length - commonlength) +
924
+ diffs[pointer][1];
925
+ text_insert = text_insert.substring(
926
+ 0,
927
+ text_insert.length - commonlength
928
+ );
929
+ text_delete = text_delete.substring(
930
+ 0,
931
+ text_delete.length - commonlength
932
+ );
933
+ }
934
+ }
935
+ // Delete the offending records and add the merged ones.
936
+ var n = count_insert + count_delete;
937
+ if (text_delete.length === 0 && text_insert.length === 0) {
938
+ diffs.splice(pointer - n, n);
939
+ pointer = pointer - n;
940
+ } else if (text_delete.length === 0) {
941
+ diffs.splice(pointer - n, n, [DIFF_INSERT, text_insert]);
942
+ pointer = pointer - n + 1;
943
+ } else if (text_insert.length === 0) {
944
+ diffs.splice(pointer - n, n, [DIFF_DELETE, text_delete]);
945
+ pointer = pointer - n + 1;
946
+ } else {
947
+ diffs.splice(
948
+ pointer - n,
949
+ n,
950
+ [DIFF_DELETE, text_delete],
951
+ [DIFF_INSERT, text_insert]
952
+ );
953
+ pointer = pointer - n + 2;
954
+ }
955
+ }
956
+ if (pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL) {
957
+ // Merge this equality with the previous one.
958
+ diffs[pointer - 1][1] += diffs[pointer][1];
959
+ diffs.splice(pointer, 1);
960
+ } else {
961
+ pointer++;
962
+ }
963
+ count_insert = 0;
964
+ count_delete = 0;
965
+ text_delete = "";
966
+ text_insert = "";
967
+ break;
968
+ }
969
+ }
970
+ if (diffs[diffs.length - 1][1] === "") {
971
+ diffs.pop(); // Remove the dummy entry at the end.
972
+ }
973
+
974
+ // Second pass: look for single edits surrounded on both sides by equalities
975
+ // which can be shifted sideways to eliminate an equality.
976
+ // e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC
977
+ var changes = false;
978
+ pointer = 1;
979
+ // Intentionally ignore the first and last element (don't need checking).
980
+ while (pointer < diffs.length - 1) {
981
+ if (
982
+ diffs[pointer - 1][0] === DIFF_EQUAL &&
983
+ diffs[pointer + 1][0] === DIFF_EQUAL
984
+ ) {
985
+ // This is a single edit surrounded by equalities.
986
+ if (
987
+ diffs[pointer][1].substring(
988
+ diffs[pointer][1].length - diffs[pointer - 1][1].length
989
+ ) === diffs[pointer - 1][1]
990
+ ) {
991
+ // Shift the edit over the previous equality.
992
+ diffs[pointer][1] =
993
+ diffs[pointer - 1][1] +
994
+ diffs[pointer][1].substring(
995
+ 0,
996
+ diffs[pointer][1].length - diffs[pointer - 1][1].length
997
+ );
998
+ diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
999
+ diffs.splice(pointer - 1, 1);
1000
+ changes = true;
1001
+ } else if (
1002
+ diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) ==
1003
+ diffs[pointer + 1][1]
1004
+ ) {
1005
+ // Shift the edit over the next equality.
1006
+ diffs[pointer - 1][1] += diffs[pointer + 1][1];
1007
+ diffs[pointer][1] =
1008
+ diffs[pointer][1].substring(diffs[pointer + 1][1].length) +
1009
+ diffs[pointer + 1][1];
1010
+ diffs.splice(pointer + 1, 1);
1011
+ changes = true;
1012
+ }
1013
+ }
1014
+ pointer++;
1015
+ }
1016
+ // If shifts were made, the diff needs reordering and another shift sweep.
1017
+ if (changes) {
1018
+ diff_cleanupMerge(diffs, fix_unicode);
1019
+ }
1020
+ }
1021
+
1022
+ function is_surrogate_pair_start(charCode) {
1023
+ return charCode >= 0xd800 && charCode <= 0xdbff;
1024
+ }
1025
+
1026
+ function is_surrogate_pair_end(charCode) {
1027
+ return charCode >= 0xdc00 && charCode <= 0xdfff;
1028
+ }
1029
+
1030
+ function starts_with_pair_end(str) {
1031
+ return is_surrogate_pair_end(str.charCodeAt(0));
1032
+ }
1033
+
1034
+ function ends_with_pair_start(str) {
1035
+ return is_surrogate_pair_start(str.charCodeAt(str.length - 1));
1036
+ }
1037
+
1038
+ function remove_empty_tuples(tuples) {
1039
+ var ret = [];
1040
+ for (var i = 0; i < tuples.length; i++) {
1041
+ if (tuples[i][1].length > 0) {
1042
+ ret.push(tuples[i]);
1043
+ }
1044
+ }
1045
+ return ret;
1046
+ }
1047
+
1048
+ function make_edit_splice(before, oldMiddle, newMiddle, after) {
1049
+ if (ends_with_pair_start(before) || starts_with_pair_end(after)) {
1050
+ return null;
1051
+ }
1052
+ return remove_empty_tuples([
1053
+ [DIFF_EQUAL, before],
1054
+ [DIFF_DELETE, oldMiddle],
1055
+ [DIFF_INSERT, newMiddle],
1056
+ [DIFF_EQUAL, after],
1057
+ ]);
1058
+ }
1059
+
1060
+ function find_cursor_edit_diff(oldText, newText, cursor_pos) {
1061
+ // note: this runs after equality check has ruled out exact equality
1062
+ var oldRange =
1063
+ typeof cursor_pos === "number"
1064
+ ? { index: cursor_pos, length: 0 }
1065
+ : cursor_pos.oldRange;
1066
+ var newRange = typeof cursor_pos === "number" ? null : cursor_pos.newRange;
1067
+ // take into account the old and new selection to generate the best diff
1068
+ // possible for a text edit. for example, a text change from "xxx" to "xx"
1069
+ // could be a delete or forwards-delete of any one of the x's, or the
1070
+ // result of selecting two of the x's and typing "x".
1071
+ var oldLength = oldText.length;
1072
+ var newLength = newText.length;
1073
+ if (oldRange.length === 0 && (newRange === null || newRange.length === 0)) {
1074
+ // see if we have an insert or delete before or after cursor
1075
+ var oldCursor = oldRange.index;
1076
+ var oldBefore = oldText.slice(0, oldCursor);
1077
+ var oldAfter = oldText.slice(oldCursor);
1078
+ var maybeNewCursor = newRange ? newRange.index : null;
1079
+ editBefore: {
1080
+ // is this an insert or delete right before oldCursor?
1081
+ var newCursor = oldCursor + newLength - oldLength;
1082
+ if (maybeNewCursor !== null && maybeNewCursor !== newCursor) {
1083
+ break editBefore;
1084
+ }
1085
+ if (newCursor < 0 || newCursor > newLength) {
1086
+ break editBefore;
1087
+ }
1088
+ var newBefore = newText.slice(0, newCursor);
1089
+ var newAfter = newText.slice(newCursor);
1090
+ if (newAfter !== oldAfter) {
1091
+ break editBefore;
1092
+ }
1093
+ var prefixLength = Math.min(oldCursor, newCursor);
1094
+ var oldPrefix = oldBefore.slice(0, prefixLength);
1095
+ var newPrefix = newBefore.slice(0, prefixLength);
1096
+ if (oldPrefix !== newPrefix) {
1097
+ break editBefore;
1098
+ }
1099
+ var oldMiddle = oldBefore.slice(prefixLength);
1100
+ var newMiddle = newBefore.slice(prefixLength);
1101
+ return make_edit_splice(oldPrefix, oldMiddle, newMiddle, oldAfter);
1102
+ }
1103
+ editAfter: {
1104
+ // is this an insert or delete right after oldCursor?
1105
+ if (maybeNewCursor !== null && maybeNewCursor !== oldCursor) {
1106
+ break editAfter;
1107
+ }
1108
+ var cursor = oldCursor;
1109
+ var newBefore = newText.slice(0, cursor);
1110
+ var newAfter = newText.slice(cursor);
1111
+ if (newBefore !== oldBefore) {
1112
+ break editAfter;
1113
+ }
1114
+ var suffixLength = Math.min(oldLength - cursor, newLength - cursor);
1115
+ var oldSuffix = oldAfter.slice(oldAfter.length - suffixLength);
1116
+ var newSuffix = newAfter.slice(newAfter.length - suffixLength);
1117
+ if (oldSuffix !== newSuffix) {
1118
+ break editAfter;
1119
+ }
1120
+ var oldMiddle = oldAfter.slice(0, oldAfter.length - suffixLength);
1121
+ var newMiddle = newAfter.slice(0, newAfter.length - suffixLength);
1122
+ return make_edit_splice(oldBefore, oldMiddle, newMiddle, oldSuffix);
1123
+ }
1124
+ }
1125
+ if (oldRange.length > 0 && newRange && newRange.length === 0) {
1126
+ replaceRange: {
1127
+ // see if diff could be a splice of the old selection range
1128
+ var oldPrefix = oldText.slice(0, oldRange.index);
1129
+ var oldSuffix = oldText.slice(oldRange.index + oldRange.length);
1130
+ var prefixLength = oldPrefix.length;
1131
+ var suffixLength = oldSuffix.length;
1132
+ if (newLength < prefixLength + suffixLength) {
1133
+ break replaceRange;
1134
+ }
1135
+ var newPrefix = newText.slice(0, prefixLength);
1136
+ var newSuffix = newText.slice(newLength - suffixLength);
1137
+ if (oldPrefix !== newPrefix || oldSuffix !== newSuffix) {
1138
+ break replaceRange;
1139
+ }
1140
+ var oldMiddle = oldText.slice(prefixLength, oldLength - suffixLength);
1141
+ var newMiddle = newText.slice(prefixLength, newLength - suffixLength);
1142
+ return make_edit_splice(oldPrefix, oldMiddle, newMiddle, oldSuffix);
1143
+ }
1144
+ }
1145
+
1146
+ return null;
1147
+ }
1148
+
1149
+ function diff(text1, text2, cursor_pos, cleanup) {
1150
+ // only pass fix_unicode=true at the top level, not when diff_main is
1151
+ // recursively invoked
1152
+ return diff_main(text1, text2, cursor_pos, cleanup, true);
1153
+ }
1154
+
1155
+ diff.INSERT = DIFF_INSERT;
1156
+ diff.DELETE = DIFF_DELETE;
1157
+ diff.EQUAL = DIFF_EQUAL;
1158
+
1159
+ diff_1 = diff;
1160
+ return diff_1;
1161
+ }
1162
+
1163
+ var prettierLinterHelpers;
1164
+ var hasRequiredPrettierLinterHelpers;
1165
+
1166
+ function requirePrettierLinterHelpers () {
1167
+ if (hasRequiredPrettierLinterHelpers) return prettierLinterHelpers;
1168
+ hasRequiredPrettierLinterHelpers = 1;
1169
+ const diff = requireDiff();
1170
+
1171
+ const LINE_ENDING_RE = /\r\n|[\r\n\u2028\u2029]/;
1172
+
1173
+ /**
1174
+ * Converts invisible characters to a commonly recognizable visible form.
1175
+ * @param {string} str - The string with invisibles to convert.
1176
+ * @returns {string} The converted string.
1177
+ */
1178
+ function showInvisibles(str) {
1179
+ let ret = '';
1180
+ for (let i = 0; i < str.length; i++) {
1181
+ switch (str[i]) {
1182
+ case ' ':
1183
+ ret += '·'; // Middle Dot, \u00B7
1184
+ break;
1185
+ case '\n':
1186
+ ret += '⏎'; // Return Symbol, \u23ce
1187
+ break;
1188
+ case '\t':
1189
+ ret += '↹'; // Left Arrow To Bar Over Right Arrow To Bar, \u21b9
1190
+ break;
1191
+ case '\r':
1192
+ ret += '␍'; // Carriage Return Symbol, \u240D
1193
+ break;
1194
+ default:
1195
+ ret += str[i];
1196
+ break;
1197
+ }
1198
+ }
1199
+ return ret;
1200
+ }
1201
+
1202
+ /**
1203
+ * Generate results for differences between source code and formatted version.
1204
+ *
1205
+ * @param {string} source - The original source.
1206
+ * @param {string} prettierSource - The Prettier formatted source.
1207
+ * @returns {Array} - An array containing { operation, offset, insertText, deleteText }
1208
+ */
1209
+ function generateDifferences(source, prettierSource) {
1210
+ // fast-diff returns the differences between two texts as a series of
1211
+ // INSERT, DELETE or EQUAL operations. The results occur only in these
1212
+ // sequences:
1213
+ // /-> INSERT -> EQUAL
1214
+ // EQUAL | /-> EQUAL
1215
+ // \-> DELETE |
1216
+ // \-> INSERT -> EQUAL
1217
+ // Instead of reporting issues at each INSERT or DELETE, certain sequences
1218
+ // are batched together and are reported as a friendlier "replace" operation:
1219
+ // - A DELETE immediately followed by an INSERT.
1220
+ // - Any number of INSERTs and DELETEs where the joining EQUAL of one's end
1221
+ // and another's beginning does not have line endings (i.e. issues that occur
1222
+ // on contiguous lines).
1223
+
1224
+ const results = diff(source, prettierSource);
1225
+ const differences = [];
1226
+
1227
+ const batch = [];
1228
+ let offset = 0; // NOTE: INSERT never advances the offset.
1229
+ while (results.length) {
1230
+ const result = results.shift();
1231
+ const op = result[0];
1232
+ const text = result[1];
1233
+ switch (op) {
1234
+ case diff.INSERT:
1235
+ case diff.DELETE:
1236
+ batch.push(result);
1237
+ break;
1238
+ case diff.EQUAL:
1239
+ if (results.length) {
1240
+ if (batch.length) {
1241
+ if (LINE_ENDING_RE.test(text)) {
1242
+ flush();
1243
+ offset += text.length;
1244
+ } else {
1245
+ batch.push(result);
1246
+ }
1247
+ } else {
1248
+ offset += text.length;
1249
+ }
1250
+ }
1251
+ break;
1252
+ default:
1253
+ throw new Error(`Unexpected fast-diff operation "${op}"`);
1254
+ }
1255
+ if (batch.length && !results.length) {
1256
+ flush();
1257
+ }
1258
+ }
1259
+
1260
+ return differences;
1261
+
1262
+ function flush() {
1263
+ let aheadDeleteText = '';
1264
+ let aheadInsertText = '';
1265
+ while (batch.length) {
1266
+ const next = batch.shift();
1267
+ const op = next[0];
1268
+ const text = next[1];
1269
+ switch (op) {
1270
+ case diff.INSERT:
1271
+ aheadInsertText += text;
1272
+ break;
1273
+ case diff.DELETE:
1274
+ aheadDeleteText += text;
1275
+ break;
1276
+ case diff.EQUAL:
1277
+ aheadDeleteText += text;
1278
+ aheadInsertText += text;
1279
+ break;
1280
+ }
1281
+ }
1282
+ if (aheadDeleteText && aheadInsertText) {
1283
+ differences.push({
1284
+ offset,
1285
+ operation: generateDifferences.REPLACE,
1286
+ insertText: aheadInsertText,
1287
+ deleteText: aheadDeleteText,
1288
+ });
1289
+ } else if (!aheadDeleteText && aheadInsertText) {
1290
+ differences.push({
1291
+ offset,
1292
+ operation: generateDifferences.INSERT,
1293
+ insertText: aheadInsertText,
1294
+ });
1295
+ } else if (aheadDeleteText && !aheadInsertText) {
1296
+ differences.push({
1297
+ offset,
1298
+ operation: generateDifferences.DELETE,
1299
+ deleteText: aheadDeleteText,
1300
+ });
1301
+ }
1302
+ offset += aheadDeleteText.length;
1303
+ }
1304
+ }
1305
+
1306
+ generateDifferences.INSERT = 'insert';
1307
+ generateDifferences.DELETE = 'delete';
1308
+ generateDifferences.REPLACE = 'replace';
1309
+
1310
+ prettierLinterHelpers = {
1311
+ showInvisibles,
1312
+ generateDifferences,
1313
+ };
1314
+ return prettierLinterHelpers;
1315
+ }
1316
+
1317
+ const name = "eslint-plugin-prettier";
1318
+ const version = "5.5.1";
1319
+ const description = "Runs prettier as an eslint rule";
1320
+ const repository = "https://github.com/prettier/eslint-plugin-prettier.git";
1321
+ const homepage = "https://github.com/prettier/eslint-plugin-prettier#readme";
1322
+ const author = "Teddy Katz";
1323
+ const maintainers = [
1324
+ "JounQin <admin@1stg.me> (https://github.com/JounQin)"
1325
+ ];
1326
+ const funding = "https://opencollective.com/eslint-plugin-prettier";
1327
+ const license = "MIT";
1328
+ const engines = {
1329
+ node: "^14.18.0 || >=16.0.0"
1330
+ };
1331
+ const main = "eslint-plugin-prettier.js";
1332
+ const types = "eslint-plugin-prettier.d.ts";
1333
+ const exports = {
1334
+ ".": {
1335
+ types: "./eslint-plugin-prettier.d.ts",
1336
+ "default": "./eslint-plugin-prettier.js"
1337
+ },
1338
+ "./recommended": {
1339
+ types: "./recommended.d.ts",
1340
+ "default": "./recommended.js"
1341
+ },
1342
+ "./package.json": "./package.json"
1343
+ };
1344
+ const files = [
1345
+ "eslint-plugin-prettier.d.ts",
1346
+ "eslint-plugin-prettier.js",
1347
+ "recommended.d.ts",
1348
+ "recommended.js",
1349
+ "worker.mjs"
1350
+ ];
1351
+ const keywords = [
1352
+ "eslint",
1353
+ "eslintplugin",
1354
+ "eslint-plugin",
1355
+ "prettier"
1356
+ ];
1357
+ const peerDependencies = {
1358
+ "@types/eslint": ">=8.0.0",
1359
+ eslint: ">=8.0.0",
1360
+ "eslint-config-prettier": ">= 7.0.0 <10.0.0 || >=10.1.0",
1361
+ prettier: ">=3.0.0"
1362
+ };
1363
+ const peerDependenciesMeta = {
1364
+ "@types/eslint": {
1365
+ optional: true
1366
+ },
1367
+ "eslint-config-prettier": {
1368
+ optional: true
1369
+ }
1370
+ };
1371
+ const dependencies = {
1372
+ "prettier-linter-helpers": "^1.0.0",
1373
+ synckit: "^0.11.7"
1374
+ };
1375
+ const _package = {
1376
+ name: name,
1377
+ version: version,
1378
+ description: description,
1379
+ repository: repository,
1380
+ homepage: homepage,
1381
+ author: author,
1382
+ maintainers: maintainers,
1383
+ funding: funding,
1384
+ license: license,
1385
+ engines: engines,
1386
+ main: main,
1387
+ types: types,
1388
+ exports: exports,
1389
+ files: files,
1390
+ keywords: keywords,
1391
+ peerDependencies: peerDependencies,
1392
+ peerDependenciesMeta: peerDependenciesMeta,
1393
+ dependencies: dependencies
1394
+ };
1395
+
1396
+ const _package$1 = {
1397
+ __proto__: null,
1398
+ author: author,
1399
+ default: _package,
1400
+ dependencies: dependencies,
1401
+ description: description,
1402
+ engines: engines,
1403
+ exports: exports,
1404
+ files: files,
1405
+ funding: funding,
1406
+ homepage: homepage,
1407
+ keywords: keywords,
1408
+ license: license,
1409
+ main: main,
1410
+ maintainers: maintainers,
1411
+ name: name,
1412
+ peerDependencies: peerDependencies,
1413
+ peerDependenciesMeta: peerDependenciesMeta,
1414
+ repository: repository,
1415
+ types: types,
1416
+ version: version
1417
+ };
1418
+
1419
+ const require$$1 = /*@__PURE__*/getAugmentedNamespace(_package$1);
1420
+
1421
+ /**
1422
+ * @file Runs `prettier` as an ESLint rule.
1423
+ * @author Andres Suarez
1424
+ */
1425
+
1426
+ var eslintPluginPrettier_1;
1427
+ var hasRequiredEslintPluginPrettier;
1428
+
1429
+ function requireEslintPluginPrettier () {
1430
+ if (hasRequiredEslintPluginPrettier) return eslintPluginPrettier_1;
1431
+ hasRequiredEslintPluginPrettier = 1;
1432
+
1433
+ // ------------------------------------------------------------------------------
1434
+ // Requirements
1435
+ // ------------------------------------------------------------------------------
1436
+
1437
+ const {
1438
+ showInvisibles,
1439
+ generateDifferences,
1440
+ } = requirePrettierLinterHelpers();
1441
+ const { name, version } = require$$1;
1442
+
1443
+ // ------------------------------------------------------------------------------
1444
+ // Constants
1445
+ // ------------------------------------------------------------------------------
1446
+
1447
+ const { INSERT, DELETE, REPLACE } = generateDifferences;
1448
+
1449
+ // ------------------------------------------------------------------------------
1450
+ // Privates
1451
+ // ------------------------------------------------------------------------------
1452
+
1453
+ // Lazily-loaded Prettier.
1454
+ /** @type {PrettierFormat} */
1455
+ let prettierFormat;
1456
+
1457
+ // ------------------------------------------------------------------------------
1458
+ // Rule Definition
1459
+ // ------------------------------------------------------------------------------
1460
+
1461
+ /** @type {WeakMap<SourceCode, number[]>} */
1462
+ const lineIndexesCache = new WeakMap();
1463
+
1464
+ /**
1465
+ * Ponyfill `sourceCode.getLocFromIndex` when it's unavailable.
1466
+ *
1467
+ * See also `getLocFromIndex` in `@eslint/js`.
1468
+ *
1469
+ * @param {SourceCode} sourceCode
1470
+ * @param {number} index
1471
+ * @returns {Position}
1472
+ */
1473
+ function getLocFromIndex(sourceCode, index) {
1474
+ if (typeof sourceCode.getLocFromIndex === 'function') {
1475
+ return sourceCode.getLocFromIndex(index);
1476
+ }
1477
+
1478
+ let lineIndexes = lineIndexesCache.get(sourceCode);
1479
+ if (!lineIndexes) {
1480
+ lineIndexes = [...sourceCode.text.matchAll(/\r?\n/g)].map(
1481
+ match => match.index,
1482
+ );
1483
+ // first line in the file starts at byte offset 0
1484
+ lineIndexes.unshift(0);
1485
+ lineIndexesCache.set(sourceCode, lineIndexes);
1486
+ }
1487
+
1488
+ let line = 0;
1489
+ while (line + 1 < lineIndexes.length && lineIndexes[line + 1] < index) {
1490
+ line += 1;
1491
+ }
1492
+ const column = index - lineIndexes[line];
1493
+
1494
+ return { line: line + 1, column };
1495
+ }
1496
+
1497
+ /**
1498
+ * Reports a difference.
1499
+ *
1500
+ * @param {Rule.RuleContext} context - The ESLint rule context.
1501
+ * @param {Difference} difference - The difference object.
1502
+ * @returns {void}
1503
+ */
1504
+ function reportDifference(context, difference) {
1505
+ const { operation, offset, deleteText = '', insertText = '' } = difference;
1506
+ /** @type {AST.Range} */
1507
+ const range = [offset, offset + deleteText.length];
1508
+ // `context.getSourceCode()` was deprecated in ESLint v8.40.0 and replaced
1509
+ // with the `sourceCode` property.
1510
+ // TODO: Only use property when our eslint peerDependency is >=8.40.0.
1511
+ const sourceCode = context.sourceCode ?? context.getSourceCode();
1512
+
1513
+ const [start, end] = range.map(index => getLocFromIndex(sourceCode, index));
1514
+
1515
+ context.report({
1516
+ messageId: operation,
1517
+ data: {
1518
+ deleteText: showInvisibles(deleteText),
1519
+ insertText: showInvisibles(insertText),
1520
+ },
1521
+ loc: { start, end },
1522
+ fix: fixer => fixer.replaceTextRange(range, insertText),
1523
+ });
1524
+ }
1525
+
1526
+ // ------------------------------------------------------------------------------
1527
+ // Module Definition
1528
+ // ------------------------------------------------------------------------------
1529
+
1530
+ /** @type {ESLint.Plugin} */
1531
+ const eslintPluginPrettier = {
1532
+ meta: { name, version },
1533
+ configs: {
1534
+ recommended: {
1535
+ extends: ['prettier'],
1536
+ plugins: ['prettier'],
1537
+ rules: {
1538
+ 'prettier/prettier': 'error',
1539
+ 'arrow-body-style': 'off',
1540
+ 'prefer-arrow-callback': 'off',
1541
+ },
1542
+ },
1543
+ },
1544
+ rules: {
1545
+ prettier: {
1546
+ meta: {
1547
+ docs: {
1548
+ url: 'https://github.com/prettier/eslint-plugin-prettier#options',
1549
+ },
1550
+ type: 'layout',
1551
+ fixable: 'code',
1552
+ schema: [
1553
+ // Prettier options:
1554
+ {
1555
+ type: 'object',
1556
+ properties: {},
1557
+ additionalProperties: true,
1558
+ },
1559
+ {
1560
+ type: 'object',
1561
+ properties: {
1562
+ usePrettierrc: { type: 'boolean' },
1563
+ fileInfoOptions: {
1564
+ type: 'object',
1565
+ properties: {},
1566
+ additionalProperties: true,
1567
+ },
1568
+ },
1569
+ additionalProperties: true,
1570
+ },
1571
+ ],
1572
+ messages: {
1573
+ [INSERT]: 'Insert `{{ insertText }}`',
1574
+ [DELETE]: 'Delete `{{ deleteText }}`',
1575
+ [REPLACE]: 'Replace `{{ deleteText }}` with `{{ insertText }}`',
1576
+ },
1577
+ },
1578
+ create(context) {
1579
+ const options = /** @type {Options | undefined} */ (context.options[1]);
1580
+ const usePrettierrc = !options || options.usePrettierrc !== false;
1581
+ /** @type {FileInfoOptions} */
1582
+ const fileInfoOptions = options?.fileInfoOptions || {};
1583
+
1584
+ // `context.getSourceCode()` was deprecated in ESLint v8.40.0 and replaced
1585
+ // with the `sourceCode` property.
1586
+ // TODO: Only use property when our eslint peerDependency is >=8.40.0.
1587
+ const sourceCode = /** @type {SourceCode} */ (
1588
+ context.sourceCode ?? context.getSourceCode()
1589
+ );
1590
+ // `context.getFilename()` was deprecated in ESLint v8.40.0 and replaced
1591
+ // with the `filename` property.
1592
+ // TODO: Only use property when our eslint peerDependency is >=8.40.0.
1593
+ const filepath = context.filename ?? context.getFilename();
1594
+
1595
+ // Processors that extract content from a file, such as the markdown
1596
+ // plugin extracting fenced code blocks may choose to specify virtual
1597
+ // file paths. If this is the case then we need to resolve prettier
1598
+ // config and file info using the on-disk path instead of the virtual
1599
+ // path.
1600
+ // `context.getPhysicalFilename()` was deprecated in ESLint v8.40.0 and replaced
1601
+ // with the `physicalFilename` property.
1602
+ // TODO: Only use property when our eslint peerDependency is >=8.40.0.
1603
+ const onDiskFilepath =
1604
+ context.physicalFilename ?? context.getPhysicalFilename();
1605
+ const source = sourceCode.text;
1606
+
1607
+ return {
1608
+ /** @param {unknown} node */
1609
+ [sourceCode.ast.type](node) {
1610
+ if (!prettierFormat) {
1611
+ // Prettier is expensive to load, so only load it if needed.
1612
+ prettierFormat = /** @type {PrettierFormat} */ (
1613
+ requireLib().createSyncFn(require.resolve('./worker.mjs'))
1614
+ );
1615
+ }
1616
+
1617
+ /** @type {PrettierOptions} */
1618
+ const eslintPrettierOptions = context.options[0] || {};
1619
+
1620
+ const parser = /** @type {Linter.Parser | undefined} */ (
1621
+ context.languageOptions?.parser
1622
+ );
1623
+
1624
+ // prettier.format() may throw a SyntaxError if it cannot parse the
1625
+ // source code it is given. Usually for JS files this isn't a
1626
+ // problem as ESLint will report invalid syntax before trying to
1627
+ // pass it to the prettier plugin. However this might be a problem
1628
+ // for non-JS languages that are handled by a plugin. Notably Vue
1629
+ // files throw an error if they contain unclosed elements, such as
1630
+ // `<template><div></template>. In this case report an error at the
1631
+ // point at which parsing failed.
1632
+ /** @type {string} */
1633
+ let prettierSource;
1634
+ try {
1635
+ prettierSource = prettierFormat(
1636
+ source,
1637
+ {
1638
+ ...eslintPrettierOptions,
1639
+ filepath,
1640
+ onDiskFilepath,
1641
+ parserMeta:
1642
+ parser &&
1643
+ (parser.meta ?? {
1644
+ name: parser.name,
1645
+ version: parser.version,
1646
+ }),
1647
+ parserPath: context.parserPath,
1648
+ usePrettierrc,
1649
+ },
1650
+ fileInfoOptions,
1651
+ );
1652
+ } catch (err) {
1653
+ if (!(err instanceof SyntaxError)) {
1654
+ throw err;
1655
+ }
1656
+
1657
+ let message = 'Parsing error: ' + err.message;
1658
+
1659
+ const error = /**
1660
+ * @type {SyntaxError & {
1661
+ * codeFrame: string;
1662
+ * loc?: AST.SourceLocation;
1663
+ * }}
1664
+ */ (err);
1665
+
1666
+ // Prettier's message contains a codeframe style preview of the
1667
+ // invalid code and the line/column at which the error occurred.
1668
+ // ESLint shows those pieces of information elsewhere already so
1669
+ // remove them from the message
1670
+ if (error.codeFrame) {
1671
+ message = message.replace(`\n${error.codeFrame}`, '');
1672
+ }
1673
+ if (error.loc) {
1674
+ message = message.replace(/ \(\d+:\d+\)$/, '');
1675
+ context.report({ message, loc: error.loc });
1676
+ } else {
1677
+ context.report({ message, node });
1678
+ }
1679
+
1680
+ return;
1681
+ }
1682
+
1683
+ if (prettierSource == null) {
1684
+ return;
1685
+ }
1686
+
1687
+ if (source !== prettierSource) {
1688
+ const differences = generateDifferences(source, prettierSource);
1689
+
1690
+ for (const difference of differences) {
1691
+ reportDifference(
1692
+ /** @type {Rule.RuleContext} */ (context),
1693
+ difference,
1694
+ );
1695
+ }
1696
+ }
1697
+ },
1698
+ };
1699
+ },
1700
+ },
1701
+ },
1702
+ };
1703
+
1704
+ eslintPluginPrettier_1 = eslintPluginPrettier;
1705
+ return eslintPluginPrettier_1;
1706
+ }
1707
+
1708
+ var eslintPluginPrettierExports = requireEslintPluginPrettier();
1709
+ const eslintPluginPrettier = /*@__PURE__*/getDefaultExportFromCjs(eslintPluginPrettierExports);
1710
+
1711
+ const eslintPluginPrettier$1 = /*#__PURE__*/_mergeNamespaces({
1712
+ __proto__: null,
1713
+ default: eslintPluginPrettier
1714
+ }, [eslintPluginPrettierExports]);
1715
+
1716
+ export { eslintPluginPrettier$1 as e };