pickier 0.1.32 → 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 +137 -10
- package/dist/format.d.ts +12 -0
- package/dist/src/index.js +126 -0
- package/package.json +1 -1
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 === "") {
|
|
@@ -40045,11 +40171,9 @@ class Command {
|
|
|
40045
40171
|
isMatched(name) {
|
|
40046
40172
|
if (this.aliasNames.includes(name))
|
|
40047
40173
|
return true;
|
|
40048
|
-
if (this.
|
|
40049
|
-
return
|
|
40050
|
-
|
|
40051
|
-
return true;
|
|
40052
|
-
return false;
|
|
40174
|
+
if (this.namespace)
|
|
40175
|
+
return `${this.namespace}:${this.name}` === name;
|
|
40176
|
+
return this.name === name;
|
|
40053
40177
|
}
|
|
40054
40178
|
get isDefaultCommand() {
|
|
40055
40179
|
return this.name === "" || this.aliasNames.includes("!");
|
|
@@ -40057,6 +40181,9 @@ class Command {
|
|
|
40057
40181
|
get isGlobalCommand() {
|
|
40058
40182
|
return this instanceof GlobalCommand;
|
|
40059
40183
|
}
|
|
40184
|
+
get displayName() {
|
|
40185
|
+
return this.namespace ? `${this.namespace}:${this.name}` : this.name;
|
|
40186
|
+
}
|
|
40060
40187
|
hasOption(name) {
|
|
40061
40188
|
name = name.split(".")[0];
|
|
40062
40189
|
return !!this.options.find((option) => {
|
|
@@ -40122,7 +40249,7 @@ class Command {
|
|
|
40122
40249
|
});
|
|
40123
40250
|
sections.push({
|
|
40124
40251
|
title: `For more info, run any command with the \`--help\` flag`,
|
|
40125
|
-
body: commands.map((command) => ` $ ${name}${command.
|
|
40252
|
+
body: commands.map((command) => ` $ ${name}${command.displayName === "" ? "" : ` ${command.displayName}`} --help`).join(`
|
|
40126
40253
|
`)
|
|
40127
40254
|
});
|
|
40128
40255
|
}
|
|
@@ -42594,8 +42721,8 @@ Received ${signal}, cleaning up...`);
|
|
|
42594
42721
|
if (this.enableDidYouMean) {
|
|
42595
42722
|
const allCommandNames = [];
|
|
42596
42723
|
for (const command of this.commands) {
|
|
42597
|
-
if (command.
|
|
42598
|
-
allCommandNames.push(command.
|
|
42724
|
+
if (command.displayName) {
|
|
42725
|
+
allCommandNames.push(command.displayName);
|
|
42599
42726
|
}
|
|
42600
42727
|
if (command.aliasNames) {
|
|
42601
42728
|
allCommandNames.push(...command.aliasNames);
|
|
@@ -43100,7 +43227,7 @@ Run \`${this.name ?? "cli"} --help\` for usage.`;
|
|
|
43100
43227
|
this.value = [];
|
|
43101
43228
|
}
|
|
43102
43229
|
if (item.group === true) {
|
|
43103
|
-
const group = item.value;
|
|
43230
|
+
const group = String(item.value);
|
|
43104
43231
|
const groupedItems = this.getGroupItems(group);
|
|
43105
43232
|
if (this.isGroupSelected(group)) {
|
|
43106
43233
|
this.value = this.value.filter((v) => groupedItems.findIndex((i) => i.value === v) === -1);
|
|
@@ -43520,7 +43647,7 @@ var require_package = __commonJS((exports, module) => {
|
|
|
43520
43647
|
module.exports = {
|
|
43521
43648
|
name: "pickier",
|
|
43522
43649
|
type: "module",
|
|
43523
|
-
version: "0.1.
|
|
43650
|
+
version: "0.1.33",
|
|
43524
43651
|
description: "Format, lint and more in a fraction of seconds.",
|
|
43525
43652
|
author: "Chris Breuer <chris@stacksjs.org>",
|
|
43526
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 === "") {
|