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.
- package/comments.config.json +4 -0
- package/comments.config.mjs +5 -1
- package/jscomments/jsdoc/comments.js +2 -0
- package/library/_commons/utilities/helpers.js +24 -24
- package/library/_commons/utilities/walk-ast.js +8 -8
- package/library/agnostic20/_commons/constants/bases.js +57 -57
- package/library/agnostic20/_commons/utilities/flows.js +26 -26
- package/library/agnostic20/_commons/utilities/helpers.js +43 -43
- package/library/agnostic20/config.js +3 -3
- package/library/directive21/_commons/constants/bases.js +105 -105
- package/library/directive21/_commons/rules/import-rules.js +18 -7
- package/library/directive21/_commons/utilities/analyze-exports-re.js +3 -3
- package/library/directive21/_commons/utilities/flows.js +61 -83
- package/library/directive21/_commons/utilities/helpers.js +85 -85
- package/library/directive21/config.js +3 -3
- package/library/index.js +8 -8
- package/package.json +1 -1
- package/types/index.d.ts +114 -114
|
@@ -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
|
-
*
|
|
138
|
-
* @param {Context} context
|
|
139
|
-
* @returns
|
|
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
|
-
*
|
|
236
|
-
* @param {Context} context
|
|
237
|
-
* @param {ImportDeclaration} node
|
|
238
|
-
* @param {ResolverFactory} resolver
|
|
239
|
-
* @returns
|
|
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
|
-
|
|
250
|
-
|
|
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
|
|
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
|
-
*
|
|
344
|
-
* @param {Context} context
|
|
345
|
-
* @param {CallExpression} node
|
|
346
|
-
* @param {ResolverFactory} resolver
|
|
347
|
-
* @returns
|
|
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
|
-
|
|
368
|
-
|
|
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
|
|
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
|
-
*
|
|
461
|
-
* @param {Context} context
|
|
462
|
-
* @param {ImportDeclaration} node
|
|
463
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
464
|
-
* @param {ResolverFactory} resolver
|
|
465
|
-
* @returns
|
|
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
|
-
*
|
|
544
|
-
* @param {Context} context
|
|
545
|
-
* @param {CallExpression} node
|
|
546
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
547
|
-
* @param {ResolverFactory} resolver
|
|
548
|
-
* @returns
|
|
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
|
-
*
|
|
625
|
-
* @param {Context} context
|
|
626
|
-
* @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node
|
|
627
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
628
|
-
* @param {ResolverFactory} resolver
|
|
629
|
-
* @returns
|
|
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
|
|
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
|
|
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
|
-
*
|
|
754
|
-
* @param {string} name
|
|
755
|
-
* @returns
|
|
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
|
-
*
|
|
764
|
-
* @param {Parameter[]} params
|
|
765
|
-
* @returns
|
|
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
|
-
*
|
|
787
|
-
* @param {Context} context
|
|
788
|
-
* @param {FunctionDeclaration} node
|
|
789
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
790
|
-
* @returns
|
|
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
|
-
*
|
|
833
|
-
* @param {Context} context
|
|
834
|
-
* @param {JSXElement} node
|
|
835
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
836
|
-
* @returns
|
|
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
|
-
*
|
|
868
|
-
* @param {Context} context
|
|
869
|
-
* @param {JSXOpeningElement} node
|
|
870
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
871
|
-
* @returns
|
|
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
|
-
*
|
|
34
|
-
* @param {string} string
|
|
35
|
-
* @returns
|
|
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
|
-
*
|
|
49
|
-
* @param {string} string
|
|
50
|
-
* @returns
|
|
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
|
-
*
|
|
61
|
-
* @param {string} string
|
|
62
|
-
* @returns
|
|
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
|
-
*
|
|
72
|
+
* Gets the commented directive of a module from its ESLint `SourceCode` object.
|
|
73
73
|
*
|
|
74
|
-
*
|
|
75
|
-
* -
|
|
76
|
-
* -
|
|
77
|
-
* -
|
|
78
|
-
* -
|
|
79
|
-
* -
|
|
80
|
-
* -
|
|
81
|
-
* -
|
|
82
|
-
* -
|
|
83
|
-
* -
|
|
84
|
-
* -
|
|
85
|
-
* @param {SourceCode} sourceCode
|
|
86
|
-
* @returns
|
|
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
|
-
*
|
|
137
|
+
* Gets the commented directive of the current module.
|
|
138
138
|
*
|
|
139
|
-
*
|
|
140
|
-
* -
|
|
141
|
-
* -
|
|
142
|
-
* -
|
|
143
|
-
* -
|
|
144
|
-
* -
|
|
145
|
-
* -
|
|
146
|
-
* -
|
|
147
|
-
* -
|
|
148
|
-
* -
|
|
149
|
-
* -
|
|
150
|
-
* @param {Context} context
|
|
151
|
-
* @returns
|
|
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
|
-
*
|
|
166
|
+
* Gets the commented directive of the imported module.
|
|
167
167
|
*
|
|
168
|
-
*
|
|
169
|
-
* -
|
|
170
|
-
* -
|
|
171
|
-
* -
|
|
172
|
-
* -
|
|
173
|
-
* -
|
|
174
|
-
* -
|
|
175
|
-
* -
|
|
176
|
-
* -
|
|
177
|
-
* -
|
|
178
|
-
* -
|
|
179
|
-
* @param {string} resolvedPath
|
|
180
|
-
* @returns
|
|
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
|
-
*
|
|
196
|
-
* -
|
|
197
|
-
* -
|
|
198
|
-
* -
|
|
199
|
-
* -
|
|
200
|
-
* -
|
|
201
|
-
* -
|
|
202
|
-
* -
|
|
203
|
-
* -
|
|
204
|
-
* -
|
|
205
|
-
* -
|
|
206
|
-
* @param {CommentedDirective} directive
|
|
207
|
-
* @param {Extension} extension
|
|
208
|
-
* @returns
|
|
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
|
-
*
|
|
226
|
-
* @param {Context} context
|
|
227
|
-
* @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node
|
|
228
|
-
* @returns
|
|
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
|
-
*
|
|
318
|
-
* @param {Context} context
|
|
319
|
-
* @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node
|
|
320
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
321
|
-
* @returns
|
|
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
|
-
*
|
|
356
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
357
|
-
* @param {CommentedDirective} importedFileCommentedDirective
|
|
358
|
-
* @returns
|
|
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
|
-
*
|
|
374
|
-
* @param {CommentedDirective} commentedDirective
|
|
375
|
-
* @returns
|
|
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
|
-
*
|
|
389
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
390
|
-
* @param {CommentedDirective} importedFileCommentedDirective
|
|
391
|
-
* @returns
|
|
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
|
-
*
|
|
16
|
-
* @param {Plugin} plugin
|
|
17
|
-
* @returns
|
|
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
|
-
*
|
|
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
|
|
171
|
-
* @returns
|
|
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
|
-
*
|
|
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
|
|
202
|
-
* @param {T} settings.reactFolder
|
|
203
|
-
* @param {U} settings.rootPath
|
|
204
|
-
* @returns
|
|
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
|
/**
|