@uinaf/oxlint-plugin-no-comments 0.1.0 → 1.0.1
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/index.js +38 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -364,6 +364,8 @@ const declarationKinds = /* @__PURE__ */ new Set([
|
|
|
364
364
|
"TSTypeAliasDeclaration",
|
|
365
365
|
"VariableDeclaration"
|
|
366
366
|
]);
|
|
367
|
+
const scopeBoundaryKinds = /* @__PURE__ */ new Set(["BlockStatement", "StaticBlock"]);
|
|
368
|
+
const declarationFilePattern = /\.d\.[cm]?ts$/u;
|
|
367
369
|
const commentOwnerKinds = /* @__PURE__ */ new Set([
|
|
368
370
|
"ExpressionStatement",
|
|
369
371
|
"PropertyDefinition",
|
|
@@ -389,7 +391,8 @@ function buildMatchers(option) {
|
|
|
389
391
|
};
|
|
390
392
|
}
|
|
391
393
|
function commentText(comment) {
|
|
392
|
-
|
|
394
|
+
if (comment.type !== "Block") return comment.value.trim();
|
|
395
|
+
return comment.value.split("\n").map((line) => line.replace(/^\s*\**\s*/u, "")).join("\n").trim();
|
|
393
396
|
}
|
|
394
397
|
function isJSDoc(comment) {
|
|
395
398
|
return comment.type === "Block" && comment.value.startsWith("*");
|
|
@@ -405,20 +408,41 @@ function isPrivateMember(node) {
|
|
|
405
408
|
if ("accessibility" in node && node.accessibility === "private") return true;
|
|
406
409
|
return "key" in node && node.key.type === "PrivateIdentifier";
|
|
407
410
|
}
|
|
411
|
+
function boundNames(pattern) {
|
|
412
|
+
switch (pattern.type) {
|
|
413
|
+
case "Identifier": return [pattern.name];
|
|
414
|
+
case "ObjectPattern": return pattern.properties.flatMap((property) => boundNames(property.type === "RestElement" ? property.argument : property.value));
|
|
415
|
+
case "ArrayPattern": return pattern.elements.flatMap((element) => element === null ? [] : boundNames(element));
|
|
416
|
+
case "AssignmentPattern": return boundNames(pattern.left);
|
|
417
|
+
case "RestElement": return boundNames(pattern.argument);
|
|
418
|
+
default: return [];
|
|
419
|
+
}
|
|
420
|
+
}
|
|
408
421
|
function declaredNames(node) {
|
|
409
|
-
if (node.type === "VariableDeclaration") return node.declarations.flatMap((declarator) => declarator.id
|
|
422
|
+
if (node.type === "VariableDeclaration") return node.declarations.flatMap((declarator) => boundNames(declarator.id));
|
|
410
423
|
if ("id" in node && node.id !== null && node.id.type === "Identifier") return [node.id.name];
|
|
411
424
|
return [];
|
|
412
425
|
}
|
|
413
426
|
function lastJSDocBefore(sourceCode, node) {
|
|
414
427
|
return sourceCode.getCommentsBefore(node).findLast(isJSDoc);
|
|
415
428
|
}
|
|
416
|
-
function
|
|
429
|
+
function isAmbient(node, declarationFile) {
|
|
430
|
+
if (declarationFile) return true;
|
|
431
|
+
let current = node;
|
|
432
|
+
while (current !== null) {
|
|
433
|
+
if (current.type === "TSModuleDeclaration" && current.declare) return true;
|
|
434
|
+
current = current.parent;
|
|
435
|
+
}
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
function isPublicApi(member, api, declarationFile) {
|
|
439
|
+
if (isPrivateMember(member)) return false;
|
|
417
440
|
let previous = member;
|
|
418
441
|
let current = member.parent;
|
|
419
442
|
while (current !== null) {
|
|
420
443
|
if (api.has(current)) return true;
|
|
421
|
-
if (current.type
|
|
444
|
+
if (scopeBoundaryKinds.has(current.type) || isPrivateMember(current)) return false;
|
|
445
|
+
if (current.type === "TSModuleBlock" && !isAmbient(current, declarationFile)) return false;
|
|
422
446
|
if (current.type === "ArrowFunctionExpression" && current.body === previous) return false;
|
|
423
447
|
previous = current;
|
|
424
448
|
current = current.parent;
|
|
@@ -507,6 +531,13 @@ const plugin = eslintCompatPlugin({
|
|
|
507
531
|
apiNodes.add(node);
|
|
508
532
|
if (node.declaration.type === "Identifier") localExports.add(node.declaration.name);
|
|
509
533
|
},
|
|
534
|
+
TSExportAssignment(node) {
|
|
535
|
+
apiNodes.add(node);
|
|
536
|
+
if (node.expression.type === "Identifier") localExports.add(node.expression.name);
|
|
537
|
+
},
|
|
538
|
+
TSModuleBlock(node) {
|
|
539
|
+
for (const statement of node.body) if (declarationKinds.has(statement.type)) members.push(statement);
|
|
540
|
+
},
|
|
510
541
|
AccessorProperty: addMember,
|
|
511
542
|
MethodDefinition: addMember,
|
|
512
543
|
PropertyDefinition: addMember,
|
|
@@ -517,6 +548,7 @@ const plugin = eslintCompatPlugin({
|
|
|
517
548
|
TSConstructSignatureDeclaration: addMember,
|
|
518
549
|
TSEnumMember: addMember,
|
|
519
550
|
TSIndexSignature: addMember,
|
|
551
|
+
TSParameterProperty: addMember,
|
|
520
552
|
TSMethodSignature: addMember,
|
|
521
553
|
TSPropertySignature: addMember,
|
|
522
554
|
TSAsExpression: addAssertion,
|
|
@@ -536,8 +568,9 @@ const plugin = eslintCompatPlugin({
|
|
|
536
568
|
const doc = lastJSDocBefore(sourceCode, node);
|
|
537
569
|
if (doc !== void 0) allowed.add(doc.start);
|
|
538
570
|
}
|
|
571
|
+
const declarationFile = declarationFilePattern.test(context.filename);
|
|
539
572
|
for (const member of members) {
|
|
540
|
-
if (
|
|
573
|
+
if (!isPublicApi(member, apiNodes, declarationFile)) continue;
|
|
541
574
|
const doc = lastJSDocBefore(sourceCode, member);
|
|
542
575
|
if (doc !== void 0) allowed.add(doc.start);
|
|
543
576
|
}
|
package/package.json
CHANGED