pickier 0.1.30 → 0.1.33

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.
package/dist/bin/cli.js CHANGED
@@ -296,6 +296,87 @@ function normalizeSpacingLine(line) {
296
296
  }
297
297
  return strings.length > 0 ? unmaskStrings(t, strings) : t;
298
298
  }
299
+ function inTemplateText(stack) {
300
+ const top = stack[stack.length - 1];
301
+ return top !== undefined && top.t === "tmpl";
302
+ }
303
+ function skipQuoted(line, i, quote) {
304
+ i++;
305
+ while (i < line.length) {
306
+ const c = line[i];
307
+ if (c === "\\") {
308
+ i += 2;
309
+ continue;
310
+ }
311
+ if (c === quote)
312
+ return i + 1;
313
+ i++;
314
+ }
315
+ return i;
316
+ }
317
+ function advanceTemplateState(line, stack) {
318
+ for (const ctx of stack) {
319
+ if (ctx.t === "tmpl")
320
+ ctx.start = -1;
321
+ }
322
+ let i = 0;
323
+ while (i < line.length) {
324
+ const top = stack[stack.length - 1];
325
+ const ch = line[i];
326
+ if (top === undefined || top.t === "interp") {
327
+ if (ch === "`") {
328
+ stack.push({ t: "tmpl", start: i });
329
+ i++;
330
+ continue;
331
+ }
332
+ if (ch === "'" || ch === '"') {
333
+ i = skipQuoted(line, i, ch);
334
+ continue;
335
+ }
336
+ if (ch === "/" && line[i + 1] === "/")
337
+ break;
338
+ if (top !== undefined) {
339
+ if (ch === "{") {
340
+ top.braces++;
341
+ i++;
342
+ continue;
343
+ }
344
+ if (ch === "}") {
345
+ if (top.braces === 0)
346
+ stack.pop();
347
+ else
348
+ top.braces--;
349
+ i++;
350
+ continue;
351
+ }
352
+ }
353
+ i++;
354
+ } else {
355
+ if (ch === "\\") {
356
+ i += 2;
357
+ continue;
358
+ }
359
+ if (ch === "`") {
360
+ stack.pop();
361
+ i++;
362
+ continue;
363
+ }
364
+ if (ch === "$" && line[i + 1] === "{") {
365
+ stack.push({ t: "interp", braces: 0 });
366
+ i += 2;
367
+ continue;
368
+ }
369
+ i++;
370
+ }
371
+ }
372
+ if (inTemplateText(stack)) {
373
+ for (const ctx of stack) {
374
+ if (ctx.t === "tmpl" && ctx.start >= 0)
375
+ return ctx.start;
376
+ }
377
+ }
378
+ return -1;
379
+ }
299
380
  function processCodeLinesFused(content, cfg) {
300
381
  const lines = content.split(`
301
382
  `);
@@ -304,8 +385,29 @@ function processCodeLinesFused(content, cfg) {
304
385
  const preferred = cfg.format.quotes;
305
386
  const doSemiRemoval = cfg.format.semi === true;
306
387
  let indentLevel = 0;
388
+ const tmplStack = [];
307
389
  for (let idx = 0;idx < len; idx++) {
308
390
  let line = lines[idx];
391
+ const protectedLine = inTemplateText(tmplStack);
392
+ let splitIdx = -1;
393
+ if (tmplStack.length > 0 || line.indexOf("`") !== -1)
394
+ splitIdx = advanceTemplateState(line, tmplStack);
395
+ if (protectedLine) {
396
+ result[idx] = line;
397
+ continue;
398
+ }
399
+ let tmplTail = "";
400
+ let prefixEndedWithSpace = false;
401
+ if (splitIdx >= 0) {
402
+ tmplTail = line.slice(splitIdx);
403
+ const prefix = line.slice(0, splitIdx);
404
+ if (prefix.length === 0) {
405
+ result[idx] = tmplTail;
406
+ continue;
407
+ }
408
+ prefixEndedWithSpace = RE_TRAILING_WS.test(prefix);
409
+ line = prefix;
410
+ }
309
411
  if (line.length === 0) {
310
412
  result[idx] = "";
311
413
  continue;
@@ -330,6 +432,11 @@ function processCodeLinesFused(content, cfg) {
330
432
  }
331
433
  }
332
434
  }
435
+ if (splitIdx >= 0) {
436
+ if (prefixEndedWithSpace && !RE_TRAILING_WS.test(line))
437
+ line += " ";
438
+ line += tmplTail;
439
+ }
333
440
  result[idx] = line;
334
441
  }
335
442
  return result.join(`
@@ -338,7 +445,16 @@ function processCodeLinesFused(content, cfg) {
338
445
  function collapseBlankLines(lines, maxConsecutive) {
339
446
  const out = [];
340
447
  let blank = 0;
448
+ const stack = [];
341
449
  for (const l of lines) {
450
+ const protectedLine = inTemplateText(stack);
451
+ if (stack.length > 0 || l.indexOf("`") !== -1)
452
+ advanceTemplateState(l, stack);
453
+ if (protectedLine) {
454
+ out.push(l);
455
+ blank = 0;
456
+ continue;
457
+ }
342
458
  if (l === "") {
343
459
  blank++;
344
460
  if (blank <= maxConsecutive)
@@ -362,7 +478,17 @@ function formatCode(src, cfg, filePath) {
362
478
  lines = [];
363
479
  let blank = 0;
364
480
  const maxConsecutive = Math.max(0, cfg.format.maxConsecutiveBlankLines);
481
+ const stack = [];
365
482
  for (const l of rawLines) {
483
+ const protectedLine = inTemplateText(stack);
484
+ let endsInTemplate = false;
485
+ if (stack.length > 0 || l.indexOf("`") !== -1)
486
+ endsInTemplate = advanceTemplateState(l, stack) >= 0;
487
+ if (protectedLine || endsInTemplate) {
488
+ lines.push(l);
489
+ blank = 0;
490
+ continue;
491
+ }
366
492
  const last = l[l.length - 1];
367
493
  const trimmed = last === " " || last === "\t" ? l.replace(RE_TRAILING_WS, "") : l;
368
494
  if (trimmed === "") {
@@ -21246,6 +21372,27 @@ var init_no_unused_vars = __esm(() => {
21246
21372
  continue;
21247
21373
  }
21248
21374
  if (inTmplExpr) {
21375
+ if (ch === "/") {
21376
+ const before = lineToProcess.slice(0, k).trimEnd();
21377
+ const regexPrecedeRe = /[=([{,:;!&|?]$/;
21378
+ if (!before || regexPrecedeRe.test(before) || before.endsWith("return")) {
21379
+ k++;
21380
+ while (k < lineToProcess.length) {
21381
+ if (lineToProcess[k] === "\\") {
21382
+ k += 2;
21383
+ continue;
21384
+ }
21385
+ if (lineToProcess[k] === "/") {
21386
+ while (k + 1 < lineToProcess.length && /[gimsuvy]/.test(lineToProcess[k + 1])) {
21387
+ k++;
21388
+ }
21389
+ break;
21390
+ }
21391
+ k++;
21392
+ }
21393
+ continue;
21394
+ }
21395
+ }
21249
21396
  if (ch === "`") {
21250
21397
  depthTmplStack.push(-1);
21251
21398
  continue;
@@ -40024,11 +40171,9 @@ class Command {
40024
40171
  isMatched(name) {
40025
40172
  if (this.aliasNames.includes(name))
40026
40173
  return true;
40027
- if (this.name === name)
40028
- return true;
40029
- if (this.namespace && `${this.namespace}:${this.name}` === name)
40030
- return true;
40031
- return false;
40174
+ if (this.namespace)
40175
+ return `${this.namespace}:${this.name}` === name;
40176
+ return this.name === name;
40032
40177
  }
40033
40178
  get isDefaultCommand() {
40034
40179
  return this.name === "" || this.aliasNames.includes("!");
@@ -40036,6 +40181,9 @@ class Command {
40036
40181
  get isGlobalCommand() {
40037
40182
  return this instanceof GlobalCommand;
40038
40183
  }
40184
+ get displayName() {
40185
+ return this.namespace ? `${this.namespace}:${this.name}` : this.name;
40186
+ }
40039
40187
  hasOption(name) {
40040
40188
  name = name.split(".")[0];
40041
40189
  return !!this.options.find((option) => {
@@ -40101,7 +40249,7 @@ class Command {
40101
40249
  });
40102
40250
  sections.push({
40103
40251
  title: `For more info, run any command with the \`--help\` flag`,
40104
- body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join(`
40252
+ body: commands.map((command) => ` $ ${name}${command.displayName === "" ? "" : ` ${command.displayName}`} --help`).join(`
40105
40253
  `)
40106
40254
  });
40107
40255
  }
@@ -42573,8 +42721,8 @@ Received ${signal}, cleaning up...`);
42573
42721
  if (this.enableDidYouMean) {
42574
42722
  const allCommandNames = [];
42575
42723
  for (const command of this.commands) {
42576
- if (command.name) {
42577
- allCommandNames.push(command.name);
42724
+ if (command.displayName) {
42725
+ allCommandNames.push(command.displayName);
42578
42726
  }
42579
42727
  if (command.aliasNames) {
42580
42728
  allCommandNames.push(...command.aliasNames);
@@ -43079,7 +43227,7 @@ Run \`${this.name ?? "cli"} --help\` for usage.`;
43079
43227
  this.value = [];
43080
43228
  }
43081
43229
  if (item.group === true) {
43082
- const group = item.value;
43230
+ const group = String(item.value);
43083
43231
  const groupedItems = this.getGroupItems(group);
43084
43232
  if (this.isGroupSelected(group)) {
43085
43233
  this.value = this.value.filter((v) => groupedItems.findIndex((i) => i.value === v) === -1);
@@ -43499,7 +43647,7 @@ var require_package = __commonJS((exports, module) => {
43499
43647
  module.exports = {
43500
43648
  name: "pickier",
43501
43649
  type: "module",
43502
- version: "0.1.30",
43650
+ version: "0.1.33",
43503
43651
  description: "Format, lint and more in a fraction of seconds.",
43504
43652
  author: "Chris Breuer <chris@stacksjs.org>",
43505
43653
  license: "MIT",
package/dist/format.d.ts CHANGED
@@ -3,4 +3,16 @@ export declare function formatCode(src: string, cfg: PickierConfig, filePath: st
3
3
  export declare function detectQuoteIssues(line: string, preferred: 'single' | 'double'): number[];
4
4
  export declare function hasIndentIssue(leading: string, indentSize: number, indentStyle?: 'spaces' | 'tabs', lineContent?: string): boolean;
5
5
  export declare function formatImports(source: string): string;
6
+ // ── Multi-line template-literal tracking ──────────────────────────────────
7
+ // The line-based formatter must never touch the *contents* of a template
8
+ // literal (re-indenting, re-spacing `${` → `$ {`, re-quoting, or trimming would
9
+ // corrupt the string and break interpolation). These helpers track, line by
10
+ // line, whether we are inside a template literal's text so such lines can be
11
+ // emitted verbatim. The scan degrades safely: on exotic input it can only ever
12
+ // under-format (skip a line), never corrupt one.
13
+ // `start` records the index of the backtick that opened the template, but only
14
+ // while scanning the line on which it opened (carried-over contexts from earlier
15
+ // lines are reset to -1 on entry). It lets callers split an opening line into a
16
+ // formattable code prefix and a verbatim template tail.
17
+ declare type TmplCtx = { t: 'tmpl', start: number } | { t: 'interp', braces: number }
6
18
  declare type ImportKind = 'value' | 'type' | 'side-effect';
package/dist/src/index.js CHANGED
@@ -9130,6 +9130,87 @@ function normalizeSpacingLine(line) {
9130
9130
  }
9131
9131
  return strings.length > 0 ? unmaskStrings(t, strings) : t;
9132
9132
  }
9133
+ function inTemplateText(stack) {
9134
+ const top = stack[stack.length - 1];
9135
+ return top !== undefined && top.t === "tmpl";
9136
+ }
9137
+ function skipQuoted(line, i, quote) {
9138
+ i++;
9139
+ while (i < line.length) {
9140
+ const c = line[i];
9141
+ if (c === "\\") {
9142
+ i += 2;
9143
+ continue;
9144
+ }
9145
+ if (c === quote)
9146
+ return i + 1;
9147
+ i++;
9148
+ }
9149
+ return i;
9150
+ }
9151
+ function advanceTemplateState(line, stack) {
9152
+ for (const ctx of stack) {
9153
+ if (ctx.t === "tmpl")
9154
+ ctx.start = -1;
9155
+ }
9156
+ let i = 0;
9157
+ while (i < line.length) {
9158
+ const top = stack[stack.length - 1];
9159
+ const ch = line[i];
9160
+ if (top === undefined || top.t === "interp") {
9161
+ if (ch === "`") {
9162
+ stack.push({ t: "tmpl", start: i });
9163
+ i++;
9164
+ continue;
9165
+ }
9166
+ if (ch === "'" || ch === '"') {
9167
+ i = skipQuoted(line, i, ch);
9168
+ continue;
9169
+ }
9170
+ if (ch === "/" && line[i + 1] === "/")
9171
+ break;
9172
+ if (top !== undefined) {
9173
+ if (ch === "{") {
9174
+ top.braces++;
9175
+ i++;
9176
+ continue;
9177
+ }
9178
+ if (ch === "}") {
9179
+ if (top.braces === 0)
9180
+ stack.pop();
9181
+ else
9182
+ top.braces--;
9183
+ i++;
9184
+ continue;
9185
+ }
9186
+ }
9187
+ i++;
9188
+ } else {
9189
+ if (ch === "\\") {
9190
+ i += 2;
9191
+ continue;
9192
+ }
9193
+ if (ch === "`") {
9194
+ stack.pop();
9195
+ i++;
9196
+ continue;
9197
+ }
9198
+ if (ch === "$" && line[i + 1] === "{") {
9199
+ stack.push({ t: "interp", braces: 0 });
9200
+ i += 2;
9201
+ continue;
9202
+ }
9203
+ i++;
9204
+ }
9205
+ }
9206
+ if (inTemplateText(stack)) {
9207
+ for (const ctx of stack) {
9208
+ if (ctx.t === "tmpl" && ctx.start >= 0)
9209
+ return ctx.start;
9210
+ }
9211
+ }
9212
+ return -1;
9213
+ }
9133
9214
  function processCodeLinesFused(content, cfg) {
9134
9215
  const lines = content.split(`
9135
9216
  `);
@@ -9138,8 +9219,29 @@ function processCodeLinesFused(content, cfg) {
9138
9219
  const preferred = cfg.format.quotes;
9139
9220
  const doSemiRemoval = cfg.format.semi === true;
9140
9221
  let indentLevel = 0;
9222
+ const tmplStack = [];
9141
9223
  for (let idx = 0;idx < len; idx++) {
9142
9224
  let line = lines[idx];
9225
+ const protectedLine = inTemplateText(tmplStack);
9226
+ let splitIdx = -1;
9227
+ if (tmplStack.length > 0 || line.indexOf("`") !== -1)
9228
+ splitIdx = advanceTemplateState(line, tmplStack);
9229
+ if (protectedLine) {
9230
+ result[idx] = line;
9231
+ continue;
9232
+ }
9233
+ let tmplTail = "";
9234
+ let prefixEndedWithSpace = false;
9235
+ if (splitIdx >= 0) {
9236
+ tmplTail = line.slice(splitIdx);
9237
+ const prefix = line.slice(0, splitIdx);
9238
+ if (prefix.length === 0) {
9239
+ result[idx] = tmplTail;
9240
+ continue;
9241
+ }
9242
+ prefixEndedWithSpace = RE_TRAILING_WS.test(prefix);
9243
+ line = prefix;
9244
+ }
9143
9245
  if (line.length === 0) {
9144
9246
  result[idx] = "";
9145
9247
  continue;
@@ -9164,6 +9266,11 @@ function processCodeLinesFused(content, cfg) {
9164
9266
  }
9165
9267
  }
9166
9268
  }
9269
+ if (splitIdx >= 0) {
9270
+ if (prefixEndedWithSpace && !RE_TRAILING_WS.test(line))
9271
+ line += " ";
9272
+ line += tmplTail;
9273
+ }
9167
9274
  result[idx] = line;
9168
9275
  }
9169
9276
  return result.join(`
@@ -9172,7 +9279,16 @@ function processCodeLinesFused(content, cfg) {
9172
9279
  function collapseBlankLines(lines, maxConsecutive) {
9173
9280
  const out = [];
9174
9281
  let blank = 0;
9282
+ const stack = [];
9175
9283
  for (const l of lines) {
9284
+ const protectedLine = inTemplateText(stack);
9285
+ if (stack.length > 0 || l.indexOf("`") !== -1)
9286
+ advanceTemplateState(l, stack);
9287
+ if (protectedLine) {
9288
+ out.push(l);
9289
+ blank = 0;
9290
+ continue;
9291
+ }
9176
9292
  if (l === "") {
9177
9293
  blank++;
9178
9294
  if (blank <= maxConsecutive)
@@ -9196,7 +9312,17 @@ function formatCode(src, cfg, filePath) {
9196
9312
  lines = [];
9197
9313
  let blank = 0;
9198
9314
  const maxConsecutive = Math.max(0, cfg.format.maxConsecutiveBlankLines);
9315
+ const stack = [];
9199
9316
  for (const l of rawLines) {
9317
+ const protectedLine = inTemplateText(stack);
9318
+ let endsInTemplate = false;
9319
+ if (stack.length > 0 || l.indexOf("`") !== -1)
9320
+ endsInTemplate = advanceTemplateState(l, stack) >= 0;
9321
+ if (protectedLine || endsInTemplate) {
9322
+ lines.push(l);
9323
+ blank = 0;
9324
+ continue;
9325
+ }
9200
9326
  const last = l[l.length - 1];
9201
9327
  const trimmed = last === " " || last === "\t" ? l.replace(RE_TRAILING_WS, "") : l;
9202
9328
  if (trimmed === "") {
@@ -20844,6 +20970,27 @@ var init_no_unused_vars = __esm(() => {
20844
20970
  continue;
20845
20971
  }
20846
20972
  if (inTmplExpr) {
20973
+ if (ch === "/") {
20974
+ const before = lineToProcess.slice(0, k).trimEnd();
20975
+ const regexPrecedeRe = /[=([{,:;!&|?]$/;
20976
+ if (!before || regexPrecedeRe.test(before) || before.endsWith("return")) {
20977
+ k++;
20978
+ while (k < lineToProcess.length) {
20979
+ if (lineToProcess[k] === "\\") {
20980
+ k += 2;
20981
+ continue;
20982
+ }
20983
+ if (lineToProcess[k] === "/") {
20984
+ while (k + 1 < lineToProcess.length && /[gimsuvy]/.test(lineToProcess[k + 1])) {
20985
+ k++;
20986
+ }
20987
+ break;
20988
+ }
20989
+ k++;
20990
+ }
20991
+ continue;
20992
+ }
20993
+ }
20847
20994
  if (ch === "`") {
20848
20995
  depthTmplStack.push(-1);
20849
20996
  continue;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pickier",
3
3
  "type": "module",
4
- "version": "0.1.30",
4
+ "version": "0.1.33",
5
5
  "description": "Format, lint and more in a fraction of seconds.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- # MIT License
2
-
3
- Copyright (c) 2024 Open Web Foundation
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.