@soujvnunes/eslint-config 0.9.0 → 0.10.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/README.md CHANGED
@@ -41,10 +41,10 @@ export default createBaseConfig()
41
41
 
42
42
  | Option | Default | Purpose |
43
43
  | --- | --- | --- |
44
- | `importGroups` | react, next, module, parent, sibling, index | Full import-order groups; insert your `@/...` paths |
44
+ | `importGroups` | react, next, module, parent, sibling, index | Full import-order groups, which replace the default list; insert your `@/...` paths |
45
45
  | `ignores` | (none) | Extra ignore globs, merged after the built-in defaults |
46
46
  | `tsconfigRootDir` | `process.cwd()` | Root for typescript-eslint's project service |
47
- | `tailwindEntryPoint` | (none) | Tailwind v4 CSS entry path. When set on the Next preset, wires `eslint-plugin-better-tailwindcss` correctness rules such as `no-unknown-classes`, which flags a class not registered in the theme, and `no-restricted-classes`, which flags an arbitrary-value class such as `text-[11px]`. The stylistic rules stay off, since `prettier-plugin-tailwindcss` already owns class order |
47
+ | `tailwindEntryPoint` | (none) | Tailwind v4 CSS entry path: the file holding `@import "tailwindcss"` and `@theme`, such as `./app/tailwind.config.css`. When set on the Next preset, wires `eslint-plugin-better-tailwindcss` correctness rules such as `no-unknown-classes`, which flags a class not registered in the theme (a dead token neither `tsc` nor the build sees), and `no-restricted-classes`, which flags an arbitrary-value class such as `text-[11px]`. Left unset, the plugin stays off, since without the entry `no-unknown-classes` cannot resolve the theme and would flag every class. The stylistic rules stay off, since `prettier-plugin-tailwindcss` already owns class order |
48
48
  | `allowArbitraryClasses` | `[]` | Utility prefixes exempt from the arbitrary-Tailwind-value ban, for a shape with no theme token (`['grid-cols']` for `grid-cols-[200px_1fr]`). Read only when `tailwindEntryPoint` is set |
49
49
  | `classMergeName` | `'cn'` | The class-merge helper name a ternary passed straight to it is banned inside of |
50
50
  | `nextConfigModules` | `[]` | Modules `next.config.*` loads, restricted to relative imports (`no-restricted-imports` on `['@/*']`) the same as a `next.config.ts`, `.mts` or `.cts` itself, on the Next preset |
@@ -69,7 +69,7 @@ These are the opinions most likely to surprise an existing codebase. All of them
69
69
 
70
70
  **No warning severity.** Every rule either fails or is not present. A deliberate exception is an `eslint-disable` comment rather than a warning, and `reportUnusedDisableDirectives` is on, so a disable comment that suppresses nothing is itself an error.
71
71
 
72
- **No comments in code: `soujvnunes/no-comments`.** It reports every comment in a JS or TS file except two kinds. A tool directive that does work stays, matched by name: `eslint-disable`, `@ts-expect-error`, `@ts-ignore`, `@ts-nocheck`, `@ts-check`, `prettier-ignore`, `biome-ignore`, a coverage pragma (`istanbul`, `c8`, `v8`, `node:coverage`), a minifier annotation (`@__PURE__`, `#__NO_SIDE_EFFECTS__` and the rest of the `__NAME__` family), a `webpack` or `turbopack` magic comment, `@vite-ignore`, `//# sourceMappingURL`, a triple-slash reference, `/* global */`, `@jsx` with its `Frag`, `ImportSource` and `Runtime` forms, `@vitest-environment`, `@jest-environment`, `@refresh reset`, `@license`, `@preserve`, `@format`, `@prettier`, `@internal` standing alone (read by TypeScript's `stripInternal`; with prose after it, it is a JSDoc like any other), `gitleaks:allow` anywhere in a one-line comment that shares its line with code, before it or after it (gitleaks reads it only on the line of the finding), the `/*!` banner and the `#!` line. Any other comment that opens with `@` or `#`, such as `// @todo`, is prose and reports. In a `.js`, `.mjs`, `.cjs` or `.jsx` file a JSDoc whose first tag is a type annotation `checkJs` reads (`@type`, `@typedef`, `@callback`, `@satisfies`, `@template`, `@param`, `@returns`, `@import`, `@enum`, `@extends`, `@augments`, `@implements`, `@this`, `@overload`) and carries the type the tag takes (a `{Type}` after `@type`, `@param`, `@returns`, `@return`, `@satisfies`, `@enum` and `@this`; a `{Type}` or a name that ends its line after `@typedef` and `@callback`; a `{constraint}` or a comma list of names that ends its line after `@template`; a `{Type}` or a type that ends its line after `@extends`, `@augments` and `@implements`; an `import` clause with its `from` after `@import`; a typed `@param` or `@returns` later in the same comment after `@overload`), stays as well, wherever it sits, since deleting it removes the type check. A JSDoc stays when it sits directly above an exported symbol (an `export * from` included, and a top-level declaration a later `export { X }`, `export default X` or `export = X` names, the shape every shadcn/ui primitive ends with, or that a CommonJS `module.exports = X`, `module.exports = { X }`, `exports.name = X` or `module.exports.name = X` names; such an assignment makes the file a module too), or above a declaration, member, property or signature whose parents reach an exported declaration before a statement boundary (a block, a function body, a non-exported top-level statement): a member of an exported class, interface, type or enum, index, call and construct signatures included, a key of an exported object, and a field of a type literal in a parameter, a generic argument or an array type. Everything inside a `declare global` block or a `declare module 'name'` block counts as exported, and so, in a file with no import or export, does every top-level declaration of a `.d.ts` file and every ambient one of any other file (a `declare const`, `function`, `class` or `namespace` with all it holds, an interface such as `interface Window`, a type alias), since those declarations are global. The rule reads the syntax, not the tsconfig: under `moduleDetection: "force"` (the Vite templates set it) or a `"type": "module"` package on `nodenext`, TypeScript treats every file as a module, so such a declaration is local there, and the rule keeps a doc it could report. In a module file a `declare namespace` is local to the file: its members count only when the namespace itself is exported. So does an `export` inside any namespace: it publishes the member only as far as the namespace is published. A factory documents what it returns on the members of an exported interface it declares as its return type: a JSDoc on a local binding the factory returns is reported, and TypeScript's declaration emit leaves it out of the inferred return type anyway. A JSDoc above anything else, a `{/* */}` in JSX and a comment inside a JSX tag are reported like any other comment. The fix deletes the comment: its whole line when it stands alone, back to the code when it trails, and one space when code sits on both sides. Six cases are left to the author: a JSX container between text, a comment inside a tag, a multi-line comment with code on both of its edges (deleting it could join two lines that semicolon insertion keeps apart), a misplaced JSDoc holding an `@` tag, a JSDoc holding an em dash, and a JSDoc that would reach an export only through an argument of a call or a `new`, such as a key in `export default defineConfig({ ... })`. The exported type there is the call's return type, which drops the doc for `defineConfig(config: UserConfig): UserConfig` and keeps it for `Object.freeze` or a generic identity helper, and the rule cannot see the signature, so it reports without a fix. `{ jsdoc: 'never' }` reports the exported JSDoc too. A reason the code cannot carry belongs in the README. Both presets turn it on at error, beside `soujvnunes/one-line-comments`, which still collapses a multi-line JSDoc on an export to one line.
72
+ **No comments in code: `soujvnunes/no-comments`.** It reports every comment in a JS or TS file, JSDoc included, except a tool directive. A tool directive that does work stays, matched by name: `eslint-disable`, `@ts-expect-error`, `@ts-ignore`, `@ts-nocheck`, `@ts-check`, `prettier-ignore`, `biome-ignore`, a coverage pragma (`istanbul`, `c8`, `v8`, `node:coverage`), a minifier annotation (`@__PURE__`, `#__NO_SIDE_EFFECTS__` and the rest of the `__NAME__` family), a `webpack` or `turbopack` magic comment, `@vite-ignore`, `//# sourceMappingURL`, a triple-slash reference, `/* global */`, `@jsx` with its `Frag`, `ImportSource` and `Runtime` forms, `@vitest-environment`, `@jest-environment`, `@refresh reset`, `@license`, `@preserve`, `@format`, `@prettier`, `@internal` standing alone (read by TypeScript's `stripInternal`; with prose after it, it is a JSDoc like any other), a JSDoc whose only content is a `@deprecated` tag with or without its sentence, on one line or several (read by editors and by `@typescript-eslint/no-deprecated`; another tag after it, or the same text in a `//` line, reports, while a scoped package name such as `@scope/pkg` in its sentence is not a tag, and an em dash in its sentence reports without a fix), `gitleaks:allow` anywhere in a one-line comment that shares its line with code, before it or after it (gitleaks reads it only on the line of the finding), the `/*!` banner and the `#!` line. Any other comment that opens with `@` or `#`, such as `// @todo`, is prose and reports. In a `.js`, `.mjs`, `.cjs` or `.jsx` file a JSDoc whose first tag is a type annotation `checkJs` reads (`@type`, `@typedef`, `@callback`, `@satisfies`, `@template`, `@param`, `@returns`, `@import`, `@enum`, `@extends`, `@augments`, `@implements`, `@this`, `@overload`) and carries the type the tag takes (a `{Type}` after `@type`, `@param`, `@returns`, `@return`, `@satisfies`, `@enum` and `@this`; a `{Type}` or a name that ends its line after `@typedef` and `@callback`; a `{constraint}` or a comma list of names that ends its line after `@template`; a `{Type}` or a type that ends its line after `@extends`, `@augments` and `@implements`; an `import` clause with its `from` after `@import`; a typed `@param` or `@returns` later in the same comment after `@overload`), stays as well, wherever it sits, since deleting it removes the type check. Every other JSDoc reports wherever it sits: above an exported symbol, on a member of an exported class, interface, type or enum, on a key of an exported object, in a `declare global` block and in a `.d.ts` file alike. The rule used to keep those and took a `jsdoc` option to report them; the option is gone, so passing it is a config error and a config that set `{ jsdoc: 'never' }` drops it. A `{/* */}` in JSX and a comment inside a JSX tag are reported like any other comment. The fix deletes the comment: its whole line when it stands alone, back to the code when it trails, and one space when code sits on both sides. Five cases are left to the author: a JSX container between text, a comment inside a tag, a multi-line comment with code on both of its edges (deleting it could join two lines that semicolon insertion keeps apart), a JSDoc holding an `@` tag, and a comment that is all a block holds, since deleting it would leave an empty block that `no-empty` reports (a function body is not such a block, since `no-empty` never reports one, so its lone comment is deleted). A reason the code cannot carry belongs in the README. Both presets turn it on at error, beside `soujvnunes/one-line-comments`, which still collapses a multi-line `@deprecated` JSDoc to one line.
73
73
 
74
74
  **Type-aware rules are enabled**, including `no-floating-promises`, `no-misused-promises`, `await-thenable`, `no-deprecated` and `no-unnecessary-type-assertion`. These need the project service, which is wired by default (see above). They are the rules most likely to surface real findings in a codebase adopting this config, and most are not autofixable.
75
75
 
@@ -82,6 +82,8 @@ These are the opinions most likely to surprise an existing codebase. All of them
82
82
 
83
83
  Measured on a Next app with 77 client files, with the TypeScript parser and browser globals the preset uses: the first rule found the 3 wrappers around a Radix primitive and `cn()` that were known to be needless, and nothing else once `error` files were exempt; the second found 16 static subtrees in 8 files, every one a block of labels and inputs or a heading a server parent could render. A threshold of two elements found 43, most of them label and input pairs that are not worth a refactor.
84
84
 
85
+ This package's tests run every client-boundary case under two settings, espree with no globals and the Next preset's TypeScript parser with browser globals, since a global the config or a TypeScript lib declares resolves differently from an undeclared one.
86
+
85
87
  Adopting this in an existing repo is usually one `eslint --fix` pass plus a short list of genuine fixes from the type-aware rules.
86
88
 
87
89
  ## Accessibility on the Next preset
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Linter } from 'eslint';
2
2
  import { ESLintUtils } from '@typescript-eslint/utils';
3
3
 
4
- declare const oneLineComments: ESLintUtils.RuleModule<"block" | "orphanDoc" | "adjacent" | "paragraphs" | "notDoc", [], unknown, ESLintUtils.RuleListener>;
4
+ declare const oneLineComments: ESLintUtils.RuleModule<"block" | "adjacent" | "paragraphs" | "notDoc" | "orphanDoc", [], unknown, ESLintUtils.RuleListener>;
5
5
 
6
6
  type CompatiblePlugin = {
7
7
  meta: {
@@ -11,28 +11,17 @@ type CompatiblePlugin = {
11
11
  declare const soujvnunesPlugin: CompatiblePlugin;
12
12
 
13
13
  interface ConfigOptions {
14
- /** Extra ignore globs, merged after the defaults. */
15
14
  ignores?: string[];
16
- /** Full import-order groups (replaces the default skeleton). */
17
15
  importGroups?: (string | string[])[];
18
- /** Root for typescript-eslint's project service. Defaults to cwd. */
19
16
  tsconfigRootDir?: string;
20
- /** Path to the Tailwind v4 CSS entry (the file with `@import "tailwindcss"` + `@theme`, e.g. `./app/tailwind.config.css`). When set on the Next preset, it wires the bundled `eslint-plugin-better-tailwindcss` correctness rules, chiefly `no-unknown-classes`, which flags a class not registered in the theme (a dead token `tsc`/build cannot see; see DESIGN-TOKENS). Leave it unset and the plugin stays off, since without the entry the rule cannot resolve the theme and would flag every class. */
21
17
  tailwindEntryPoint?: string;
22
- /** Utility prefixes exempt from the arbitrary-Tailwind-value ban, for a shape with no theme token (e.g. `['grid-cols', 'grid-rows']` for `grid-cols-[200px_1fr]`). Only read when `tailwindEntryPoint` is set. */
23
18
  allowArbitraryClasses?: string[];
24
- /** The `cn()`-like helper name a ternary passed straight to it is banned inside of. */
25
19
  classMergeName?: string;
26
- /** Modules next.config.* loads, beside a next.config.ts, .mts or .cts itself (the .js and .mjs forms sit in the default ignores), restricted with the same repo's `no-restricted-imports` patterns (`['@/*']`) as the config file: relative imports only. */
27
20
  nextConfigModules?: string[];
28
- /** Globs wired to `soujvnunes/one-export-per-file`, the probe-only one-value-export-per-module rule. Unwired (no globs) leaves the rule exported but off. */
29
21
  strictExportGlobs?: string[];
30
- /** Extra flat-config objects appended at the end. */
31
22
  extend?: Linter.Config[];
32
23
  }
33
- /** Base config for TypeScript libraries (no React/Next layers). */
34
24
  declare const createBaseConfig: (options?: ConfigOptions) => any[];
35
- /** Full config for Next.js apps: base plus React, React Hooks, jsx-a11y and Next plugins. */
36
25
  declare const createNextConfig: (options?: ConfigOptions) => any[];
37
26
 
38
27
  export { type ConfigOptions, createBaseConfig, createNextConfig, oneLineComments, soujvnunesPlugin };
package/dist/index.js CHANGED
@@ -659,15 +659,23 @@ var TYPE_TAGS = /* @__PURE__ */ new Map([
659
659
  ]);
660
660
  var ANNOTATION = /^\s*[@#]/u;
661
661
  var BLOCK_ANNOTATION = /^\s*[\w-]+:\S/u;
662
+ var DEPRECATION = /^@deprecated(?![\w-])/u;
663
+ var LATER_TAG = /\s@\w[\w-]*(?![\w/-])/u;
662
664
  var isComment = (token) => token?.type === AST_TOKEN_TYPES.Line || token?.type === AST_TOKEN_TYPES.Block;
663
665
  var isDocShaped = (comment) => comment.type === AST_TOKEN_TYPES.Block && comment.value.startsWith("*");
664
666
  var isBanner = (comment) => comment.type === AST_TOKEN_TYPES.Block && comment.value.startsWith("!");
665
667
  var pragmaText = (comment) => comment.value.replace(/^\*+/u, "");
668
+ var docText = (comment) => comment.value.split(/\r?\n/u).map((line) => line.trim().replace(/^\*+/u, "").trim()).filter(Boolean).join(" ");
669
+ var isDeprecation = (comment) => {
670
+ if (!isDocShaped(comment)) return false;
671
+ const text = docText(comment);
672
+ return DEPRECATION.test(text) && !LATER_TAG.test(text);
673
+ };
666
674
  var isDirectiveText = (text) => DIRECTIVE.test(text) || ANNOTATION.test(text);
667
675
  var isDirective = (comment) => isDirectiveText(pragmaText(comment)) || comment.type === AST_TOKEN_TYPES.Block && (BLOCK_DIRECTIVE.test(comment.value) || !isDocShaped(comment) && BLOCK_ANNOTATION.test(comment.value));
668
676
  var isToolDirective = (comment) => {
669
677
  const text = pragmaText(comment);
670
- return DIRECTIVE.test(text) || PRAGMA.test(text) || comment.type === AST_TOKEN_TYPES.Block && BLOCK_DIRECTIVE.test(comment.value);
678
+ return DIRECTIVE.test(text) || PRAGMA.test(text) || isDeprecation(comment) || comment.type === AST_TOKEN_TYPES.Block && BLOCK_DIRECTIVE.test(comment.value);
671
679
  };
672
680
  var holdsTag = (comment) => /(?:^|\s)@\w/u.test(pragmaText(comment));
673
681
  var isTypeAnnotation = (comment) => {
@@ -714,163 +722,20 @@ var createCommentLookup = (sourceCode) => {
714
722
  };
715
723
 
716
724
  // noComments.ts
717
- var EXPORTS = /* @__PURE__ */ new Set([
718
- AST_NODE_TYPES14.ExportNamedDeclaration,
719
- AST_NODE_TYPES14.ExportDefaultDeclaration,
720
- AST_NODE_TYPES14.ExportAllDeclaration
721
- ]);
722
- var DOCUMENTED = /* @__PURE__ */ new Set([
723
- AST_NODE_TYPES14.ClassDeclaration,
724
- AST_NODE_TYPES14.FunctionDeclaration,
725
- AST_NODE_TYPES14.TSDeclareFunction,
726
- AST_NODE_TYPES14.VariableDeclaration,
727
- AST_NODE_TYPES14.TSInterfaceDeclaration,
728
- AST_NODE_TYPES14.TSTypeAliasDeclaration,
729
- AST_NODE_TYPES14.TSEnumDeclaration,
730
- AST_NODE_TYPES14.TSModuleDeclaration,
731
- AST_NODE_TYPES14.PropertyDefinition,
732
- AST_NODE_TYPES14.MethodDefinition,
733
- AST_NODE_TYPES14.TSAbstractPropertyDefinition,
734
- AST_NODE_TYPES14.TSAbstractMethodDefinition,
735
- AST_NODE_TYPES14.AccessorProperty,
736
- AST_NODE_TYPES14.TSAbstractAccessorProperty,
737
- AST_NODE_TYPES14.TSParameterProperty,
738
- AST_NODE_TYPES14.TSIndexSignature,
739
- AST_NODE_TYPES14.TSPropertySignature,
740
- AST_NODE_TYPES14.TSMethodSignature,
741
- AST_NODE_TYPES14.TSCallSignatureDeclaration,
742
- AST_NODE_TYPES14.TSConstructSignatureDeclaration,
743
- AST_NODE_TYPES14.TSEnumMember,
744
- AST_NODE_TYPES14.Property
745
- ]);
746
- var BOUNDARIES = /* @__PURE__ */ new Set([
747
- AST_NODE_TYPES14.Program,
748
- AST_NODE_TYPES14.BlockStatement,
749
- AST_NODE_TYPES14.StaticBlock
750
- ]);
751
- var MODULE_STATEMENTS = /* @__PURE__ */ new Set([
752
- AST_NODE_TYPES14.ImportDeclaration,
753
- AST_NODE_TYPES14.ExportNamedDeclaration,
754
- AST_NODE_TYPES14.ExportDefaultDeclaration,
755
- AST_NODE_TYPES14.ExportAllDeclaration,
756
- AST_NODE_TYPES14.TSExportAssignment
757
- ]);
758
- var MEMBER_OPENERS = /* @__PURE__ */ new Set(["{", ";", ","]);
759
725
  var JS_FILE = /\.[cm]?jsx?$/u;
760
- var DECLARATION_FILE = /\.d\.[cm]?ts$/u;
761
726
  var EM_DASH = String.fromCodePoint(8212);
762
- var identifierName = (node) => node?.type === AST_NODE_TYPES14.Identifier ? node.name : void 0;
763
- var isModuleExports = (node) => node.type === AST_NODE_TYPES14.MemberExpression && identifierName(node.object) === "module" && identifierName(node.property) === "exports";
764
- var commonJsExport = (statement) => {
765
- if (statement.type !== AST_NODE_TYPES14.ExpressionStatement) return null;
766
- const { expression } = statement;
767
- if (expression.type !== AST_NODE_TYPES14.AssignmentExpression) return null;
768
- const { left, right } = expression;
769
- if (left.type !== AST_NODE_TYPES14.MemberExpression) return null;
770
- const exported = isModuleExports(left) || identifierName(left.object) === "exports" || isModuleExports(left.object);
771
- return exported ? right : null;
772
- };
773
- var deferredExports = (body) => {
774
- const names = /* @__PURE__ */ new Set();
775
- const add = (node) => {
776
- const name = identifierName(node);
777
- if (name) names.add(name);
778
- };
779
- for (const statement of body) {
780
- const commonJs = commonJsExport(statement);
781
- if (commonJs?.type === AST_NODE_TYPES14.ObjectExpression) {
782
- for (const property of commonJs.properties) {
783
- if (property.type === AST_NODE_TYPES14.Property) add(property.value);
784
- }
785
- } else add(commonJs);
786
- if (statement.type === AST_NODE_TYPES14.ExportNamedDeclaration && !statement.source) {
787
- for (const { local } of statement.specifiers) add(local);
788
- }
789
- if (statement.type === AST_NODE_TYPES14.ExportDefaultDeclaration) add(statement.declaration);
790
- if (statement.type === AST_NODE_TYPES14.TSExportAssignment) add(statement.expression);
791
- }
792
- return names;
793
- };
794
- var declaredIds = (statement) => {
795
- if (statement.type === AST_NODE_TYPES14.VariableDeclaration) {
796
- return statement.declarations.map(({ id }) => id);
797
- }
798
- return "id" in statement ? [statement.id] : [];
799
- };
800
- var boundNames = (node) => {
801
- if (node?.type === AST_NODE_TYPES14.Identifier) return [node.name];
802
- if (node?.type === AST_NODE_TYPES14.ObjectPattern) {
803
- return node.properties.flatMap(
804
- (property) => boundNames(property.type === AST_NODE_TYPES14.RestElement ? property.argument : property.value)
805
- );
806
- }
807
- if (node?.type === AST_NODE_TYPES14.ArrayPattern) {
808
- return node.elements.flatMap((element) => boundNames(element));
809
- }
810
- if (node?.type === AST_NODE_TYPES14.AssignmentPattern) return boundNames(node.left);
811
- if (node?.type === AST_NODE_TYPES14.RestElement) return boundNames(node.argument);
812
- return [];
813
- };
814
- var isDeferred = (statement, deferred) => declaredIds(statement).some((id) => boundNames(id).some((name) => deferred.has(name)));
815
- var isModuleFile = (program) => program.body.some(
816
- (statement) => MODULE_STATEMENTS.has(statement.type) || commonJsExport(statement) !== null || statement.type === AST_NODE_TYPES14.TSImportEqualsDeclaration && statement.moduleReference.type === AST_NODE_TYPES14.TSExternalModuleReference
817
- );
818
- var isAmbient = (statement) => statement.type === AST_NODE_TYPES14.TSInterfaceDeclaration || statement.type === AST_NODE_TYPES14.TSTypeAliasDeclaration || "declare" in statement && statement.declare === true;
819
- var ambience = (block) => {
820
- let declared = false;
821
- let node = block.parent;
822
- while (node) {
823
- if (node.type === AST_NODE_TYPES14.TSModuleDeclaration) {
824
- if (node.kind === "global" || node.id.type === AST_NODE_TYPES14.Literal) return "public";
825
- declared ||= node.declare;
826
- }
827
- node = node.parent;
828
- }
829
- return declared ? "declared" : "local";
830
- };
831
- var isBoundary = (node, child, walk) => BOUNDARIES.has(node.type) || node.type === AST_NODE_TYPES14.ArrowFunctionExpression && node.body === child || !walk.throughCalls && (node.type === AST_NODE_TYPES14.CallExpression || node.type === AST_NODE_TYPES14.NewExpression) && node.arguments.some((argument) => argument === child);
832
- var isPublished = (statement, walk) => {
833
- const { parent } = statement;
834
- if (parent?.type !== AST_NODE_TYPES14.TSModuleBlock) return true;
835
- return ambience(parent) === "public" || reachesExport(parent.parent, walk);
836
- };
837
- var reachesExport = (start, walk) => {
838
- let child = start;
839
- let node = start.parent;
840
- while (node) {
841
- if (EXPORTS.has(node.type)) return isPublished(node, walk);
842
- if (node.type === AST_NODE_TYPES14.TSModuleBlock) {
843
- const scope = ambience(node);
844
- if (scope !== "declared") return scope === "public";
845
- }
846
- if (node.type === AST_NODE_TYPES14.Program) return walk.topLevel(child);
847
- if (isBoundary(node, child, walk)) return false;
848
- child = node;
849
- node = node.parent;
850
- }
851
- return false;
852
- };
853
- var isExportedDoc = (comment, sourceCode, lookup, decorated, walk) => {
854
- const before = sourceCode.getTokenBefore(comment);
855
- if (before?.loc.end.line === comment.loc.start.line && !MEMBER_OPENERS.has(before.value)) {
856
- return false;
857
- }
858
- const token = sourceCode.getTokenAfter(comment);
859
- if (!token) return false;
860
- const target = decorated.get(token.range[0]);
861
- if (target?.type === AST_NODE_TYPES14.ClassDeclaration && reachesExport(target, walk)) {
862
- return true;
863
- }
864
- let node = lookup.nodeAt(token.range[0]);
865
- while (node?.range[0] === token.range[0]) {
866
- if (EXPORTS.has(node.type)) return isPublished(node, walk);
867
- if (DOCUMENTED.has(node.type)) return reachesExport(node, walk);
868
- node = node.parent ?? null;
869
- }
870
- return false;
871
- };
872
727
  var isJsxNode = (node) => !!node && node.type.startsWith("JSX") && node.type !== AST_NODE_TYPES14.JSXExpressionContainer;
873
- var classify = (comment, sourceCode, lookup, decorated, topLevel) => {
728
+ var FUNCTION_NODES = /* @__PURE__ */ new Set([
729
+ AST_NODE_TYPES14.FunctionDeclaration,
730
+ AST_NODE_TYPES14.FunctionExpression,
731
+ AST_NODE_TYPES14.ArrowFunctionExpression
732
+ ]);
733
+ var isEmptyBlock = (node) => {
734
+ if (node?.type === AST_NODE_TYPES14.SwitchStatement) return node.cases.length === 0;
735
+ if (node?.type === AST_NODE_TYPES14.StaticBlock) return node.body.length === 0;
736
+ return node?.type === AST_NODE_TYPES14.BlockStatement && node.body.length === 0 && !FUNCTION_NODES.has(node.parent.type);
737
+ };
738
+ var classify = (comment, lookup) => {
874
739
  const node = lookup.enclosingNode(comment);
875
740
  const inJsx = isJsxNode(node);
876
741
  if (isToolDirective(comment) || lookup.isAllowMarker(comment)) {
@@ -878,30 +743,23 @@ var classify = (comment, sourceCode, lookup, decorated, topLevel) => {
878
743
  }
879
744
  if (isBanner(comment)) return "banner";
880
745
  if (inJsx) return node?.type === AST_NODE_TYPES14.JSXEmptyExpression ? "jsx" : "attribute";
881
- if (isDocShaped(comment)) {
882
- const reaches = (throughCalls) => isExportedDoc(comment, sourceCode, lookup, decorated, { topLevel, throughCalls });
883
- if (reaches(false)) return "jsdoc";
884
- return reaches(true) ? "argumentDoc" : "orphanDoc";
885
- }
746
+ if (isDocShaped(comment)) return "jsdoc";
886
747
  return comment.type === AST_TOKEN_TYPES2.Line ? "line" : "block";
887
748
  };
749
+ var KEPT = "Only a tool directive stays, such as `eslint-disable`, `@ts-expect-error`, a type annotation in a JS file, a lone `@internal` or a JSDoc holding only `@deprecated`.";
888
750
  var MESSAGES = {
889
- line: "Comments are not allowed in code. Delete this `//` comment: a reason the code cannot carry belongs in the README. Only tool directives and a JSDoc on an exported symbol stay.",
890
- block: "Comments are not allowed in code. Delete this block comment: a reason the code cannot carry belongs in the README. Only tool directives and a JSDoc on an exported symbol stay.",
891
- orphanDoc: "A JSDoc is allowed only directly above an exported symbol, or a member of an exported class, interface, type or enum. Delete this one.",
892
- argumentDoc: "This JSDoc sits in an argument of an exported call or `new`, so it is published only when the callee returns its argument's type, as `Object.freeze` or a generic identity helper does. The rule cannot see the signature: delete it unless the callee keeps it.",
893
- jsdoc: "This config allows no JSDoc. Delete it.",
751
+ line: `Comments are not allowed in code. Delete this \`//\` comment: a reason the code cannot carry belongs in the README. ${KEPT}`,
752
+ block: `Comments are not allowed in code. Delete this block comment: a reason the code cannot carry belongs in the README. ${KEPT}`,
753
+ jsdoc: `Comments are not allowed in code, JSDoc included. Delete this JSDoc: a reason the code cannot carry belongs in the README. ${KEPT}`,
894
754
  jsx: "Comments are not allowed in JSX. Delete this `{/* */}` container; only a tool directive stays.",
895
755
  attribute: "Comments are not allowed inside a JSX tag. Delete this one.",
896
- emDash: "This JSDoc holds an em dash. Write a comma, a colon, parentheses or two sentences instead."
756
+ emDash: "This `@deprecated` JSDoc holds an em dash. Write a comma, a colon, parentheses or two sentences instead."
897
757
  };
898
758
  var MESSAGE_IDS = {
899
759
  directive: null,
900
760
  banner: null,
901
761
  jsxDirective: null,
902
762
  jsdoc: "jsdoc",
903
- orphanDoc: "orphanDoc",
904
- argumentDoc: "argumentDoc",
905
763
  jsx: "jsx",
906
764
  attribute: "attribute",
907
765
  line: "line",
@@ -911,29 +769,17 @@ var noComments = ESLintUtils2.RuleCreator.withoutDocs({
911
769
  meta: {
912
770
  type: "suggestion",
913
771
  docs: {
914
- description: "Disallow comments in code, except tool directives and a JSDoc directly above an exported symbol or a member of an exported class, interface, type or enum."
772
+ description: "Disallow comments in code, JSDoc included, except tool directives, a type-annotation JSDoc in a JS file, a lone `@internal` and a JSDoc holding only `@deprecated`."
915
773
  },
916
774
  fixable: "code",
917
- schema: [
918
- {
919
- type: "object",
920
- properties: { jsdoc: { type: "string", enum: ["exports", "never"] } },
921
- additionalProperties: false
922
- }
923
- ],
775
+ schema: [],
924
776
  messages: MESSAGES
925
777
  },
926
- defaultOptions: [{}],
927
- create(context, [{ jsdoc }]) {
778
+ defaultOptions: [],
779
+ create(context) {
928
780
  const sourceCode = context.sourceCode;
929
781
  const { lines, text } = sourceCode;
930
782
  const lookup = createCommentLookup(sourceCode);
931
- const decorated = /* @__PURE__ */ new Map();
932
- const program = sourceCode.ast;
933
- const deferred = deferredExports(program.body);
934
- const globalScope = !isModuleFile(program);
935
- const declarationFile = DECLARATION_FILE.test(context.filename);
936
- const topLevel = (statement) => isDeferred(statement, deferred) || globalScope && (declarationFile || isAmbient(statement));
937
783
  const typedJs = JS_FILE.test(context.filename);
938
784
  const lineStart = (line) => sourceCode.getIndexFromLoc({ line, column: 0 });
939
785
  const lineEnd = (line) => lineStart(line) + (lines[line - 1]?.length ?? 0);
@@ -943,7 +789,7 @@ var noComments = ESLintUtils2.RuleCreator.withoutDocs({
943
789
  return [0, text.length];
944
790
  };
945
791
  const removal = (comment, kind) => {
946
- if (kind === "attribute" || kind === "argumentDoc" || (kind === "orphanDoc" || kind === "jsdoc") && holdsTag(comment)) {
792
+ if (kind === "attribute" || kind === "jsdoc" && holdsTag(comment) || isEmptyBlock(lookup.enclosingNode(comment))) {
947
793
  return null;
948
794
  }
949
795
  const span = lookup.jsxContainer(comment) ?? comment;
@@ -967,19 +813,12 @@ var noComments = ESLintUtils2.RuleCreator.withoutDocs({
967
813
  return nextStart === void 0 ? null : { range: [range[0], nextStart], text: "", lines: null };
968
814
  };
969
815
  return {
970
- Decorator(decorator) {
971
- const { parent } = decorator;
972
- if ("decorators" in parent && parent.decorators[0] === decorator) {
973
- decorated.set(decorator.range[0], parent);
974
- }
975
- },
976
816
  "Program:exit"() {
977
817
  const reports = [];
978
818
  for (const comment of sourceCode.getAllComments().filter(isComment)) {
979
- const kind = typedJs && isTypeAnnotation(comment) ? "directive" : classify(comment, sourceCode, lookup, decorated, topLevel);
980
- if (kind === "jsdoc" && jsdoc !== "never") {
981
- if (comment.value.includes(EM_DASH))
982
- reports.push({ comment, messageId: "emDash", fix: null });
819
+ const kind = typedJs && isTypeAnnotation(comment) ? "directive" : classify(comment, lookup);
820
+ if (isDeprecation(comment) && comment.value.includes(EM_DASH)) {
821
+ reports.push({ comment, messageId: "emDash", fix: null });
983
822
  continue;
984
823
  }
985
824
  const messageId = MESSAGE_IDS[kind];
@@ -1120,9 +959,9 @@ var oneLineComments = ESLintUtils4.RuleCreator.withoutDocs({
1120
959
  messages: {
1121
960
  adjacent: "Two comment lines are touching. A comment is one line, however long it runs: join them, or write one line per fact beside the code it describes.",
1122
961
  paragraphs: "A paragraph break inside a comment, a bare `//` between comment lines or an empty line inside a block, makes it a set of comments rather than one wrapped line, and joining it would bury every fact but the first. Write one line per fact beside the code it describes, or move the rationale to the README or the project MANIFEST.",
1123
- block: "This block comment spans lines. A comment is one line, however long it runs: collapse it to one `//` line, or to one `/** \u2026 */` line when it is JSDoc, or move the rationale to the README or the project MANIFEST.",
962
+ block: "This block comment spans lines. A comment is one line, however long it runs: collapse it to one `//` line, or to one `/** \u2026 */` line when a tool reads it as JSDoc, or move the rationale to the README or the project MANIFEST.",
1124
963
  notDoc: "A block comment is for JSDoc and JSX only. Write this one as `//`, on its own line or at the end of one, or delete it if it is empty.",
1125
- orphanDoc: "`/**` is JSDoc, and JSDoc sits directly above the code it documents. Move it there, join it with the doc under it, or write it as `//`."
964
+ orphanDoc: "`/**` opens a JSDoc, which a tool reads only directly above the code it applies to. Move it there when a tool reads it, and delete it otherwise."
1126
965
  }
1127
966
  },
1128
967
  defaultOptions: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soujvnunes/eslint-config",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Shared flat ESLint config factories (base + Next.js).",
5
5
  "license": "MIT",
6
6
  "author": "soujvnunes",