eslint-plugin-use-agnostic 2.0.8 → 2.1.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.
@@ -1,8 +1,5 @@
1
1
  import path from "path";
2
2
 
3
- import { resolveImportingPath } from "resolve-importing-path";
4
- import { findUpSync } from "find-up";
5
-
6
3
  import {
7
4
  EXTENSIONS,
8
5
  reExportNotSameMessageId,
@@ -134,9 +131,9 @@ export const fileIsRegularJavaScript = (filePath) =>
134
131
  //
135
132
 
136
133
  /**
137
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#CURRENTFILEFLOW
138
- * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
139
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#CURRENTFILEFLOW
134
+ * The flow that begins the import rules enforcement rule, retrieving the verified commented directive of the current file before comparing it to upcoming verified commented directives of the files it imports.
135
+ * @param {Context} context The ESLint rule's `context` object.
136
+ * @returns Either an object with `skip: true` to disregard or one with the non-null `verifiedCommentedDirective`.
140
137
  */
141
138
  export const currentFileFlow = (context) => {
142
139
  const skipTrue = { ...skip, verifiedCommentedDirective: undefined };
@@ -232,11 +229,11 @@ export const currentFileFlow = (context) => {
232
229
  /* importedFileFlow */
233
230
 
234
231
  /**
235
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#IMPORTEDFILEFLOW
236
- * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
237
- * @param {ImportDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
238
- * @param {ResolverFactory} resolver
239
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#IMPORTEDFILEFLOW
232
+ * The flow that is shared between import and re-export traversals to obtain the import file's commented directive.
233
+ * @param {Context} context The ESLint rule's `context` object.
234
+ * @param {ImportDeclaration} node The ESLint `node` of the rule's current traversal.
235
+ * @param {ResolverFactory} resolver The resolver generated with `oxc-resolver` to resolve the node's import path.
236
+ * @returns Either an object with `skip: true` to disregard or one with the non-null `importedFileCommentedDirective`. And now with the added results of `analyzeExportsForReExports`.
240
237
  */
241
238
  const importedFileFlow = (context, node, resolver) => {
242
239
  const skipTrue = {
@@ -246,18 +243,8 @@ const importedFileFlow = (context, node, resolver) => {
246
243
  };
247
244
 
248
245
  // finds the full path of the import
249
- // const resolvedImportPath = resolveImportingPath(
250
- // path.dirname(context.filename),
251
- // node.source.value,
252
- // findUpSync("tsconfig.json", {
253
- // cwd: path.dirname(context.filename),
254
- // }) ?? context.cwd,
255
- // );
256
- const resolvedImportPath = resolver.resolveFileSync(
257
- context.filename,
258
- node.source.value,
259
- ).path;
260
- console.debug("resolvedImportPath is:", resolvedImportPath);
246
+ const resolvedImportPath =
247
+ resolver.resolveFileSync(context.filename, node.source.value).path ?? null; // works
261
248
 
262
249
  // does not operate on paths it did not resolve
263
250
  if (resolvedImportPath === null) return skipTrue;
@@ -272,13 +259,14 @@ const importedFileFlow = (context, node, resolver) => {
272
259
  commentedDirective: importedFileCommentedDirective,
273
260
  sourceCode: importedFileSourceCode,
274
261
  } = getCommentedDirectiveFromImportedModule(resolvedImportPath);
262
+ // Actually, this will need to remain, because the obtained `importedFileSourceCode` is necessary for further linting.
275
263
 
276
264
  // returns early if there is no directive or no valid directive (same, but eventually no directive could have defaults)
277
265
  if (!importedFileCommentedDirective) {
278
266
  // Now silencing the warning as superfluous, in order to not warn on imports of files without a commented directive that are outside of linting range.
279
267
 
280
268
  // console.warn(
281
- // `WARNING. The imported file ${resolvedImportPath}, whose path has been resolved from ${context.filename}, has no commented $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#DIRECTIVEPERIOD It is thus ignored since the report on that circumstance would be available on the imported file itself.`
269
+ // `WARNING. The imported file ${resolvedImportPath}, whose path has been resolved from ${context.filename}, has no commented directive. It is thus ignored since the report on that circumstance would be available on the imported file itself.`
282
270
  // ); // The decision not to report has been taken to not inflate the number of warnings.
283
271
  return skipTrue;
284
272
  }
@@ -340,11 +328,11 @@ const importedFileFlow = (context, node, resolver) => {
340
328
 
341
329
  // NEW!! Currently strictly adapted from importedFileFlow
342
330
  /**
343
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#IMPORTEDFILEFLOWREQUIRE
344
- * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
345
- * @param {CallExpression} node $COMMENT#JSDOC#PARAMS#NODE
346
- * @param {ResolverFactory} resolver
347
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#IMPORTEDFILEFLOW
331
+ * The `importedFileFlow` adapted for `require` calls to obtain the import file's commented directive.
332
+ * @param {Context} context The ESLint rule's `context` object.
333
+ * @param {CallExpression} node The ESLint `node` of the rule's current traversal.
334
+ * @param {ResolverFactory} resolver The resolver generated with `oxc-resolver` to resolve the node's import path.
335
+ * @returns Either an object with `skip: true` to disregard or one with the non-null `importedFileCommentedDirective`. And now with the added results of `analyzeExportsForReExports`.
348
336
  */
349
337
  const importedFileFlowRequire = (context, node, resolver) => {
350
338
  const skipTrue = {
@@ -364,18 +352,8 @@ const importedFileFlowRequire = (context, node, resolver) => {
364
352
  if (typeof importPath !== "string") return skipTrue;
365
353
 
366
354
  // finds the full path of the import
367
- // const resolvedImportPath = resolveImportingPath(
368
- // path.dirname(context.filename),
369
- // importPath,
370
- // findUpSync("tsconfig.json", {
371
- // cwd: path.dirname(context.filename),
372
- // }) ?? context.cwd,
373
- // );
374
- const resolvedImportPath = resolver.resolveFileSync(
375
- context.filename,
376
- importPath,
377
- ).path;
378
- console.debug("resolvedImportPath (require) is:", resolvedImportPath);
355
+ const resolvedImportPath =
356
+ resolver.resolveFileSync(context.filename, importPath).path ?? null; // works (?)
379
357
 
380
358
  // does not operate on paths it did not resolve
381
359
  if (resolvedImportPath === null) return skipTrue;
@@ -396,7 +374,7 @@ const importedFileFlowRequire = (context, node, resolver) => {
396
374
  // Now silencing the warning as superfluous, in order to not warn on imports of files without a commented directive that are outside of linting range.
397
375
 
398
376
  // console.warn(
399
- // `WARNING. The imported file ${resolvedImportPath}, whose path has been resolved from ${context.filename}, has no commented $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#DIRECTIVEPERIOD It is thus ignored since the report on that circumstance would be available on the imported file itself.`
377
+ // `WARNING. The imported file ${resolvedImportPath}, whose path has been resolved from ${context.filename}, has no commented directive. It is thus ignored since the report on that circumstance would be available on the imported file itself.`
400
378
  // ); // The decision not to report has been taken to not inflate the number of warnings.
401
379
  return skipTrue;
402
380
  }
@@ -457,12 +435,12 @@ const importedFileFlowRequire = (context, node, resolver) => {
457
435
  /* importsFlow */
458
436
 
459
437
  /**
460
- * $COMMENT#JSDOC#FORALIASVARIABLES#IMPORTSFLOWCOMMENTED
461
- * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
462
- * @param {ImportDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
463
- * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
464
- * @param {ResolverFactory} resolver
465
- * @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
438
+ * The full flow for import traversals to enforce commented directives import rules.
439
+ * @param {Context} context The ESLint rule's `context` object.
440
+ * @param {ImportDeclaration} node The ESLint `node` of the rule's current traversal.
441
+ * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
442
+ * @param {ResolverFactory} resolver The resolver generated with `oxc-resolver` to resolve the node's import path.
443
+ * @returns Early if the flow needs to be interrupted.
466
444
  */
467
445
  export const importsFlow = (
468
446
  context,
@@ -540,12 +518,12 @@ export const importsFlow = (
540
518
 
541
519
  // NEW!! Currently strictly adapted from importsFlow
542
520
  /**
543
- * $COMMENT#JSDOC#FORALIASVARIABLES#IMPORTSFLOWCOMMENTEDREQUIRE
544
- * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
545
- * @param {CallExpression} node $COMMENT#JSDOC#PARAMS#NODE
546
- * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
547
- * @param {ResolverFactory} resolver
548
- * @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
521
+ * The `importsFlow` adapted for `require` calls to enforce commented directives import rules.
522
+ * @param {Context} context The ESLint rule's `context` object.
523
+ * @param {CallExpression} node The ESLint `node` of the rule's current traversal.
524
+ * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
525
+ * @param {ResolverFactory} resolver The resolver generated with `oxc-resolver` to resolve the node's import path.
526
+ * @returns Early if the flow needs to be interrupted.
549
527
  */
550
528
  export const importsFlowRequire = (
551
529
  context,
@@ -621,12 +599,12 @@ export const importsFlowRequire = (
621
599
  /* allExportsFlow */
622
600
 
623
601
  /**
624
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#ALLEXPORTSFLOW
625
- * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
626
- * @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
627
- * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
628
- * @param {ResolverFactory} resolver
629
- * @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
602
+ * The full flow for export traversals, shared between `ExportNamedDeclaration`, `ExportAllDeclaration`, and `ExportDefaultDeclaration`, to ensure same commented directive re-exports in modules that aren't Agnostic Strategies Modules, and enforce strategized exports specifically in Agnostic Strategies modules.
603
+ * @param {Context} context The ESLint rule's `context` object.
604
+ * @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node The ESLint `node` of the rule's current traversal.
605
+ * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
606
+ * @param {ResolverFactory} resolver The resolver generated with `oxc-resolver` to resolve the node's import path.
607
+ * @returns Early if the flow needs to be interrupted.
630
608
  */
631
609
  export const allExportsFlow = (
632
610
  context,
@@ -667,12 +645,12 @@ export const allExportsFlow = (
667
645
  // else
668
646
  currentFileCommentedDirective = addressedDirective; // to still keep compatibility with strategies
669
647
 
670
- // Lints imports of Agnostic Strategies Modules beyond strategy resolution, such as to warn imports of Special Agnostic Modules. Does the same with $COMMENT#DIRECTIVE21#USE_AGNOSTIC_CONDITIONS#KINDSSIMPLE Modules, since they are the only other modules which cannot import themselves.
648
+ // Lints imports of Agnostic Strategies Modules beyond strategy resolution, such as to warn imports of Special Agnostic Modules. Does the same with Agnostic Conditions Modules, since they are the only other modules which cannot import themselves.
671
649
  if (
672
650
  currentFileCommentedDirective === USE_AGNOSTIC_STRATEGIES ||
673
651
  currentFileCommentedDirective === USE_AGNOSTIC_CONDITIONS
674
652
  ) {
675
- // Basically, all modules need to do reexports that correspond to their own modules, but not Agnostic Strategies Modules and $COMMENT#DIRECTIVE21#USE_AGNOSTIC_CONDITIONS#KINDSSIMPLE Modules, the latter which are in fact NOT allowed to do re-exports.
653
+ // Basically, all modules need to do reexports that correspond to their own modules, but not Agnostic Strategies Modules and Agnostic Conditions Modules, the latter which are in fact NOT allowed to do re-exports.
676
654
  if (
677
655
  isImportBlocked(
678
656
  currentFileCommentedDirective,
@@ -750,9 +728,9 @@ export const allExportsFlow = (
750
728
  /* functionDeclarationFlow */
751
729
 
752
730
  /**
753
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#NAMEISPASCALCASE
754
- * @param {string} name $COMMENT#JSDOC#PARAMS#DIRECTIVE21#NAME
755
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#NAMEISPASCALCASE
731
+ * Checks if the name of an identifier is in PascalCase, as a cheap way to assess whether or not it is a React component.
732
+ * @param {string} name The name of the identifier at hand.
733
+ * @returns `true` if the name is recognized as PascalCase, `false` otherwise.
756
734
  */
757
735
  const nameIsPascalCase = (name) => {
758
736
  // PascalCase: starts with capital, no underscores, no hyphens
@@ -760,9 +738,9 @@ const nameIsPascalCase = (name) => {
760
738
  };
761
739
 
762
740
  /**
763
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#DECLARESCHILDRENPROP
764
- * @param {Parameter[]} params $COMMENT#JSDOC#PARAMS#DIRECTIVE21#PARAMS
765
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#DECLARESCHILDRENPROP
741
+ * Checks whether the parameters of a function (React component) include the `children` property.
742
+ * @param {Parameter[]} params The parameters at hand.
743
+ * @returns `true` if the parameters include the `children` property, `false` otherwise.
766
744
  */
767
745
  const declaresChildrenProp = (params) => {
768
746
  if (params.length === 0) return false;
@@ -783,11 +761,11 @@ const declaresChildrenProp = (params) => {
783
761
  };
784
762
 
785
763
  /**
786
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#FUNCTIONDECLARATIONFLOW
787
- * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
788
- * @param {FunctionDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
789
- * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
790
- * @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
764
+ * The flow for function declarations to ensure that Client Lineals Components are made in Client Components Modules and Client Contexts Components are made in Client Contexts Modules, based on the fact that the former are child-free and the latter are children-bearing.
765
+ * @param {Context} context The ESLint rule's `context` object.
766
+ * @param {FunctionDeclaration} node The ESLint `node` of the rule's current traversal.
767
+ * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
768
+ * @returns Early if the flow needs to be interrupted.
791
769
  */
792
770
  export const functionDeclarationFlow = (
793
771
  context,
@@ -829,11 +807,11 @@ export const functionDeclarationFlow = (
829
807
  /* jsxElementFlow */
830
808
 
831
809
  /**
832
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#JSXELEMENTFLOW
833
- * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
834
- * @param {JSXElement} node $COMMENT#JSDOC#PARAMS#NODE
835
- * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
836
- * @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
810
+ * The flow for JSX elements to ensure that render props are only used isolated inside a Client Components Module, where their execution would safely be happening exclusively on the client.
811
+ * @param {Context} context The ESLint rule's `context` object.
812
+ * @param {JSXElement} node The ESLint `node` of the rule's current traversal.
813
+ * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
814
+ * @returns Early if the flow needs to be interrupted.
837
815
  */
838
816
  export const jsxElementFlow = (
839
817
  context,
@@ -864,11 +842,11 @@ export const jsxElementFlow = (
864
842
  /* jsxOpeningElementFlow */
865
843
 
866
844
  /**
867
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#JSXOPENINGELEMENTFLOW
868
- * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
869
- * @param {JSXOpeningElement} node $COMMENT#JSDOC#PARAMS#NODE
870
- * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
871
- * @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
845
+ * The flow for JSX opening elements to ensure that event handler props on intrinsic elements are only used in modules that can safely create Client Components.
846
+ * @param {Context} context The ESLint rule's `context` object.
847
+ * @param {JSXOpeningElement} node The ESLint `node` of the rule's current traversal.
848
+ * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
849
+ * @returns Early if the flow needs to be interrupted.
872
850
  */
873
851
  export const jsxOpeningElementFlow = (
874
852
  context,
@@ -30,9 +30,9 @@ import {
30
30
  /* getCommentedDirectiveFromSourceCode */
31
31
 
32
32
  /**
33
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#DETECTQUOTETYPE
34
- * @param {string} string $COMMENT#JSDOC#PARAMS#DIRECTIVE21#STRING
35
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#DETECTQUOTETYPE
33
+ * Detects whether a string is single- or double-quoted.
34
+ * @param {string} string The original string.
35
+ * @returns `true` if single-quoted, `false` if double-quoted, `null` if neither.
36
36
  */
37
37
  const detectQuoteType = (string) => {
38
38
  if (string.startsWith("'") && string.endsWith("'")) {
@@ -45,9 +45,9 @@ const detectQuoteType = (string) => {
45
45
  };
46
46
 
47
47
  /**
48
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#STRIPSINGLEQUOTES
49
- * @param {string} string $COMMENT#JSDOC#PARAMS#DIRECTIVE21#STRING
50
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#STRIPSINGLEQUOTES
48
+ * Removes single quotes from a string known to be single-quoted.
49
+ * @param {string} string The original string.
50
+ * @returns The string with quotes removed.
51
51
  */
52
52
  const stripSingleQuotes = (string) => {
53
53
  if (string.startsWith("'") && string.endsWith("'")) {
@@ -57,9 +57,9 @@ const stripSingleQuotes = (string) => {
57
57
  };
58
58
 
59
59
  /**
60
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#STRIPDOUBLEQUOTES
61
- * @param {string} string $COMMENT#JSDOC#PARAMS#DIRECTIVE21#STRING
62
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#STRIPSINGLEQUOTES
60
+ * Removes double quotes from a string known to be double-quoted.
61
+ * @param {string} string The original string.
62
+ * @returns The string with quotes removed.
63
63
  */
64
64
  const stripDoubleQuotes = (string) => {
65
65
  if (string.startsWith('"') && string.endsWith('"')) {
@@ -69,21 +69,21 @@ const stripDoubleQuotes = (string) => {
69
69
  };
70
70
 
71
71
  /**
72
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE1
72
+ * Gets the commented directive of a module from its ESLint `SourceCode` object.
73
73
  *
74
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE2
75
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERLOGICSA
76
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTLOGICSA
77
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICLOGICSA
78
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERCOMPONENTSA
79
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCOMPONENTSA
80
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCOMPONENTSA
81
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERFUNCTIONSA
82
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCONTEXTSA
83
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCONDITIONSA
84
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICSTRATEGIESA
85
- * @param {SourceCode} sourceCode $COMMENT#JSDOC#PARAMS#DIRECTIVE21#SOURCECODE
86
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE
74
+ * Accepted directives for the default Directive-First Architecture are (single or double quotes included):
75
+ * - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
76
+ * - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
77
+ * - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
78
+ * - `'use server components'`, `"use server components"` denoting a Server Components Module.
79
+ * - `'use client components'`, `"use client components"` denoting a Client Components Module.
80
+ * - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
81
+ * - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
82
+ * - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
83
+ * - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
84
+ * - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
85
+ * @param {SourceCode} sourceCode The ESLint SourceCode object.
86
+ * @returns The commented directive, or lack thereof via `null`. Given the strictness of this architecture, the lack of a directive is considered a mistake. (Though rules may provide the opportunity to declare a default, and configs with preset defaults may become provided.)
87
87
  */
88
88
  export const getCommentedDirectiveFromSourceCode = (sourceCode) => {
89
89
  // returns null IMMEDIATELY if the SourceCode is faulty (inexistent)
@@ -134,21 +134,21 @@ export const getCommentedDirectiveFromSourceCode = (sourceCode) => {
134
134
  /* getCommentedDirectiveFromCurrentModule */
135
135
 
136
136
  /**
137
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMCURRENTMODULE1
137
+ * Gets the commented directive of the current module.
138
138
  *
139
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE2
140
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERLOGICSA
141
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTLOGICSA
142
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICLOGICSA
143
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERCOMPONENTSA
144
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCOMPONENTSA
145
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCOMPONENTSA
146
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERFUNCTIONSA
147
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCONTEXTSA
148
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCONDITIONSA
149
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICSTRATEGIESA
150
- * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
151
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE
139
+ * Accepted directives for the default Directive-First Architecture are (single or double quotes included):
140
+ * - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
141
+ * - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
142
+ * - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
143
+ * - `'use server components'`, `"use server components"` denoting a Server Components Module.
144
+ * - `'use client components'`, `"use client components"` denoting a Client Components Module.
145
+ * - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
146
+ * - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
147
+ * - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
148
+ * - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
149
+ * - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
150
+ * @param {Context} context The ESLint rule's `context` object.
151
+ * @returns The commented directive, or lack thereof via `null`. Given the strictness of this architecture, the lack of a directive is considered a mistake. (Though rules may provide the opportunity to declare a default, and configs with preset defaults may become provided.)
152
152
  */
153
153
  export const getCommentedDirectiveFromCurrentModule = (context) => {
154
154
  const sourceCode = context.sourceCode;
@@ -163,21 +163,21 @@ export const getCommentedDirectiveFromCurrentModule = (context) => {
163
163
  /* getCommentedDirectiveFromImportedModule */
164
164
 
165
165
  /**
166
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMIMPORTEDMODULE1
166
+ * Gets the commented directive of the imported module.
167
167
  *
168
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE2
169
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERLOGICSA
170
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTLOGICSA
171
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICLOGICSA
172
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERCOMPONENTSA
173
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCOMPONENTSA
174
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCOMPONENTSA
175
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERFUNCTIONSA
176
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCONTEXTSA
177
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCONDITIONSA
178
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICSTRATEGIESA
179
- * @param {string} resolvedPath $COMMENT#JSDOC#PARAMS#RESOLVEDPATH
180
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMIMPORTEDMODULE
168
+ * Accepted directives for the default Directive-First Architecture are (single or double quotes included):
169
+ * - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
170
+ * - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
171
+ * - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
172
+ * - `'use server components'`, `"use server components"` denoting a Server Components Module.
173
+ * - `'use client components'`, `"use client components"` denoting a Client Components Module.
174
+ * - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
175
+ * - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
176
+ * - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
177
+ * - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
178
+ * - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
179
+ * @param {string} resolvedPath The resolved path of the imported module.
180
+ * @returns The commented directive, or lack thereof via `null`. Now also provides the obtained `SourceCode` object. Given the strictness of this architecture, the lack of a directive is considered a mistake. (Though rules may provide the opportunity to declare a default, and configs with preset defaults may become provided.)
181
181
  */
182
182
  export const getCommentedDirectiveFromImportedModule = (resolvedPath) => {
183
183
  const sourceCode = getSourceCodeFromFilePath(resolvedPath);
@@ -192,20 +192,20 @@ export const getCommentedDirectiveFromImportedModule = (resolvedPath) => {
192
192
  /* getVerifiedCommentedDirective */
193
193
 
194
194
  /**
195
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETVERIFIEDCOMMENTEDDIRECTIVE
196
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERLOGICSB
197
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTLOGICSB
198
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICLOGICSB
199
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERCOMPONENTSB
200
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCOMPONENTSB
201
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCOMPONENTSB
202
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERFUNCTIONSB
203
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCONTEXTSB
204
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCONDITIONSB
205
- * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICSTRATEGIESB
206
- * @param {CommentedDirective} directive $COMMENT#JSDOC#PARAMS#DIRECTIVE21#DIRECTIVE
207
- * @param {Extension} extension $COMMENT#JSDOC#PARAMS#EXTENSION
208
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETVERIFIEDCOMMENTEDDIRECTIVE
195
+ * Ensures that a module's commented directive is consistent with its file extension (depending on whether it ends with 'x' for JSX).
196
+ * - `'use server logics'`: Server Logics Modules do NOT export JSX.
197
+ * - `'use client logics'`: Client Logics Modules do NOT export JSX.
198
+ * - `'use agnostic logics'`: Agnostic Logics Modules do NOT export JSX.
199
+ * - `'use server components'`: Server Components Modules ONLY export JSX.
200
+ * - `'use client components'`: Client Components Modules ONLY export JSX.
201
+ * - `'use agnostic components'`: Agnostic Components Modules ONLY export JSX.
202
+ * - `'use server functions'`: Server Functions Modules do NOT export JSX.
203
+ * - `'use client contexts'`: Client Contexts Modules ONLY export JSX.
204
+ * - `'use agnostic conditions'`: Agnostic Conditions Modules ONLY export JSX.
205
+ * - `'use agnostic strategies'`: Agnostic Strategies Modules may export JSX.
206
+ * @param {CommentedDirective} directive The commented directive as written on top of the file (cannot be `null` at that stage).
207
+ * @param {Extension} extension The JavaScript (TypeScript) extension of the file.
208
+ * @returns The verified commented directive, from which imports rules are applied. Returns `null` if the verification failed, upon which an error will be reported depending on the commented directive, since the error logic here is strictly binary.
209
209
  */
210
210
  export const getVerifiedCommentedDirective = (directive, extension) => {
211
211
  const rule = commentedDirectives_extensionRules[directive];
@@ -222,10 +222,10 @@ export const getVerifiedCommentedDirective = (directive, extension) => {
222
222
  /* getStrategizedDirective */
223
223
 
224
224
  /**
225
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETSTRATEGIZEDDIRECTIVE
226
- * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
227
- * @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
228
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETSTRATEGIZEDDIRECTIVE
225
+ * Gets the interpreted directive from a specified commented Strategy (such as `@serverLogics`) nested inside the import (or export) declaration for an import (or export) from an Agnostic Strategies Module.
226
+ * @param {Context} context The ESLint rule's `context` object.
227
+ * @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node The ESLint `node` of the rule's current traversal.
228
+ * @returns The interpreted directive, a.k.a. strategized directive, or lack thereof via `null`.
229
229
  */
230
230
  export const getStrategizedDirective = (context, node) => {
231
231
  // gets the first nested `/* */` comment inside the node
@@ -314,11 +314,11 @@ export const fileIsRegularJavaScript = (filePath) =>
314
314
  //
315
315
 
316
316
  /**
317
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#ADDRESSDIRECTIVEIFAGNOSTICSTRATEGIES
318
- * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
319
- * @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
320
- * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
321
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#ADDRESSDIRECTIVEIFAGNOSTICSTRATEGIES
317
+ * Verifies the current node's export strategy if the current commented directive is `"use agnostic strategies"` by reporting `exportNotStrategized` in case an export is not strategized in an Agnostic Strategies Module.
318
+ * @param {Context} context The ESLint rule's `context` object.
319
+ * @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node The ESLint `node` of the rule's current traversal.
320
+ * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
321
+ * @returns The commented directive, the addressed strategy (as a commented directive) or `null` in case of failure.
322
322
  */
323
323
  export const addressDirectiveIfAgnosticStrategies = (
324
324
  context,
@@ -352,10 +352,10 @@ export const addressDirectiveIfAgnosticStrategies = (
352
352
  /* isImportBlocked */
353
353
 
354
354
  /**
355
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#ISIMPORTBLOCKED
356
- * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
357
- * @param {CommentedDirective} importedFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#IMPORTEDFILECOMMENTEDDIRECTIVE
358
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#ISIMPORTBLOCKED
355
+ * Returns a boolean deciding if an imported file's commented directive is incompatible with the current file's commented directive.
356
+ * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
357
+ * @param {CommentedDirective} importedFileCommentedDirective The imported file's commented directive.
358
+ * @returns `true` if the import is blocked, as established in `commentedDirectives_BlockedImports`.
359
359
  */
360
360
  export const isImportBlocked = (
361
361
  currentFileCommentedDirective,
@@ -370,9 +370,9 @@ export const isImportBlocked = (
370
370
  /* makeMessageFromCurrentFileCommentedDirective */
371
371
 
372
372
  /**
373
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#MAKEMESSAGEFROMCURRENTFILECOMMENTEDDIRECTIVE
374
- * @param {CommentedDirective} commentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#COMMENTEDDIRECTIVE
375
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#MAKEMESSAGEFROMCURRENTFILECOMMENTEDDIRECTIVE
373
+ * Lists in an message the commented modules incompatible with a commented module based on its commented directive.
374
+ * @param {CommentedDirective} commentedDirective The commented directive of the commented module.
375
+ * @returns The message listing the incompatible commented modules.
376
376
  */
377
377
  export const makeMessageFromCurrentFileCommentedDirective = (
378
378
  commentedDirective,
@@ -385,10 +385,10 @@ export const makeMessageFromCurrentFileCommentedDirective = (
385
385
  /* findSpecificViolationMessage */
386
386
 
387
387
  /**
388
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#FINDSPECIFICVIOLATIONMESSAGE
389
- * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
390
- * @param {CommentedDirective} importedFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#IMPORTEDFILECOMMENTEDDIRECTIVE
391
- * @returns $COMMENT#JSDOC#RETURNS#FINDSPECIFICVIOLATIONMESSAGE
388
+ * Finds the `message` for the specific violation of commented directives import rules based on `commentedDirectives_BlockedImports`.
389
+ * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
390
+ * @param {CommentedDirective} importedFileCommentedDirective The imported file's commented directive.
391
+ * @returns The corresponding `message`.
392
392
  */
393
393
  export const findSpecificViolationMessage = (
394
394
  currentFileCommentedDirective,
@@ -12,9 +12,9 @@ import {
12
12
  */
13
13
 
14
14
  /**
15
- * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#MAKEDIRECTIVE21CONFIG
16
- * @param {Plugin} plugin $COMMENT#JSDOC#PARAMS#PLUGIN
17
- * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#MAKEDIRECTIVE21CONFIG
15
+ * Makes the directive21 config for the use-agnostic ESLint plugin.
16
+ * @param {Plugin} plugin The use-agnostic ESLint plugin itself.
17
+ * @returns The directive21 config's name as a key and its config as its value.
18
18
  */
19
19
  export const makeDirective21Config = (plugin) => ({
20
20
  [directive21ConfigName]: defineConfig([
package/library/index.js CHANGED
@@ -165,10 +165,10 @@ export {
165
165
  export { directive21Data } from "../jscomments/_commons/constants/data.js";
166
166
 
167
167
  /**
168
- * $COMMENT#JSDOC#DEFINITIONS#DEFINEDIRECTIVE21
168
+ * Creates the ESLint config object required as the basis for the Directive-First Architecture, linting server-client-agnostic imports based on their commented directives. (Defaults to `"warn"`. You can import and use ```[`${useAgnosticPluginName}/${directive21ConfigName}`]``` later in a further ESLint config object to modify that value.)
169
169
  * @template {string} T
170
- * @param {T} reactFolder $COMMENT#JSDOC#PARAMS#REACTFOLDER
171
- * @returns $COMMENT#JSDOC#RETURNS#DEFINEDIRECTIVE21
170
+ * @param {T} reactFolder The path of the project's React folder where everything React lives, relative to the root of the project. This is, for example, the app directory when using the Next.js App Router, as `"app"`.
171
+ * @returns An ESLint config object that applies `eslint-plugin-use-agnostic`'s `directive21` config by using the provided `reactFolder` as the basis for JavaScript/TypeScript glob patterns.
172
172
  */
173
173
  export const defineDirective21 = (reactFolder) => {
174
174
  /** @type {[`${T}/*\*\/*.tsx`, `${T}/*\*\/*.ts`, `${T}/*\*\/*.jsx`, `${T}/*\*\/*.js`, `${T}/*\*\/*.mjs`, `${T}/*\*\/*.cjs`]} */
@@ -195,13 +195,13 @@ export const defineDirective21 = (reactFolder) => {
195
195
  };
196
196
 
197
197
  /**
198
- * $COMMENT#JSDOC#DEFINITIONS#DEFINECONFIGSETTINGS
198
+ * Defines the config settings for the eXtra JSX VS Code extension as a means to configure `eXtra JSX` directly from ESLint, given the fact that `eslint-plugin-use-agnostic` and `eXtra JSX` have to work together in making the Directive-First Architecture.
199
199
  * @template {string} T
200
200
  * @template {string} U
201
- * @param {Object} settings $COMMENT#JSDOC#PARAMS#SETTINGS
202
- * @param {T} settings.reactFolder $COMMENT#JSDOC#PARAMS#REACTFOLDER
203
- * @param {U} settings.rootPath $COMMENT#JSDOC#PARAMS#ROOTPATH
204
- * @returns $COMMENT#JSDOC#RETURNS#DEFINECONFIGSETTINGS
201
+ * @param {Object} settings The settings as follows:
202
+ * @param {T} settings.reactFolder The path of the project's React folder where everything React lives, relative to the root of the project. This is, for example, the app directory when using the Next.js App Router, as `"app"`.
203
+ * @param {U} settings.rootPath The absolute path of the root of the project, from which the absolute path of the React folder can be easily obtained.
204
+ * @returns The config object responsible for the settings retrieved by the eXtra JSX VS Code extension.
205
205
  */
206
206
  export const defineConfigSettings = ({ reactFolder, rootPath }) => {
207
207
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-use-agnostic",
3
- "version": "2.0.8",
3
+ "version": "2.1.0",
4
4
  "description": "Highlights problematic server-client imports in projects made with the Fullstack React Architecture.",
5
5
  "keywords": [
6
6
  "eslint",