@uinaf/oxlint-plugin-no-comments 1.1.0 → 1.1.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/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ ![oxlint-plugin-no-comments — Oxlint rule that bans code comments.](https://uinaf.dev/og/banner/oxlint-plugin-no-comments.png)
2
+
1
3
  # @uinaf/oxlint-plugin-no-comments
2
4
 
3
5
  An Oxlint rule that bans code comments. Names, types, and tests carry intent;
@@ -44,7 +46,7 @@ lint: {
44
46
  | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
45
47
  | Tool directives | `eslint-disable*`, `eslint-enable*`, `oxlint-disable*`, `oxlint-enable*`, `@ts-expect-error`, `@ts-ignore`, `@ts-nocheck`, `@ts-check`, `/// <reference …>`, `prettier-ignore`, `istanbul`/`c8`/`v8 ignore`, `node:coverage`, `@__PURE__`, `@__NO_SIDE_EFFECTS__`, `@vite-ignore`, `@vitest-environment` |
46
48
  | License headers | `/*! … */`, `@license`, or `SPDX-*` before the first statement |
47
- | API docs | The last JSDoc block before a declaration TypeScript exports, or before a public member of an exported class, interface, type, or enum. This counts implicit exports in `.d.ts` files, `declare module`, and `declare global` |
49
+ | API docs | The last JSDoc block before a declaration TypeScript exports, or before a public member of an exported class, interface, type, enum, or object literal. This counts implicit exports in `.d.ts` files, `declare module`, and `declare global` |
48
50
  | Lint-required | `SAFETY:` comments that anti-slop's `require-safety-comment-for-type-assertion` accepts for a non-`const` type assertion |
49
51
 
50
52
  Everything else is reported, including `TODO`, JSX comments, JSDoc on
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // node_modules/.pnpm/@oxlint+plugins@1.90.0/node_modules/@oxlint/plugins/index.js
1
+ // node_modules/.pnpm/@oxlint+plugins@1.94.0/node_modules/@oxlint/plugins/index.js
2
2
  /**
3
3
  * Define a rule.
4
4
  *
@@ -366,6 +366,11 @@ const declarationKinds = /* @__PURE__ */ new Set([
366
366
  ]);
367
367
  const scopeBoundaryKinds = /* @__PURE__ */ new Set(["BlockStatement", "StaticBlock"]);
368
368
  const declarationFilePattern = /\.d\.[cm]?ts$/u;
369
+ const objectLiteralPathKinds = /* @__PURE__ */ new Set([
370
+ "ObjectExpression",
371
+ "Property",
372
+ "TSSatisfiesExpression"
373
+ ]);
369
374
  const commentOwnerKinds = /* @__PURE__ */ new Set([
370
375
  "ExpressionStatement",
371
376
  "PropertyDefinition",
@@ -445,7 +450,7 @@ function rootIdentifier(node) {
445
450
  function hasExportDeclarations(statements) {
446
451
  return statements.some((statement) => statement.type === "ExportNamedDeclaration" && statement.declaration === null || statement.type === "ExportAllDeclaration" || statement.type === "TSExportAssignment" || statement.type === "ExportDefaultDeclaration" && !declarationKinds.has(statement.declaration.type));
447
452
  }
448
- function collectApi(statements, visible, ambient, api) {
453
+ function collectApi(statements, visible, ambient, api, declarators) {
449
454
  const listed = localExportNames(statements);
450
455
  const exportContext = ambient && !hasExportDeclarations(statements);
451
456
  for (const statement of statements) {
@@ -462,21 +467,26 @@ function collectApi(statements, visible, ambient, api) {
462
467
  }
463
468
  const exported = explicit || visible && implicit;
464
469
  if (exported) api.add(statement);
470
+ if (exported && declaration?.type === "VariableDeclaration") {
471
+ const all = explicit || exportContext;
472
+ for (const declarator of declaration.declarations) if (all || boundNames(declarator.id).some((name) => listed.has(name))) declarators.add(declarator);
473
+ }
465
474
  if (declaration?.type !== "TSModuleDeclaration" || declaration.body?.type !== "TSModuleBlock") continue;
466
475
  const external = declaration.global || declaration.id.type === "Literal";
467
- collectApi(declaration.body.body, external || visible && exported, ambient || declaration.declare, api);
476
+ collectApi(declaration.body.body, external || visible && exported, ambient || declaration.declare, api, declarators);
468
477
  }
469
478
  }
470
479
  function lastJSDocBefore(sourceCode, node) {
471
480
  return sourceCode.getCommentsBefore(node).findLast(isJSDoc);
472
481
  }
473
- function isPublicApi(member, api) {
482
+ function isPublicApi(member, api, declarators) {
474
483
  if (isPrivateMember(member)) return false;
475
484
  let previous = member;
476
485
  let current = member.parent;
477
486
  while (current !== null) {
478
487
  if (api.has(current)) return true;
479
488
  if (scopeBoundaryKinds.has(current.type) || isPrivateMember(current)) return false;
489
+ if (current.type === "VariableDeclarator" && !declarators.has(current)) return false;
480
490
  if (current.type === "TSModuleBlock") return false;
481
491
  if (current.type === "ArrowFunctionExpression" && current.body === previous) return false;
482
492
  previous = current;
@@ -484,6 +494,16 @@ function isPublicApi(member, api) {
484
494
  }
485
495
  return false;
486
496
  }
497
+ function isExportedObjectProperty(property, api, declarators) {
498
+ let current = property.parent;
499
+ while (current !== null) {
500
+ if (api.has(current)) return true;
501
+ if (current.type === "VariableDeclarator") return declarators.has(current);
502
+ if (!(objectLiteralPathKinds.has(current.type) || current.type === "TSAsExpression" && isConstAssertion(current))) return false;
503
+ current = current.parent;
504
+ }
505
+ return false;
506
+ }
487
507
  function safetyCommentsFor(sourceCode, assertion, pattern) {
488
508
  const found = [];
489
509
  const collect = (owner) => {
@@ -688,6 +708,7 @@ const plugin = eslintCompatPlugin({
688
708
  createOnce(context) {
689
709
  const matchersByOption = /* @__PURE__ */ new Map();
690
710
  const members = [];
711
+ const properties = [];
691
712
  const assertions = [];
692
713
  const emptyContainers = [];
693
714
  const addMember = (node) => {
@@ -699,12 +720,16 @@ const plugin = eslintCompatPlugin({
699
720
  return {
700
721
  before() {
701
722
  members.length = 0;
723
+ properties.length = 0;
702
724
  assertions.length = 0;
703
725
  emptyContainers.length = 0;
704
726
  },
705
727
  JSXExpressionContainer(node) {
706
728
  if (node.expression.type === "JSXEmptyExpression") emptyContainers.push(node);
707
729
  },
730
+ Property(node) {
731
+ properties.push(node);
732
+ },
708
733
  AccessorProperty: addMember,
709
734
  MethodDefinition: addMember,
710
735
  PropertyDefinition: addMember,
@@ -727,18 +752,24 @@ const plugin = eslintCompatPlugin({
727
752
  const matchers = matchersByOption.get(optionKey) ?? buildMatchers(option);
728
753
  matchersByOption.set(optionKey, matchers);
729
754
  const apiNodes = /* @__PURE__ */ new Set();
755
+ const exportedDeclarators = /* @__PURE__ */ new Set();
730
756
  const declarationFile = declarationFilePattern.test(context.filename);
731
- collectApi(program.body, true, declarationFile, apiNodes);
757
+ collectApi(program.body, true, declarationFile, apiNodes, exportedDeclarators);
732
758
  const allowed = /* @__PURE__ */ new Set();
733
759
  for (const node of apiNodes) {
734
760
  const doc = lastJSDocBefore(sourceCode, node);
735
761
  if (doc !== void 0) allowed.add(doc.start);
736
762
  }
737
763
  for (const member of members) {
738
- if (!isPublicApi(member, apiNodes)) continue;
764
+ if (!isPublicApi(member, apiNodes, exportedDeclarators)) continue;
739
765
  const doc = lastJSDocBefore(sourceCode, member);
740
766
  if (doc !== void 0) allowed.add(doc.start);
741
767
  }
768
+ for (const property of properties) {
769
+ if (!isExportedObjectProperty(property, apiNodes, exportedDeclarators)) continue;
770
+ const doc = lastJSDocBefore(sourceCode, property);
771
+ if (doc !== void 0) allowed.add(doc.start);
772
+ }
742
773
  for (const assertion of assertions) for (const comment of safetyCommentsFor(sourceCode, assertion, matchers.safety)) allowed.add(comment.start);
743
774
  const headerEnd = program.body[0]?.start ?? program.end;
744
775
  const comments = sourceCode.getAllComments();
@@ -752,10 +783,14 @@ const plugin = eslintCompatPlugin({
752
783
  const edits = planEdits(sourceCode.text, comments, reported, emptyContainers);
753
784
  for (const comment of reported) {
754
785
  const edit = edits.get(comment);
755
- context.report({
786
+ if (edit === void 0) context.report({
787
+ node: comment,
788
+ messageId: "comment"
789
+ });
790
+ else context.report({
756
791
  node: comment,
757
792
  messageId: "comment",
758
- ...edit === void 0 ? {} : { fix: (fixer) => fixer.replaceTextRange([edit.start, edit.end], edit.text) }
793
+ fix: (fixer) => fixer.replaceTextRange([edit.start, edit.end], edit.text)
759
794
  });
760
795
  }
761
796
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uinaf/oxlint-plugin-no-comments",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Oxlint rule that bans code comments, except tool directives, license headers, API docs, and SAFETY justifications",
5
5
  "keywords": [
6
6
  "comments",
@@ -36,9 +36,10 @@
36
36
  "prepublishOnly": "pnpm run verify:full"
37
37
  },
38
38
  "devDependencies": {
39
- "@oxlint/plugins": "1.90.0",
39
+ "@oxlint/plugins": "1.94.0",
40
40
  "@types/node": "^26.6.6",
41
- "oxlint": "1.90.0",
41
+ "@uinaf/oxlint-config": "1.0.0",
42
+ "oxlint": "1.94.0",
42
43
  "vite": "catalog:",
43
44
  "vite-plus": "catalog:"
44
45
  },
@@ -52,5 +53,5 @@
52
53
  "engines": {
53
54
  "node": ">=20.19.0"
54
55
  },
55
- "packageManager": "pnpm@12.18.0"
56
+ "packageManager": "pnpm@12.23.0"
56
57
  }