@uinaf/oxlint-plugin-no-comments 0.1.0 → 1.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.
- package/dist/index.js +36 -4
- 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",
|
|
@@ -405,20 +407,41 @@ function isPrivateMember(node) {
|
|
|
405
407
|
if ("accessibility" in node && node.accessibility === "private") return true;
|
|
406
408
|
return "key" in node && node.key.type === "PrivateIdentifier";
|
|
407
409
|
}
|
|
410
|
+
function boundNames(pattern) {
|
|
411
|
+
switch (pattern.type) {
|
|
412
|
+
case "Identifier": return [pattern.name];
|
|
413
|
+
case "ObjectPattern": return pattern.properties.flatMap((property) => boundNames(property.type === "RestElement" ? property.argument : property.value));
|
|
414
|
+
case "ArrayPattern": return pattern.elements.flatMap((element) => element === null ? [] : boundNames(element));
|
|
415
|
+
case "AssignmentPattern": return boundNames(pattern.left);
|
|
416
|
+
case "RestElement": return boundNames(pattern.argument);
|
|
417
|
+
default: return [];
|
|
418
|
+
}
|
|
419
|
+
}
|
|
408
420
|
function declaredNames(node) {
|
|
409
|
-
if (node.type === "VariableDeclaration") return node.declarations.flatMap((declarator) => declarator.id
|
|
421
|
+
if (node.type === "VariableDeclaration") return node.declarations.flatMap((declarator) => boundNames(declarator.id));
|
|
410
422
|
if ("id" in node && node.id !== null && node.id.type === "Identifier") return [node.id.name];
|
|
411
423
|
return [];
|
|
412
424
|
}
|
|
413
425
|
function lastJSDocBefore(sourceCode, node) {
|
|
414
426
|
return sourceCode.getCommentsBefore(node).findLast(isJSDoc);
|
|
415
427
|
}
|
|
416
|
-
function
|
|
428
|
+
function isAmbient(node, declarationFile) {
|
|
429
|
+
if (declarationFile) return true;
|
|
430
|
+
let current = node;
|
|
431
|
+
while (current !== null) {
|
|
432
|
+
if (current.type === "TSModuleDeclaration" && current.declare) return true;
|
|
433
|
+
current = current.parent;
|
|
434
|
+
}
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
function isPublicApi(member, api, declarationFile) {
|
|
438
|
+
if (isPrivateMember(member)) return false;
|
|
417
439
|
let previous = member;
|
|
418
440
|
let current = member.parent;
|
|
419
441
|
while (current !== null) {
|
|
420
442
|
if (api.has(current)) return true;
|
|
421
|
-
if (current.type
|
|
443
|
+
if (scopeBoundaryKinds.has(current.type) || isPrivateMember(current)) return false;
|
|
444
|
+
if (current.type === "TSModuleBlock" && !isAmbient(current, declarationFile)) return false;
|
|
422
445
|
if (current.type === "ArrowFunctionExpression" && current.body === previous) return false;
|
|
423
446
|
previous = current;
|
|
424
447
|
current = current.parent;
|
|
@@ -507,6 +530,13 @@ const plugin = eslintCompatPlugin({
|
|
|
507
530
|
apiNodes.add(node);
|
|
508
531
|
if (node.declaration.type === "Identifier") localExports.add(node.declaration.name);
|
|
509
532
|
},
|
|
533
|
+
TSExportAssignment(node) {
|
|
534
|
+
apiNodes.add(node);
|
|
535
|
+
if (node.expression.type === "Identifier") localExports.add(node.expression.name);
|
|
536
|
+
},
|
|
537
|
+
TSModuleBlock(node) {
|
|
538
|
+
for (const statement of node.body) if (declarationKinds.has(statement.type)) members.push(statement);
|
|
539
|
+
},
|
|
510
540
|
AccessorProperty: addMember,
|
|
511
541
|
MethodDefinition: addMember,
|
|
512
542
|
PropertyDefinition: addMember,
|
|
@@ -517,6 +547,7 @@ const plugin = eslintCompatPlugin({
|
|
|
517
547
|
TSConstructSignatureDeclaration: addMember,
|
|
518
548
|
TSEnumMember: addMember,
|
|
519
549
|
TSIndexSignature: addMember,
|
|
550
|
+
TSParameterProperty: addMember,
|
|
520
551
|
TSMethodSignature: addMember,
|
|
521
552
|
TSPropertySignature: addMember,
|
|
522
553
|
TSAsExpression: addAssertion,
|
|
@@ -536,8 +567,9 @@ const plugin = eslintCompatPlugin({
|
|
|
536
567
|
const doc = lastJSDocBefore(sourceCode, node);
|
|
537
568
|
if (doc !== void 0) allowed.add(doc.start);
|
|
538
569
|
}
|
|
570
|
+
const declarationFile = declarationFilePattern.test(context.filename);
|
|
539
571
|
for (const member of members) {
|
|
540
|
-
if (
|
|
572
|
+
if (!isPublicApi(member, apiNodes, declarationFile)) continue;
|
|
541
573
|
const doc = lastJSDocBefore(sourceCode, member);
|
|
542
574
|
if (doc !== void 0) allowed.add(doc.start);
|
|
543
575
|
}
|
package/package.json
CHANGED