eslint-plugin-use-agnostic 1.6.8 → 1.6.9

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.
@@ -7,9 +7,10 @@ import {
7
7
  EXTENSIONS,
8
8
  reExportNotSameMessageId,
9
9
  importBreaksCommentedImportRulesMessageId,
10
- noCommentedDirective,
11
- commentedDirectiveVerificationFailed,
12
- importNotStrategized,
10
+ noCommentedDirectiveMessageId,
11
+ commentedDirectiveVerificationFailedMessageId,
12
+ importNotStrategizedMessageId,
13
+ cantChainImportAcrossEnvironmentsMessageId,
13
14
  skip,
14
15
  } from "../../../_commons/constants/bases.js";
15
16
  import {
@@ -17,9 +18,12 @@ import {
17
18
  commentedDirectives_verificationReports,
18
19
  // currentFileCommentedDirective,
19
20
  // importedFileCommentedDirective,
21
+ // currentFileEnvironment,
22
+ // importedFileEnvironment,
20
23
  commentedDirectiveMessage,
21
24
  specificViolationMessage,
22
25
  specificFailure,
26
+ environments_allowedChainImportEnvironments,
23
27
  } from "../constants/bases.js";
24
28
 
25
29
  import { highlightFirstLineOfCode } from "../../../_commons/utilities/helpers.js";
@@ -33,6 +37,7 @@ import {
33
37
  getStrategizedDirective,
34
38
  addressDirectiveIfAgnosticStrategies,
35
39
  } from "./helpers.js";
40
+ import { analyzeExportsForReExports } from "./analyze-exports-re.js";
36
41
 
37
42
  /**
38
43
  * @typedef {import('../../../../types/directive21/_commons/typedefs.js').Context} Context
@@ -41,14 +46,15 @@ import {
41
46
  * @typedef {import('../../../../types/directive21/_commons/typedefs.js').ExportNamedDeclaration} ExportNamedDeclaration
42
47
  * @typedef {import('../../../../types/directive21/_commons/typedefs.js').ExportAllDeclaration} ExportAllDeclaration
43
48
  * @typedef {import('../../../../types/directive21/_commons/typedefs.js').ExportDefaultDeclaration} ExportDefaultDeclaration
49
+ * @typedef {import('../../../../types/directive21/_commons/typedefs.js').Environment} Environment
44
50
  */
45
51
 
46
52
  /* currentFileFlow */
47
53
 
48
54
  /**
49
- * 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.
50
- * @param {Context} context The ESLint rule's `context` object.
51
- * @returns Either an object with `skip: true` to disregard or one with the non-null `verifiedCommentedDirective`.
55
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#CURRENTFILEFLOW
56
+ * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
57
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#CURRENTFILEFLOW
52
58
  */
53
59
  export const currentFileFlow = (context) => {
54
60
  const skipTrue = { ...skip, verifiedCommentedDirective: undefined };
@@ -74,7 +80,7 @@ export const currentFileFlow = (context) => {
74
80
  if (!commentedDirective) {
75
81
  context.report({
76
82
  loc: highlightFirstLineOfCode(context),
77
- messageId: noCommentedDirective,
83
+ messageId: noCommentedDirectiveMessageId,
78
84
  });
79
85
  return skipTrue;
80
86
  }
@@ -89,7 +95,7 @@ export const currentFileFlow = (context) => {
89
95
  if (!verifiedCommentedDirective) {
90
96
  context.report({
91
97
  loc: highlightFirstLineOfCode(context),
92
- messageId: commentedDirectiveVerificationFailed,
98
+ messageId: commentedDirectiveVerificationFailedMessageId,
93
99
  data: {
94
100
  [specificFailure]:
95
101
  commentedDirectives_verificationReports[commentedDirective],
@@ -104,13 +110,17 @@ export const currentFileFlow = (context) => {
104
110
  /* importedFileFlow */
105
111
 
106
112
  /**
107
- * The flow that is shared between import and re-export traversals to obtain the import file's commented directive.
108
- * @param {Context} context The ESLint rule's `context` object.
109
- * @param {ImportDeclaration} node The ESLint `node` of the rule's current traversal.
110
- * @returns Either an object with `skip: true` to disregard or one with the non-null `importedFileCommentedDirective`.
113
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#IMPORTEDFILEFLOW
114
+ * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
115
+ * @param {ImportDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
116
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#IMPORTEDFILEFLOW (And now we the added results of `analyzeExportsForReExports`.)
111
117
  */
112
118
  const importedFileFlow = (context, node) => {
113
- const skipTrue = { ...skip, importedFileCommentedDirective: undefined };
119
+ const skipTrue = {
120
+ ...skip,
121
+ importedFileCommentedDirective: undefined,
122
+ analyzeExportsForReExportsResults: undefined,
123
+ };
114
124
 
115
125
  // finds the full path of the import
116
126
  const resolvedImportPath = resolveImportingPath(
@@ -130,15 +140,17 @@ const importedFileFlow = (context, node) => {
130
140
  if (!isImportedFileJS) return skipTrue;
131
141
 
132
142
  // GETTING THE DIRECTIVE (or lack thereof) OF THE IMPORTED FILE
133
- let importedFileCommentedDirective =
134
- getCommentedDirectiveFromImportedModule(resolvedImportPath);
143
+ let {
144
+ commentedDirective: importedFileCommentedDirective,
145
+ sourceCode: importedFileSourceCode,
146
+ } = getCommentedDirectiveFromImportedModule(resolvedImportPath);
135
147
 
136
148
  // returns early if there is no directive or no valid directive (same, but eventually no directive could have defaults)
137
149
  if (!importedFileCommentedDirective) {
138
150
  // 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.
139
151
 
140
152
  // console.warn(
141
- // `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.`
153
+ // `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.`
142
154
  // ); // The decision not to report has been taken to not inflate the number of warnings.
143
155
  return skipTrue;
144
156
  }
@@ -160,7 +172,7 @@ const importedFileFlow = (context, node) => {
160
172
  if (importingFileCommentedDirective === null) {
161
173
  context.report({
162
174
  node,
163
- messageId: importNotStrategized,
175
+ messageId: importNotStrategizedMessageId,
164
176
  });
165
177
  return skipTrue;
166
178
  }
@@ -169,17 +181,37 @@ const importedFileFlow = (context, node) => {
169
181
  importedFileCommentedDirective = importingFileCommentedDirective;
170
182
  }
171
183
 
172
- return { skip: undefined, importedFileCommentedDirective };
184
+ // you never know
185
+ if (!importedFileSourceCode) {
186
+ console.warn(
187
+ `Somehow, file "${resolvedImportPath}" does not have a SourceCode object obtainable.`
188
+ );
189
+ return {
190
+ skip: undefined,
191
+ importedFileCommentedDirective,
192
+ analyzeExportsForReExportsResults: undefined,
193
+ };
194
+ }
195
+
196
+ const analyzeExportsForReExportsResults = analyzeExportsForReExports(
197
+ importedFileSourceCode
198
+ );
199
+
200
+ return {
201
+ skip: undefined,
202
+ importedFileCommentedDirective,
203
+ analyzeExportsForReExportsResults,
204
+ };
173
205
  };
174
206
 
175
207
  /* importsFlow */
176
208
 
177
209
  /**
178
- * The full flow for import traversals to enforce effective directives import rules.
179
- * @param {Context} context The ESLint rule's `context` object.
180
- * @param {ImportDeclaration} node The ESLint `node` of the rule's current traversal.
181
- * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
182
- * @returns Early if the flow needs to be interrupted.
210
+ * $COMMENT#JSDOC#FORALIASVARIABLES#IMPORTSFLOW
211
+ * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
212
+ * @param {ImportDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
213
+ * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
214
+ * @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
183
215
  */
184
216
  export const importsFlow = (context, node, currentFileCommentedDirective) => {
185
217
  // does not operate on `import type`
@@ -214,22 +246,73 @@ export const importsFlow = (context, node, currentFileCommentedDirective) => {
214
246
  },
215
247
  });
216
248
  }
249
+
250
+ // new
251
+ if (result.analyzeExportsForReExportsResults) {
252
+ const { reExportsWithSource, reExportsViaLocal } =
253
+ result.analyzeExportsForReExportsResults;
254
+ // console.debug("reExportsWithSource are:", reExportsWithSource);
255
+ // console.debug("reExportsViaLocal are:", reExportsViaLocal);
256
+ // console.debug(
257
+ // "currentFileCommentedDirective is:",
258
+ // currentFileCommentedDirective
259
+ // );
260
+ // console.debug(
261
+ // "importedFileCommentedDirective is:",
262
+ // importedFileCommentedDirective
263
+ // );
264
+ // console.debug(context.sourceCode.getText(node));
265
+
266
+ // immediately returns if no re-exports are found
267
+ if (reExportsWithSource.length === 0 && reExportsViaLocal.length === 0)
268
+ return;
269
+
270
+ /** @type {Environment} */
271
+ const currentFileEnvironment = currentFileCommentedDirective.split(" ")[1];
272
+ /** @type {Environment} */
273
+ const importedFileEnvironment =
274
+ importedFileCommentedDirective.split(" ")[1];
275
+ // console.debug("currentFileEnvironment is:", currentFileEnvironment);
276
+ // console.debug("importedFileEnvironment is:", importedFileEnvironment);
277
+
278
+ if (
279
+ !environments_allowedChainImportEnvironments[
280
+ currentFileEnvironment
281
+ ].includes(importedFileEnvironment)
282
+ ) {
283
+ // console.debug(cantChainImportAcrossEnvironmentsMessageId);
284
+
285
+ context.report({
286
+ node,
287
+ messageId: cantChainImportAcrossEnvironmentsMessageId,
288
+ data: {
289
+ // currentFileEnvironment:
290
+ currentFileEnvironment,
291
+ // importedFileEnvironment:
292
+ importedFileEnvironment,
293
+ },
294
+ });
295
+ }
296
+ }
217
297
  };
218
298
 
219
299
  /* allExportsFlow */
220
300
 
221
301
  /**
222
- * 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.
223
- * @param {Context} context The ESLint rule's `context` object.
224
- * @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node The ESLint `node` of the rule's current traversal.
225
- * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
226
- * @returns Early if the flow needs to be interrupted.
302
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#ALLEXPORTSFLOW
303
+ * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
304
+ * @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
305
+ * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
306
+ * @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
227
307
  */
228
308
  export const allExportsFlow = (
229
309
  context,
230
310
  node,
231
311
  currentFileCommentedDirective
232
312
  ) => {
313
+ // saving the original commented directive (speficially for "use agnostic strategies")
314
+ const originalCurrentFileCommentedDirective = currentFileCommentedDirective;
315
+
233
316
  // does not operate on `export type`
234
317
  if (node.exportKind === "type") return;
235
318
 
@@ -271,5 +354,56 @@ export const allExportsFlow = (
271
354
  },
272
355
  });
273
356
  }
357
+
358
+ // new
359
+ if (result.analyzeExportsForReExportsResults) {
360
+ const { reExportsWithSource, reExportsViaLocal } =
361
+ result.analyzeExportsForReExportsResults;
362
+ // console.debug("reExportsWithSource are:", reExportsWithSource);
363
+ // console.debug("reExportsViaLocal are:", reExportsViaLocal);
364
+ // console.debug(
365
+ // "currentFileCommentedDirective is:",
366
+ // currentFileCommentedDirective
367
+ // );
368
+ // console.debug(
369
+ // "importedFileCommentedDirective is:",
370
+ // importedFileCommentedDirective
371
+ // );
372
+ // console.debug(context.sourceCode.getText(node));
373
+
374
+ // immediately returns if no re-exports are found
375
+ if (reExportsWithSource.length === 0 && reExportsViaLocal.length === 0)
376
+ return;
377
+
378
+ if (originalCurrentFileCommentedDirective !== USE_AGNOSTIC_STRATEGIES) {
379
+ /** @type {Environment} */
380
+ const currentFileEnvironment =
381
+ currentFileCommentedDirective.split(" ")[1];
382
+ /** @type {Environment} */
383
+ const importedFileEnvironment =
384
+ importedFileCommentedDirective.split(" ")[1];
385
+ // console.debug("currentFileEnvironment is:", currentFileEnvironment);
386
+ // console.debug("importedFileEnvironment is:", importedFileEnvironment);
387
+
388
+ if (
389
+ !environments_allowedChainImportEnvironments[
390
+ currentFileEnvironment
391
+ ].includes(importedFileEnvironment)
392
+ ) {
393
+ // console.debug(cantChainImportAcrossEnvironmentsMessageId);
394
+
395
+ context.report({
396
+ node,
397
+ messageId: cantChainImportAcrossEnvironmentsMessageId,
398
+ data: {
399
+ // currentFileEnvironment:
400
+ currentFileEnvironment,
401
+ // importedFileEnvironment:
402
+ importedFileEnvironment,
403
+ },
404
+ });
405
+ }
406
+ }
407
+ }
274
408
  }
275
409
  };
@@ -1,6 +1,6 @@
1
1
  import { getSourceCodeFromFilePath } from "get-sourcecode-from-file-path";
2
2
 
3
- import { exportNotStrategized } from "../../../_commons/constants/bases.js";
3
+ import { exportNotStrategizedMessageId } from "../../../_commons/constants/bases.js";
4
4
  import {
5
5
  USE_AGNOSTIC_STRATEGIES,
6
6
  commentedDirectivesArray,
@@ -31,9 +31,9 @@ import {
31
31
  /* getCommentedDirectiveFromSourceCode */
32
32
 
33
33
  /**
34
- * Detects whether a string is single- or double-quoted.
35
- * @param {string} string The original string.
36
- * @returns `true` if single-quoted, `false` if double-quoted, `null` if neither.
34
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#DETECTQUOTETYPE
35
+ * @param {string} string $COMMENT#JSDOC#PARAMS#DIRECTIVE21#STRING
36
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#DETECTQUOTETYPE
37
37
  */
38
38
  const detectQuoteType = (string) => {
39
39
  if (string.startsWith("'") && string.endsWith("'")) {
@@ -46,9 +46,9 @@ const detectQuoteType = (string) => {
46
46
  };
47
47
 
48
48
  /**
49
- * Removes single quotes from a string known to be single-quoted.
50
- * @param {string} string The original string.
51
- * @returns The string with quotes removed.
49
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#STRIPSINGLEQUOTES
50
+ * @param {string} string $COMMENT#JSDOC#PARAMS#DIRECTIVE21#STRING
51
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#STRIPSINGLEQUOTES
52
52
  */
53
53
  const stripSingleQuotes = (string) => {
54
54
  if (string.startsWith("'") && string.endsWith("'")) {
@@ -58,9 +58,9 @@ const stripSingleQuotes = (string) => {
58
58
  };
59
59
 
60
60
  /**
61
- * Removes double quotes from a string known to be double-quoted.
62
- * @param {string} string The original string.
63
- * @returns The string with quotes removed.
61
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#STRIPDOUBLEQUOTES
62
+ * @param {string} string $COMMENT#JSDOC#PARAMS#DIRECTIVE21#STRING
63
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#STRIPSINGLEQUOTES
64
64
  */
65
65
  const stripDoubleQuotes = (string) => {
66
66
  if (string.startsWith('"') && string.endsWith('"')) {
@@ -70,21 +70,21 @@ const stripDoubleQuotes = (string) => {
70
70
  };
71
71
 
72
72
  /**
73
- * Gets the commented directive of a module from its ESLint `SourceCode` object.
73
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE1
74
74
  *
75
- * Accepted directives for the default Directive-First Architecture are (single or double quotes included):
76
- * - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
77
- * - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
78
- * - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
79
- * - `'use server components'`, `"use server components"` denoting a Server Components Module.
80
- * - `'use client components'`, `"use client components"` denoting a Client Components Module.
81
- * - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
82
- * - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
83
- * - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
84
- * - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
85
- * - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
86
- * @param {SourceCode} sourceCode The ESLint SourceCode object.
87
- * @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.)
75
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE2
76
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERLOGICSA
77
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTLOGICSA
78
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICLOGICSA
79
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERCOMPONENTSA
80
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCOMPONENTSA
81
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCOMPONENTSA
82
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERFUNCTIONSA
83
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCONTEXTSA
84
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCONDITIONSA
85
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICSTRATEGIESA
86
+ * @param {SourceCode} sourceCode $COMMENT#JSDOC#PARAMS#DIRECTIVE21#SOURCECODE
87
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE
88
88
  */
89
89
  export const getCommentedDirectiveFromSourceCode = (sourceCode) => {
90
90
  // gets all comments from the source code
@@ -132,21 +132,21 @@ export const getCommentedDirectiveFromSourceCode = (sourceCode) => {
132
132
  /* getCommentedDirectiveFromCurrentModule */
133
133
 
134
134
  /**
135
- * Gets the commented directive of the current module.
135
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMCURRENTMODULE1
136
136
  *
137
- * Accepted directives for the default Directive-First Architecture are (single or double quotes included):
138
- * - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
139
- * - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
140
- * - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
141
- * - `'use server components'`, `"use server components"` denoting a Server Components Module.
142
- * - `'use client components'`, `"use client components"` denoting a Client Components Module.
143
- * - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
144
- * - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
145
- * - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
146
- * - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
147
- * - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
148
- * @param {Context} context The ESLint rule's `context` object.
149
- * @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.)
137
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE2
138
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERLOGICSA
139
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTLOGICSA
140
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICLOGICSA
141
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERCOMPONENTSA
142
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCOMPONENTSA
143
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCOMPONENTSA
144
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERFUNCTIONSA
145
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCONTEXTSA
146
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCONDITIONSA
147
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICSTRATEGIESA
148
+ * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
149
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE
150
150
  */
151
151
  export const getCommentedDirectiveFromCurrentModule = (context) => {
152
152
  const sourceCode = context.sourceCode;
@@ -158,46 +158,46 @@ export const getCommentedDirectiveFromCurrentModule = (context) => {
158
158
  /* getCommentedDirectiveFromImportedModule */
159
159
 
160
160
  /**
161
- * Gets the commented directive of the imported module.
161
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMIMPORTEDMODULE1
162
162
  *
163
- * Accepted directives for the default Directive-First Architecture are (single or double quotes included):
164
- * - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
165
- * - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
166
- * - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
167
- * - `'use server components'`, `"use server components"` denoting a Server Components Module.
168
- * - `'use client components'`, `"use client components"` denoting a Client Components Module.
169
- * - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
170
- * - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
171
- * - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
172
- * - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
173
- * - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
174
- * @param {string} resolvedPath The resolved path of the imported module.
175
- * @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.)
163
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE2
164
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERLOGICSA
165
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTLOGICSA
166
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICLOGICSA
167
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERCOMPONENTSA
168
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCOMPONENTSA
169
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCOMPONENTSA
170
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERFUNCTIONSA
171
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCONTEXTSA
172
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCONDITIONSA
173
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICSTRATEGIESA
174
+ * @param {string} resolvedPath $COMMENT#JSDOC#PARAMS#RESOLVEDPATH
175
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE Now also provides the obtained SourceCode object.
176
176
  */
177
177
  export const getCommentedDirectiveFromImportedModule = (resolvedPath) => {
178
178
  const sourceCode = getSourceCodeFromFilePath(resolvedPath);
179
179
  const commentedDirective = getCommentedDirectiveFromSourceCode(sourceCode);
180
180
 
181
- return commentedDirective;
181
+ return { commentedDirective, sourceCode };
182
182
  };
183
183
 
184
184
  /* getVerifiedCommentedDirective */
185
185
 
186
186
  /**
187
- * Ensures that a module's commented directive is consistent with its file extension (depending on whether it ends with 'x' for JSX).
188
- * - `'use server logics'`: Server Logics Modules do NOT export JSX.
189
- * - `'use client logics'`: Client Logics Modules do NOT export JSX.
190
- * - `'use agnostic logics'`: Agnostic Logics Modules do NOT export JSX.
191
- * - `'use server components'`: Server Components Modules ONLY export JSX.
192
- * - `'use client components'`: Client Components Modules ONLY export JSX.
193
- * - `'use agnostic components'`: Agnostic Components Modules ONLY export JSX.
194
- * - `'use server functions'`: Server Functions Modules do NOT export JSX.
195
- * - `'use client contexts'`: Client Contexts Modules ONLY export JSX.
196
- * - `'use agnostic conditions'`: Agnostic Conditions Modules ONLY export JSX.
197
- * - `'use agnostic strategies'`: Agnostic Strategies Modules may export JSX.
198
- * @param {CommentedDirective} directive The commented directive as written on top of the file (cannot be `null` at that stage).
199
- * @param {Extension} extension The JavaScript (TypeScript) extension of the file.
200
- * @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.
187
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETVERIFIEDCOMMENTEDDIRECTIVE
188
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERLOGICSB
189
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTLOGICSB
190
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICLOGICSB
191
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERCOMPONENTSB
192
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCOMPONENTSB
193
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCOMPONENTSB
194
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERFUNCTIONSB
195
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCONTEXTSB
196
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCONDITIONSB
197
+ * - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICSTRATEGIESB
198
+ * @param {CommentedDirective} directive $COMMENT#JSDOC#PARAMS#DIRECTIVE21#DIRECTIVE
199
+ * @param {Extension} extension $COMMENT#JSDOC#PARAMS#EXTENSION
200
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETVERIFIEDCOMMENTEDDIRECTIVE
201
201
  */
202
202
  export const getVerifiedCommentedDirective = (directive, extension) => {
203
203
  const rule = commentedDirectives_extensionRules[directive];
@@ -214,10 +214,10 @@ export const getVerifiedCommentedDirective = (directive, extension) => {
214
214
  /* getStrategizedDirective */
215
215
 
216
216
  /**
217
- * 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.
218
- * @param {Context} context The ESLint rule's `context` object.
219
- * @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node The ESLint `node` of the rule's current traversal.
220
- * @returns The interpreted directive, a.k.a. strategized directive, or lack thereof via `null`.
217
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETSTRATEGIZEDDIRECTIVE
218
+ * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
219
+ * @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
220
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETSTRATEGIZEDDIRECTIVE
221
221
  */
222
222
  export const getStrategizedDirective = (context, node) => {
223
223
  // gets the first nested `/* */` comment inside the node
@@ -246,11 +246,11 @@ export const getStrategizedDirective = (context, node) => {
246
246
  /* addressDirectiveIfAgnosticStrategies */
247
247
 
248
248
  /**
249
- * 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.
250
- * @param {Context} context The ESLint rule's `context` object.
251
- * @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node The ESLint `node` of the rule's current traversal.
252
- * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
253
- * @returns The commented directive, the addressed strategy (as a commented directive) or `null` in case of failure.
249
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#ADDRESSDIRECTIVEIFAGNOSTICSTRATEGIES
250
+ * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
251
+ * @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
252
+ * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
253
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#ADDRESSDIRECTIVEIFAGNOSTICSTRATEGIES
254
254
  */
255
255
  export const addressDirectiveIfAgnosticStrategies = (
256
256
  context,
@@ -266,7 +266,7 @@ export const addressDirectiveIfAgnosticStrategies = (
266
266
  if (exportStrategizedDirective === null) {
267
267
  context.report({
268
268
  node,
269
- messageId: exportNotStrategized,
269
+ messageId: exportNotStrategizedMessageId,
270
270
  });
271
271
  }
272
272
 
@@ -276,10 +276,10 @@ export const addressDirectiveIfAgnosticStrategies = (
276
276
  /* isImportBlocked */
277
277
 
278
278
  /**
279
- * Returns a boolean deciding if an imported file's commented directive is incompatible with the current file's commented directive.
280
- * @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective The current file's commented directive.
281
- * @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective The imported file's commented directive.
282
- * @returns `true` if the import is blocked, as established in `commentedDirectives_BlockedImports`.
279
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#ISIMPORTBLOCKED
280
+ * @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
281
+ * @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#IMPORTEDFILECOMMENTEDDIRECTIVE
282
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#ISIMPORTBLOCKED
283
283
  */
284
284
  export const isImportBlocked = (
285
285
  currentFileCommentedDirective,
@@ -294,9 +294,9 @@ export const isImportBlocked = (
294
294
  /* makeMessageFromCurrentFileCommentedDirective */
295
295
 
296
296
  /**
297
- * Lists in an message the commented modules incompatible with a commented module based on its commented directive.
298
- * @param {CommentedDirectiveWithoutUseAgnosticStrategies} commentedDirective The commented directive of the commented module.
299
- * @returns The message listing the incompatible commented modules.
297
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#MAKEMESSAGEFROMCURRENTFILECOMMENTEDDIRECTIVE
298
+ * @param {CommentedDirectiveWithoutUseAgnosticStrategies} commentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#COMMENTEDDIRECTIVE
299
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#MAKEMESSAGEFROMCURRENTFILECOMMENTEDDIRECTIVE
300
300
  */
301
301
  export const makeMessageFromCurrentFileCommentedDirective = (
302
302
  commentedDirective
@@ -309,10 +309,10 @@ export const makeMessageFromCurrentFileCommentedDirective = (
309
309
  /* findSpecificViolationMessage */
310
310
 
311
311
  /**
312
- * Finds the `message` for the specific violation of commented directives import rules based on `commentedDirectives_BlockedImports`.
313
- * @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective The current file's commented directive.
314
- * @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective The imported file's commented directive.
315
- * @returns The corresponding `message`.
312
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#FINDSPECIFICVIOLATIONMESSAGE
313
+ * @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
314
+ * @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#IMPORTEDFILECOMMENTEDDIRECTIVE
315
+ * @returns $COMMENT#JSDOC#RETURNS#FINDSPECIFICVIOLATIONMESSAGE
316
316
  */
317
317
  export const findSpecificViolationMessage = (
318
318
  currentFileCommentedDirective,
@@ -12,9 +12,9 @@ import {
12
12
  */
13
13
 
14
14
  /**
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.
15
+ * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#MAKEDIRECTIVE21CONFIG
16
+ * @param {Plugin} plugin $COMMENT#JSDOC#PARAMS#PLUGIN
17
+ * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#MAKEDIRECTIVE21CONFIG
18
18
  */
19
19
  export const makeDirective21Config = (plugin) => ({
20
20
  [directive21ConfigName]: defineConfig([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-use-agnostic",
3
- "version": "1.6.8",
3
+ "version": "1.6.9",
4
4
  "description": "Highlights problematic server-client imports in projects made with the Fullstack React Architecture.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "find-up": "^8.0.0",
47
- "get-sourcecode-from-file-path": "^1.1.2",
47
+ "get-sourcecode-from-file-path": "^1.1.3",
48
48
  "resolve-importing-path": "^1.0.3",
49
49
  "typescript-eslint": "^8.32.0"
50
50
  },