eslint-plugin-use-agnostic 1.6.10 → 1.7.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 +46 -2
- package/comments.config.mjs +47 -3
- package/jscomments/jsdoc/comments.js +14 -2
- package/jscomments/jsdoc/composed-variables.js +2 -0
- package/library/_commons/utilities/helpers.js +21 -21
- package/library/_commons/utilities/walk-ast.js +6 -6
- package/library/agnostic20/_commons/constants/bases.js +57 -57
- package/library/agnostic20/_commons/utilities/flows.js +17 -17
- package/library/agnostic20/_commons/utilities/helpers.js +43 -43
- package/library/agnostic20/config.js +3 -3
- package/library/directive21/_commons/constants/bases.js +85 -85
- package/library/directive21/_commons/utilities/analyze-exports-re.js +3 -7
- package/library/directive21/_commons/utilities/flows.js +22 -52
- package/library/directive21/_commons/utilities/helpers.js +85 -85
- package/library/directive21/config.js +3 -3
- package/package.json +1 -1
- package/types/index.d.ts +100 -100
|
@@ -15,6 +15,10 @@ export const jsDocComments = Object.freeze({
|
|
|
15
15
|
"$COMMENT#JSDOC#FORCOMPOSEDVARIABLES#LISTSINMESSAGE $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#RESOLVED $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#MODULESINCOMPATIBLE $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#RESOLVED $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#MODULEBASEDON $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#RESOLVED $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#DIRECTIVEPERIOD" /* $COMMENT#JSDOC#DEFINITIONS#MAKEMESSAGEFROMCURRENTFILERESOLVEDDIRECTIVE */,
|
|
16
16
|
findSpecificViolationMessage:
|
|
17
17
|
"$COMMENT#JSDOC#FORCOMPOSEDVARIABLES#FINDTHEMESSAGE $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#RESOLVED $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#RULESBASEDON $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#RDBIPERIOD" /* $COMMENT#JSDOC#DEFINITIONS#FINDSPECIFICVIOLATIONMESSAGE */,
|
|
18
|
+
walkAST: "Walks an AST with a given callback." /* $COMMENT#JSDOC#DEFINITIONS#WALKAST */,
|
|
19
|
+
visitNode: "Recursively visits an AST node with a given callback." /* $COMMENT#JSDOC#DEFINITIONS#VISITNODE */,
|
|
20
|
+
analyzeExportsForReExports:
|
|
21
|
+
"Analyzes a source code's exports to detect re-exports." /* $COMMENT#JSDOC#DEFINITIONS#ANALYZEEXPORTSFORREEXPORTS */,
|
|
18
22
|
agnostic20: Object.freeze({
|
|
19
23
|
makeAgnostic20Config:
|
|
20
24
|
"$COMMENT#JSDOC#FORCOMPOSEDVARIABLES#MAKESTHE $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#AGNOSTIC20 $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#CONFIGFORPLUGIN" /* $COMMENT#JSDOC#DEFINITIONS#AGNOSTIC20#MAKEAGNOSTIC20CONFIG */,
|
|
@@ -126,6 +130,12 @@ export const jsDocComments = Object.freeze({
|
|
|
126
130
|
extension:
|
|
127
131
|
"The JavaScript (TypeScript) extension of the file." /* $COMMENT#JSDOC#PARAMS#EXTENSION */,
|
|
128
132
|
node: "The ESLint `node` of the rule's current traversal." /* $COMMENT#JSDOC#PARAMS#NODE */,
|
|
133
|
+
sourceCodeA: "The `SourceCode` where the AST comes from." /* $COMMENT#JSDOC#PARAMS#SOURCECODEA */,
|
|
134
|
+
callback: "The callback that runs during the walk." /* $COMMENT#JSDOC#PARAMS#CALLBACK */,
|
|
135
|
+
nodeB: "The node being visited." /* $COMMENT#JSDOC#PARAMS#NODEB */,
|
|
136
|
+
parent: "The parent of the node being visited." /* $COMMENT#JSDOC#PARAMS#PARENT */,
|
|
137
|
+
visitorKeys: "The visitor keys of the node being visited." /* $COMMENT#JSDOC#PARAMS#VISITORKEYS */,
|
|
138
|
+
sourceCodeB: "The `SourceCode` to analyze." /* $COMMENT#JSDOC#PARAMS#SOURCECODEB */,
|
|
129
139
|
agnostic20: Object.freeze({
|
|
130
140
|
currentFileEffectiveDirective:
|
|
131
141
|
"$COMMENT#JSDOC#FORCOMPOSEDVARIABLES#THECURRENTFILE $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#EFFECTIVE $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#DIRECTIVEPERIOD" /* $COMMENT#JSDOC#PARAMS#AGNOSTIC20#CURRENTFILEEFFECTIVEDIRECTIVE */,
|
|
@@ -245,6 +255,8 @@ export const jsDocComments = Object.freeze({
|
|
|
245
255
|
"$COMMENT#JSDOC#FORCOMPOSEDVARIABLES#THEMESSAGELISTING $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#RESOLVED $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#MODULESPERIOD" /* $COMMENT#JSDOC#RETURNS#MAKEMESSAGEFROMCURRENTFILERESOLVEDDIRECTIVE */,
|
|
246
256
|
findSpecificViolationMessage:
|
|
247
257
|
"The corresponding `message`." /* $COMMENT#JSDOC#RETURNS#FINDSPECIFICVIOLATIONMESSAGE */,
|
|
258
|
+
analyzeExportsForReExports:
|
|
259
|
+
"An object with the `reExportsWithSource` key tracking the direct re-exports from an imported source in an array and the `reExportsViaLocal` key tracking the indirect re-exports from an imported source in an array." /* $COMMENT#JSDOC#RETURNS#ANALYZEEXPORTSFORREEXPORTS */,
|
|
248
260
|
agnostic20: Object.freeze({
|
|
249
261
|
makeAgnostic20Config:
|
|
250
262
|
"$COMMENT#JSDOC#FORCOMPOSEDVARIABLES#INITIALTHE $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#AGNOSTIC20 $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#CONFIGSNAME" /* $COMMENT#JSDOC#RETURNS#AGNOSTIC20#MAKEAGNOSTIC20CONFIG */,
|
|
@@ -291,7 +303,7 @@ export const jsDocComments = Object.freeze({
|
|
|
291
303
|
getCommentedDirectiveFromCurrentModule:
|
|
292
304
|
"JSDOC#RETURNS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE" /* $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMCURRENTMODULE */,
|
|
293
305
|
getCommentedDirectiveFromImportedModule:
|
|
294
|
-
"
|
|
306
|
+
"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.)" /* $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMIMPORTEDMODULE */,
|
|
295
307
|
getVerifiedCommentedDirective:
|
|
296
308
|
"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." /* $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETVERIFIEDCOMMENTEDDIRECTIVE */,
|
|
297
309
|
getStrategizedDirective:
|
|
@@ -307,7 +319,7 @@ export const jsDocComments = Object.freeze({
|
|
|
307
319
|
currentFileFlow:
|
|
308
320
|
"$COMMENT#JSDOC#FORCOMPOSEDVARIABLES#EITHERSKIPTRUENONNULL $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#VCDPERIOD" /* $COMMENT#JSDOC#RETURNS#DIRECTIVE21#CURRENTFILEFLOW */,
|
|
309
321
|
importedFileFlow:
|
|
310
|
-
"$COMMENT#JSDOC#FORCOMPOSEDVARIABLES#EITHERSKIPTRUENONNULL $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#IFCDPERIOD" /* $COMMENT#JSDOC#RETURNS#DIRECTIVE21#IMPORTEDFILEFLOW */,
|
|
322
|
+
"$COMMENT#JSDOC#FORCOMPOSEDVARIABLES#EITHERSKIPTRUENONNULL $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#IFCDPERIOD $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#ANALYZEEXPORTSFORREEXPORTSRESULTS" /* $COMMENT#JSDOC#RETURNS#DIRECTIVE21#IMPORTEDFILEFLOW */,
|
|
311
323
|
importsFlow:
|
|
312
324
|
"JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY" /* $COMMENT#JSDOC#RETURNS#DIRECTIVE21#IMPORTSFLOW */,
|
|
313
325
|
allExportsFlow:
|
|
@@ -99,4 +99,6 @@ export const forComposedVariables = Object.freeze({
|
|
|
99
99
|
"`verifiedCommentedDirective`." /* $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#VCDPERIOD */,
|
|
100
100
|
ifcdPeriod:
|
|
101
101
|
"`importedFileCommentedDirective`." /* $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#IFCDPERIOD */,
|
|
102
|
+
analyzeExportsForReExportsResults:
|
|
103
|
+
"And now with the added results of `analyzeExportsForReExports`." /* $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#ANALYZEEXPORTSFORREEXPORTSRESULTS */,
|
|
102
104
|
});
|
|
@@ -17,9 +17,9 @@ import {
|
|
|
17
17
|
/* highlightFirstLineOfCode */
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @param {Context} context
|
|
22
|
-
* @returns
|
|
20
|
+
* Gets the coordinates for the first line of code of a file.
|
|
21
|
+
* @param {Context} context An ESLint rule's `context` object.
|
|
22
|
+
* @returns The `context.report` `loc`-compatible coordinates for the first line of code of a file.
|
|
23
23
|
*/
|
|
24
24
|
export const highlightFirstLineOfCode = (context) => ({
|
|
25
25
|
start: { line: 1, column: 0 },
|
|
@@ -29,13 +29,13 @@ export const highlightFirstLineOfCode = (context) => ({
|
|
|
29
29
|
/* isImportBlocked */
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Returns a boolean deciding if an imported file's "resolved" directive is incompatible with the current file's "resolved" directive.
|
|
33
33
|
* @template {ResolvedDirectiveWithoutUseAgnosticStrategies} T
|
|
34
34
|
* @template {ResolvedDirectiveWithoutUseAgnosticStrategies} U
|
|
35
|
-
* @param {ResolvedDirectives_BlockedImports<T, U>} resolvedDirectives_blockedImports
|
|
36
|
-
* @param {T} currentFileResolvedDirective
|
|
37
|
-
* @param {U} importedFileResolvedDirective
|
|
38
|
-
* @returns
|
|
35
|
+
* @param {ResolvedDirectives_BlockedImports<T, U>} resolvedDirectives_blockedImports The blocked imports object, either for agnostic20 or for directive21.
|
|
36
|
+
* @param {T} currentFileResolvedDirective The current file's "resolved" directive.
|
|
37
|
+
* @param {U} importedFileResolvedDirective The imported file's "resolved" directive.
|
|
38
|
+
* @returns `true` if the import is blocked, as established in respective `resolvedDirectives_blockedImports`.
|
|
39
39
|
*/
|
|
40
40
|
export const isImportBlocked = (
|
|
41
41
|
// Note: "Blocked" here is preferred over "not allowed" because a specific message will be shared for each of the blocked situations, explaining their reasons and the solutions needed.
|
|
@@ -50,12 +50,12 @@ export const isImportBlocked = (
|
|
|
50
50
|
/* makeIntroForSpecificViolationMessage */
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
53
|
+
* Makes the intro for each specific import rule violation messages.
|
|
54
54
|
* @template {ResolvedDirectiveWithoutUseAgnosticStrategies} T
|
|
55
55
|
* @template {ResolvedDirectiveWithoutUseAgnosticStrategies} U
|
|
56
|
-
* @param {T} currentFileResolvedDirective
|
|
57
|
-
* @param {U} importedFileResolvedDirective
|
|
58
|
-
* @returns
|
|
56
|
+
* @param {T} currentFileResolvedDirective The current file's "resolved" directive.
|
|
57
|
+
* @param {U} importedFileResolvedDirective The imported file's "resolved" directive.
|
|
58
|
+
* @returns "[Current file 'resolved' modules] are not allowed to import [imported file 'resolved' modules]."
|
|
59
59
|
*/
|
|
60
60
|
export const makeIntroForSpecificViolationMessage = (
|
|
61
61
|
currentFileResolvedDirective,
|
|
@@ -70,12 +70,12 @@ export const makeIntroForSpecificViolationMessage = (
|
|
|
70
70
|
/* makeMessageFromCurrentFileResolvedDirective */
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
73
|
+
* Lists in an message the "resolved" modules incompatible with a "resolved" module based on its "resolved" directive.
|
|
74
74
|
* @template {ResolvedDirectiveWithoutUseAgnosticStrategies} T
|
|
75
75
|
* @template {ResolvedDirectiveWithoutUseAgnosticStrategies} U
|
|
76
|
-
* @param {ResolvedDirectives_BlockedImports<T, U>} resolvedDirectives_blockedImports
|
|
77
|
-
* @param {T} currentFileResolvedDirective
|
|
78
|
-
* @returns
|
|
76
|
+
* @param {ResolvedDirectives_BlockedImports<T, U>} resolvedDirectives_blockedImports The blocked imports object, either for agnostic20 or for directive21.
|
|
77
|
+
* @param {T} currentFileResolvedDirective The "resolved" directive of the "resolved" module.
|
|
78
|
+
* @returns The message listing the incompatible "resolved" modules.
|
|
79
79
|
*/
|
|
80
80
|
export const makeMessageFromCurrentFileResolvedDirective = (
|
|
81
81
|
resolvedDirectives_blockedImports,
|
|
@@ -111,13 +111,13 @@ export const makeMessageFromCurrentFileResolvedDirective = (
|
|
|
111
111
|
/* findSpecificViolationMessage */
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
114
|
+
* Finds the `message` for the specific violation of "resolved" directives import rules based on `resolvedDirectives_blockedImports`.
|
|
115
115
|
* @template {ResolvedDirectiveWithoutUseAgnosticStrategies} T
|
|
116
116
|
* @template {ResolvedDirectiveWithoutUseAgnosticStrategies} U
|
|
117
|
-
* @param {ResolvedDirectives_BlockedImports<T, U>} resolvedDirectives_blockedImports
|
|
118
|
-
* @param {T} currentFileResolvedDirective
|
|
119
|
-
* @param {U} importedFileResolvedDirective
|
|
120
|
-
* @returns
|
|
117
|
+
* @param {ResolvedDirectives_BlockedImports<T, U>} resolvedDirectives_blockedImports The blocked imports object, either for agnostic20 or for directive21.
|
|
118
|
+
* @param {T} currentFileResolvedDirective The current file's "resolved" directive.
|
|
119
|
+
* @param {U} importedFileResolvedDirective The imported file's "resolved" directive.
|
|
120
|
+
* @returns The corresponding `message`.
|
|
121
121
|
*/
|
|
122
122
|
export const findSpecificViolationMessage = (
|
|
123
123
|
resolvedDirectives_blockedImports,
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Walks an AST with a given callback.
|
|
9
|
-
* @param {SourceCode} sourceCode
|
|
10
|
-
* @param {(node: Node, parent: Node | null) => void} callback
|
|
9
|
+
* @param {SourceCode} sourceCode The `SourceCode` where the AST comes from.
|
|
10
|
+
* @param {(node: Node, parent: Node | null) => void} callback The callback that runs during the walk.
|
|
11
11
|
*/
|
|
12
12
|
export const walkAST = (sourceCode, callback) => {
|
|
13
13
|
const ast = sourceCode.ast;
|
|
@@ -18,10 +18,10 @@ export const walkAST = (sourceCode, callback) => {
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Recursively visits an AST node with a given callback.
|
|
21
|
-
* @param {Node} node
|
|
22
|
-
* @param {Node | null} parent
|
|
23
|
-
* @param {VisitorKeys} visitorKeys
|
|
24
|
-
* @param {(node: Node, parent: Node | null) => void} callback
|
|
21
|
+
* @param {Node} node The node being visited.
|
|
22
|
+
* @param {Node | null} parent The parent of the node being visited.
|
|
23
|
+
* @param {VisitorKeys} visitorKeys The visitor keys of the node being visited.
|
|
24
|
+
* @param {(node: Node, parent: Node | null) => void} callback The callback that runs during the walk.
|
|
25
25
|
*/
|
|
26
26
|
const visitNode = (node, parent, visitorKeys, callback) => {
|
|
27
27
|
callback(node, parent);
|
|
@@ -89,12 +89,12 @@ const SUGGEST_USE_AGNOSTIC =
|
|
|
89
89
|
"If the module you're trying to import does not possess any server-side code however, please mark it with this plugin's own and eponymous 'use agnostic' directive to signal its compatibility across all environments.";
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
92
|
+
* Makes a blockedImport object for the identified blocked import at hand.
|
|
93
93
|
* @template {EffectiveDirective} T
|
|
94
94
|
* @template {EffectiveDirective} U
|
|
95
|
-
* @param {T} currentFileEffectiveDirective
|
|
96
|
-
* @param {U} importedFileEffectiveDirective
|
|
97
|
-
* @returns
|
|
95
|
+
* @param {T} currentFileEffectiveDirective The current file's effective directive.
|
|
96
|
+
* @param {U} importedFileEffectiveDirective The imported file's effective directive.
|
|
97
|
+
* @returns The blockedImport object for the identified blocked import at hand.
|
|
98
98
|
*/
|
|
99
99
|
export const makeBlockedImport = (
|
|
100
100
|
currentFileEffectiveDirective,
|
|
@@ -114,12 +114,12 @@ export const makeBlockedImport = (
|
|
|
114
114
|
};
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
|
-
*
|
|
117
|
+
* Makes a blockedImport object for the identified blocked import at hand enhanced with the suggestion to use the `'use agnostic'` directive.
|
|
118
118
|
* @template {EffectiveDirective} T
|
|
119
119
|
* @template {EffectiveDirective} U
|
|
120
|
-
* @param {T} currentFileEffectiveDirective
|
|
121
|
-
* @param {U} importedFileEffectiveDirective
|
|
122
|
-
* @returns
|
|
120
|
+
* @param {T} currentFileEffectiveDirective The current file's effective directive.
|
|
121
|
+
* @param {U} importedFileEffectiveDirective The imported file's effective directive.
|
|
122
|
+
* @returns The enhanced blockedImport object with the suggestion to use the `'use agnostic'` directive.
|
|
123
123
|
*/
|
|
124
124
|
const makeBlockedImportSuggestingUseAgnostic = (
|
|
125
125
|
currentFileEffectiveDirective,
|
|
@@ -140,123 +140,123 @@ const makeBlockedImportSuggestingUseAgnostic = (
|
|
|
140
140
|
|
|
141
141
|
export const effectiveDirectives_blockedImports = Object.freeze({
|
|
142
142
|
[USE_SERVER_LOGICS]: Object.freeze([
|
|
143
|
-
// USE_SERVER_LOGICS
|
|
144
|
-
// USE_SERVER_COMPONENTS
|
|
145
|
-
// USE_SERVER_FUNCTIONS
|
|
143
|
+
// USE_SERVER_LOGICS allowed, because Server Logics can compose with one another.
|
|
144
|
+
// USE_SERVER_COMPONENTS allowed, because Server Components are OK to be composed with Server Logics as long as the Server Logics Module, by convention, does not export React components.
|
|
145
|
+
// USE_SERVER_FUNCTIONS allowed, because Server Functions, being able to import one another, can compose and do so via Server Logics, despite this method seeming superfluous at first glance. (Perhaps a preferrable use case for this has been found or could be found either today or in the future.)
|
|
146
146
|
makeBlockedImport(
|
|
147
147
|
USE_SERVER_LOGICS,
|
|
148
148
|
USE_CLIENT_LOGICS
|
|
149
|
-
) /*
|
|
149
|
+
) /* Client Logics should never leak to the server. */,
|
|
150
150
|
makeBlockedImport(
|
|
151
151
|
USE_SERVER_LOGICS,
|
|
152
152
|
USE_CLIENT_COMPONENTS
|
|
153
|
-
) /*
|
|
154
|
-
// USE_AGNOSTIC_LOGICS
|
|
155
|
-
// USE_AGNOSTIC_COMPONENTS
|
|
153
|
+
) /* Client Components cannot be tinkered with on the server. */,
|
|
154
|
+
// USE_AGNOSTIC_LOGICS allowed, because Agnostic Logics can run safely on the server just like they can on the client.
|
|
155
|
+
// USE_AGNOSTIC_COMPONENTS allowed, because Agnostic Components can be composed with Logics on the server just like they can on the client, as long at the Server Logics Module, by convention, does not export React components.
|
|
156
156
|
]),
|
|
157
157
|
[USE_SERVER_COMPONENTS]: Object.freeze([
|
|
158
|
-
// USE_SERVER_LOGICS
|
|
159
|
-
// USE_SERVER_COMPONENTS
|
|
160
|
-
// USE_SERVER_FUNCTIONS
|
|
158
|
+
// USE_SERVER_LOGICS allowed, because Server Logics, being logic from the server, can safely support Server Components.
|
|
159
|
+
// USE_SERVER_COMPONENTS allowed, because Server Components can compose with one another, assuming thanks to the inclusion of the 'use agnostic' directive that they are actual Server Components.
|
|
160
|
+
// USE_SERVER_FUNCTIONS allowed, because Server Functions can be passed to imported Client Components within Server Components Modules, even though indeed Server Components Modules and Server Components can make their own Server Functions through inline `'use server'` directives.
|
|
161
161
|
makeBlockedImport(
|
|
162
162
|
USE_SERVER_COMPONENTS,
|
|
163
163
|
USE_CLIENT_LOGICS
|
|
164
|
-
) /*
|
|
165
|
-
// USE_CLIENT_COMPONENTS
|
|
166
|
-
// USE_AGNOSTIC_LOGICS
|
|
167
|
-
// USE_AGNOSTIC_COMPONENTS
|
|
164
|
+
) /* Client Logics should never leak to the server. */,
|
|
165
|
+
// USE_CLIENT_COMPONENTS allowed, because Client Components can be nested inside Server Components either to wrap some of the tree with client state accessible through child Client Components and pass through Server Components or to create client boundaries when the root of the application is planted on the server.
|
|
166
|
+
// USE_AGNOSTIC_LOGICS allowed, because Agnostic Logics can run safely on the server just like they can on the client.
|
|
167
|
+
// USE_AGNOSTIC_COMPONENTS allowed, because Agnostic Components can render safely on the server just like they can on the client.
|
|
168
168
|
]),
|
|
169
169
|
[USE_SERVER_FUNCTIONS]: Object.freeze([
|
|
170
|
-
// USE_SERVER_LOGICS
|
|
170
|
+
// USE_SERVER_LOGICS allowed, because Server Logics, being logic from the server, can safely support Server Functions.
|
|
171
171
|
makeBlockedImport(
|
|
172
172
|
USE_SERVER_FUNCTIONS,
|
|
173
173
|
USE_SERVER_COMPONENTS
|
|
174
|
-
) /*
|
|
175
|
-
// USE_SERVER_FUNCTIONS
|
|
174
|
+
) /* Server Components aren't allowed because Server Functions have no business working with React Components. */,
|
|
175
|
+
// USE_SERVER_FUNCTIONS allowed, because Server Functions, even though they don't need to import one another and the same results can be generated via Server Logics for the outcome of a single Server Function, can still compose with one another. (Perhaps a preferrable use case for this has been found or could be found either today or in the future.)
|
|
176
176
|
makeBlockedImport(
|
|
177
177
|
USE_SERVER_FUNCTIONS,
|
|
178
178
|
USE_CLIENT_LOGICS
|
|
179
|
-
) /*
|
|
179
|
+
) /* Client Logics should never leak to the server. */,
|
|
180
180
|
makeBlockedImport(
|
|
181
181
|
USE_SERVER_FUNCTIONS,
|
|
182
182
|
USE_CLIENT_COMPONENTS
|
|
183
|
-
) /*
|
|
184
|
-
// USE_AGNOSTIC_LOGICS
|
|
183
|
+
) /* Client Components aren't allowed because Server Functions have no business working with React Components. */,
|
|
184
|
+
// USE_AGNOSTIC_LOGICS allowed, because Agnostic Logics can run safely on the server just like they can on the client.
|
|
185
185
|
makeBlockedImport(
|
|
186
186
|
USE_SERVER_FUNCTIONS,
|
|
187
187
|
USE_AGNOSTIC_COMPONENTS
|
|
188
|
-
) /*
|
|
188
|
+
) /* Agnostic Components aren't allowed because Server Functions have no business working with React Components. */,
|
|
189
189
|
]),
|
|
190
190
|
[USE_CLIENT_LOGICS]: Object.freeze([
|
|
191
191
|
makeBlockedImportSuggestingUseAgnostic(
|
|
192
192
|
USE_CLIENT_LOGICS,
|
|
193
193
|
USE_SERVER_LOGICS
|
|
194
|
-
) /*
|
|
194
|
+
) /* Server Logics should never leak to the client. */,
|
|
195
195
|
makeBlockedImportSuggestingUseAgnostic(
|
|
196
196
|
USE_CLIENT_LOGICS,
|
|
197
197
|
USE_SERVER_COMPONENTS
|
|
198
|
-
) /*
|
|
199
|
-
// USE_SERVER_FUNCTIONS
|
|
200
|
-
// USE_CLIENT_LOGICS
|
|
201
|
-
// USE_CLIENT_COMPONENTS
|
|
202
|
-
// USE_AGNOSTIC_LOGICS
|
|
203
|
-
// USE_AGNOSTIC_COMPONENTS
|
|
198
|
+
) /* Server Components cannot be tinkered with on the client. */,
|
|
199
|
+
// USE_SERVER_FUNCTIONS allowed, because Server Functions can technically be attached to Client Components that are being tinkered with within Client Logics Modules.
|
|
200
|
+
// USE_CLIENT_LOGICS allowed, because Client Logics can compose with one another.
|
|
201
|
+
// USE_CLIENT_COMPONENTS allowed, because Client Components are OK to be composed with Client Logics as long as the Client Logics Module, by convention, does not export React components.
|
|
202
|
+
// USE_AGNOSTIC_LOGICS allowed, because Agnostic Logics can run safely on the client just like they can on the server.
|
|
203
|
+
// USE_AGNOSTIC_COMPONENTS allowed, because Agnostic Components can be composed with Logics on the client just like they can on the server, as long as the Client Logics Module, by convention, does not export React components.
|
|
204
204
|
]),
|
|
205
205
|
[USE_CLIENT_COMPONENTS]: Object.freeze([
|
|
206
206
|
makeBlockedImportSuggestingUseAgnostic(
|
|
207
207
|
USE_CLIENT_LOGICS,
|
|
208
208
|
USE_SERVER_LOGICS
|
|
209
|
-
) /*
|
|
209
|
+
) /* Server Logics should never leak to the client. */,
|
|
210
210
|
makeBlockedImportSuggestingUseAgnostic(
|
|
211
211
|
USE_CLIENT_LOGICS,
|
|
212
212
|
USE_SERVER_COMPONENTS
|
|
213
|
-
) /*
|
|
214
|
-
// USE_SERVER_FUNCTIONS
|
|
215
|
-
// USE_CLIENT_LOGICS
|
|
216
|
-
// USE_CLIENT_COMPONENTS
|
|
217
|
-
// USE_AGNOSTIC_LOGICS
|
|
218
|
-
// USE_AGNOSTIC_COMPONENTS
|
|
213
|
+
) /* Server Components cannot be tinkered with on the client. */,
|
|
214
|
+
// USE_SERVER_FUNCTIONS allowed, because Server Functions can specifically be triggered by Client Components.
|
|
215
|
+
// USE_CLIENT_LOGICS allowed, because Client Logics, being logic from the client, can safely support Client Components.
|
|
216
|
+
// USE_CLIENT_COMPONENTS allowed, because Client Components can compose with one another.
|
|
217
|
+
// USE_AGNOSTIC_LOGICS allowed, because Agnostic Logics can run safely on the client just like they can on the server.
|
|
218
|
+
// USE_AGNOSTIC_COMPONENTS allowed, because Agnostic Components can render safely on the client just like they can on the server.
|
|
219
219
|
]),
|
|
220
220
|
[USE_AGNOSTIC_LOGICS]: Object.freeze([
|
|
221
221
|
makeBlockedImportSuggestingUseAgnostic(
|
|
222
222
|
USE_AGNOSTIC_LOGICS,
|
|
223
223
|
USE_SERVER_LOGICS
|
|
224
|
-
) /*
|
|
224
|
+
) /* Server Logics cannot run on both the server and the client. */,
|
|
225
225
|
makeBlockedImportSuggestingUseAgnostic(
|
|
226
226
|
USE_AGNOSTIC_LOGICS,
|
|
227
227
|
USE_SERVER_COMPONENTS
|
|
228
|
-
) /*
|
|
228
|
+
) /* Server Components cannot be tinkered with on both the server and the client. */,
|
|
229
229
|
makeBlockedImport(
|
|
230
230
|
USE_AGNOSTIC_LOGICS,
|
|
231
231
|
USE_SERVER_FUNCTIONS
|
|
232
|
-
) /*
|
|
232
|
+
) /* Server Functions can be modified on the server and on the client, but their use cases on both environments are not one-to-one compatible, since they're being addressed as they are on the server and addressed as references on the client. */,
|
|
233
233
|
makeBlockedImport(
|
|
234
234
|
USE_AGNOSTIC_LOGICS,
|
|
235
235
|
USE_CLIENT_LOGICS
|
|
236
|
-
) /*
|
|
236
|
+
) /* Client Logics cannot run on both the server and the client. */,
|
|
237
237
|
makeBlockedImport(
|
|
238
238
|
USE_AGNOSTIC_LOGICS,
|
|
239
239
|
USE_CLIENT_COMPONENTS
|
|
240
|
-
) /*
|
|
241
|
-
// USE_AGNOSTIC_LOGICS
|
|
242
|
-
// USE_AGNOSTIC_COMPONENTS
|
|
240
|
+
) /* Client Components cannot be tinkered with on both the server and the client. */,
|
|
241
|
+
// USE_AGNOSTIC_LOGICS allowed, because Agnostic Logics can compose with one another.
|
|
242
|
+
// USE_AGNOSTIC_COMPONENTS allowed, because Agnostic Components can be composed with Logics agnostically as long as the Agnostic Logics Module, by convention, does not export React components.
|
|
243
243
|
]),
|
|
244
244
|
[USE_AGNOSTIC_COMPONENTS]: Object.freeze([
|
|
245
245
|
makeBlockedImportSuggestingUseAgnostic(
|
|
246
246
|
USE_AGNOSTIC_COMPONENTS,
|
|
247
247
|
USE_SERVER_LOGICS
|
|
248
|
-
) /*
|
|
248
|
+
) /* Server Logics cannot run on both the server and the client. */,
|
|
249
249
|
makeBlockedImportSuggestingUseAgnostic(
|
|
250
250
|
USE_AGNOSTIC_COMPONENTS,
|
|
251
251
|
USE_SERVER_COMPONENTS
|
|
252
|
-
) /*
|
|
253
|
-
// USE_SERVER_FUNCTIONS
|
|
252
|
+
) /* Server Components, unlike Client Components, cannot make silos of their own once on the opposing environment (the client in this case), and therefore cannot be executed from the client, making them unable to execute agnostically from both the server and the client. */,
|
|
253
|
+
// USE_SERVER_FUNCTIONS allowed, because Server Functions can be passed to Client Components as props when Client Components are also legally imported into Agnostic Components Modules.
|
|
254
254
|
makeBlockedImport(
|
|
255
255
|
USE_AGNOSTIC_COMPONENTS,
|
|
256
256
|
USE_CLIENT_LOGICS
|
|
257
|
-
) /*
|
|
258
|
-
// USE_CLIENT_COMPONENTS
|
|
259
|
-
// USE_AGNOSTIC_LOGICS
|
|
260
|
-
// USE_AGNOSTIC_COMPONENTS
|
|
257
|
+
) /* Client Logics cannot run on both the server and the client. */,
|
|
258
|
+
// USE_CLIENT_COMPONENTS allowed, because Client Components can be nested inside Agnostic Components either to wrap some of the tree with client state accessible through child Client Components and pass through Server Components — if still on the Server Tree — or to create client boundaries when the root of the application is planted on the server.
|
|
259
|
+
// USE_AGNOSTIC_LOGICS allowed, because Agnostic Logics, being environment-agnostic logic, can safely support Agnostic Components.
|
|
260
|
+
// USE_AGNOSTIC_COMPONENTS allowed, because Agnostic Components can compose with one another.
|
|
261
261
|
]),
|
|
262
262
|
});
|
|
@@ -40,9 +40,9 @@ import {
|
|
|
40
40
|
/* currentFileFlow */
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @param {Context} context
|
|
45
|
-
* @returns
|
|
43
|
+
* The flow that begins the import rules enforcement rule, retrieving the effective directive of the current file before comparing it to upcoming effective directives of the files it imports.
|
|
44
|
+
* @param {Context} context The ESLint rule's `context` object.
|
|
45
|
+
* @returns Either an object with `skip: true` to disregard or one with the non-null `currentFileEffectiveDirective`.
|
|
46
46
|
*/
|
|
47
47
|
export const currentFileFlow = (context) => {
|
|
48
48
|
const skipTrue = { ...skip, currentFileEffectiveDirective: undefined };
|
|
@@ -95,10 +95,10 @@ export const currentFileFlow = (context) => {
|
|
|
95
95
|
/* importedFileFlow */
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
99
|
-
* @param {Context} context
|
|
100
|
-
* @param {ImportDeclaration} node
|
|
101
|
-
* @returns
|
|
98
|
+
* The flow that is shared between import and re-export traversals to obtain the import file's effective directive.
|
|
99
|
+
* @param {Context} context The ESLint rule's `context` object.
|
|
100
|
+
* @param {ImportDeclaration} node The ESLint `node` of the rule's current traversal.
|
|
101
|
+
* @returns Either an object with `skip: true` to disregard or one with the non-null `importedFileEffectiveDirective`.
|
|
102
102
|
*/
|
|
103
103
|
const importedFileFlow = (context, node) => {
|
|
104
104
|
const skipTrue = { ...skip, importedFileEffectiveDirective: undefined };
|
|
@@ -146,11 +146,11 @@ const importedFileFlow = (context, node) => {
|
|
|
146
146
|
|
|
147
147
|
/* importsFlow */
|
|
148
148
|
|
|
149
|
-
/**
|
|
150
|
-
* @param {Context} context
|
|
151
|
-
* @param {ImportDeclaration} node
|
|
152
|
-
* @param {EffectiveDirective} currentFileEffectiveDirective
|
|
153
|
-
* @returns
|
|
149
|
+
/** The full flow for import traversals to enforce effective directives import rules.
|
|
150
|
+
* @param {Context} context The ESLint rule's `context` object.
|
|
151
|
+
* @param {ImportDeclaration} node The ESLint `node` of the rule's current traversal.
|
|
152
|
+
* @param {EffectiveDirective} currentFileEffectiveDirective The current file's effective directive.
|
|
153
|
+
* @returns Early if the flow needs to be interrupted.
|
|
154
154
|
*/
|
|
155
155
|
export const importsFlow = (context, node, currentFileEffectiveDirective) => {
|
|
156
156
|
// does not operate on `import type`
|
|
@@ -186,11 +186,11 @@ export const importsFlow = (context, node, currentFileEffectiveDirective) => {
|
|
|
186
186
|
|
|
187
187
|
/* reExportsFlow */
|
|
188
188
|
|
|
189
|
-
/**
|
|
190
|
-
* @param {Context} context
|
|
191
|
-
* @param {ExportNamedDeclaration | ExportAllDeclaration} node
|
|
192
|
-
* @param {EffectiveDirective} currentFileEffectiveDirective
|
|
193
|
-
* @returns
|
|
189
|
+
/** The full flow for export traversals, shared between `ExportNamedDeclaration` and `ExportAllDeclaration`, to ensure same effective directive re-exports.
|
|
190
|
+
* @param {Context} context The ESLint rule's `context` object.
|
|
191
|
+
* @param {ExportNamedDeclaration | ExportAllDeclaration} node The ESLint `node` of the rule's current traversal.
|
|
192
|
+
* @param {EffectiveDirective} currentFileEffectiveDirective The current file's effective directive.
|
|
193
|
+
* @returns Early if the flow needs to be interrupted.
|
|
194
194
|
*/
|
|
195
195
|
export const reExportsFlow = (context, node, currentFileEffectiveDirective) => {
|
|
196
196
|
// does not operate on `export type`
|
|
@@ -28,13 +28,13 @@ import {
|
|
|
28
28
|
/* getDirectiveFromModule */
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
* -
|
|
33
|
-
* -
|
|
34
|
-
* -
|
|
35
|
-
* -
|
|
36
|
-
* @param {AST} ast
|
|
37
|
-
* @returns
|
|
31
|
+
* Gets the directive of a module from its Abstract Syntax Tree.
|
|
32
|
+
* - `null` denotes a server-by-default module, ideally a Server Module.
|
|
33
|
+
* - `'use server'` denotes a Server Functions Module.
|
|
34
|
+
* - `'use client'` denotes a Client Module.
|
|
35
|
+
* - `'use agnostic'` denotes an Agnostic Module (formerly Shared Module).
|
|
36
|
+
* @param {AST} ast The module's AST (Abstract Syntax Tree).
|
|
37
|
+
* @returns The directive, or lack thereof via `null`. The lack of a directive is considered server-by-default.
|
|
38
38
|
*/
|
|
39
39
|
export const getDirectiveFromModule = (ast) => {
|
|
40
40
|
// the AST body to check for the top-of-the-file directive
|
|
@@ -63,13 +63,13 @@ export const getDirectiveFromModule = (ast) => {
|
|
|
63
63
|
/* getDirectiveFromCurrentModule */
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
67
|
-
* -
|
|
68
|
-
* -
|
|
69
|
-
* -
|
|
70
|
-
* -
|
|
71
|
-
* @param {Context} context
|
|
72
|
-
* @returns
|
|
66
|
+
* Gets the directive of the current module.
|
|
67
|
+
* - `null` denotes a server-by-default module, ideally a Server Module.
|
|
68
|
+
* - `'use server'` denotes a Server Functions Module.
|
|
69
|
+
* - `'use client'` denotes a Client Module.
|
|
70
|
+
* - `'use agnostic'` denotes an Agnostic Module (formerly Shared Module).
|
|
71
|
+
* @param {Context} context The ESLint rule's `context` object.
|
|
72
|
+
* @returns The directive, or lack thereof via `null`. The lack of a directive is considered server-by-default.
|
|
73
73
|
*/
|
|
74
74
|
export const getDirectiveFromCurrentModule = (context) => {
|
|
75
75
|
// the AST of the current module
|
|
@@ -81,13 +81,13 @@ export const getDirectiveFromCurrentModule = (context) => {
|
|
|
81
81
|
/* getDirectiveFromImportedModule */
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
|
-
*
|
|
85
|
-
* -
|
|
86
|
-
* -
|
|
87
|
-
* -
|
|
88
|
-
* -
|
|
89
|
-
* @param {string} resolvedPath
|
|
90
|
-
* @returns
|
|
84
|
+
* Gets the directive of the imported module.
|
|
85
|
+
* - `null` denotes a server-by-default module, ideally a Server Module.
|
|
86
|
+
* - `'use server'` denotes a Server Functions Module.
|
|
87
|
+
* - `'use client'` denotes a Client Module.
|
|
88
|
+
* - `'use agnostic'` denotes an Agnostic Module (formerly Shared Module).
|
|
89
|
+
* @param {string} resolvedPath The resolved path of the imported module.
|
|
90
|
+
* @returns The directive, or lack thereof via `null`. The lack of a directive is considered server-by-default.
|
|
91
91
|
*/
|
|
92
92
|
export const getDirectiveFromImportedModule = (resolvedPath) => {
|
|
93
93
|
// the AST of the imported module
|
|
@@ -99,17 +99,17 @@ export const getDirectiveFromImportedModule = (resolvedPath) => {
|
|
|
99
99
|
/* getEffectiveDirective */
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
103
|
-
* -
|
|
104
|
-
* -
|
|
105
|
-
* -
|
|
106
|
-
* -
|
|
107
|
-
* -
|
|
108
|
-
* -
|
|
109
|
-
* -
|
|
110
|
-
* @param {Directive | NoDirective} directive
|
|
111
|
-
* @param {Extension} extension
|
|
112
|
-
* @returns
|
|
102
|
+
* Gets the effective directive of a module, based on the combination of its directive (or lack thereof) and its extension (depending on whether it ends with 'x' for JSX).
|
|
103
|
+
* - `'use server logics'` denotes a Server Logics Module.
|
|
104
|
+
* - `'use server components'` denotes a Server Components Module.
|
|
105
|
+
* - `'use server functions'` denotes a Server Functions Module.
|
|
106
|
+
* - `'use client logics'` denotes a Client Logics Module.
|
|
107
|
+
* - `'use client components'` denotes a Client Components Module.
|
|
108
|
+
* - `'use agnostic logics'` denotes an Agnostic Logics Module.
|
|
109
|
+
* - `'use agnostic components'` denotes an Agnostic Components Module.
|
|
110
|
+
* @param {Directive | NoDirective} directive The directive as written on top of the file (`"no directive"` if no valid directive).
|
|
111
|
+
* @param {Extension} extension The JavaScript (TypeScript) extension of the file.
|
|
112
|
+
* @returns The effective directive, from which imports rules are applied.
|
|
113
113
|
*/
|
|
114
114
|
export const getEffectiveDirective = (directive, extension) => {
|
|
115
115
|
const moduleKind = extension.endsWith("x")
|
|
@@ -124,10 +124,10 @@ export const getEffectiveDirective = (directive, extension) => {
|
|
|
124
124
|
/* isImportBlocked */
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
|
-
*
|
|
128
|
-
* @param {EffectiveDirective} currentFileEffectiveDirective
|
|
129
|
-
* @param {EffectiveDirective} importedFileEffectiveDirective
|
|
130
|
-
* @returns
|
|
127
|
+
* Returns a boolean deciding if an imported file's effective directive is incompatible with the current file's effective directive.
|
|
128
|
+
* @param {EffectiveDirective} currentFileEffectiveDirective The current file's effective directive.
|
|
129
|
+
* @param {EffectiveDirective} importedFileEffectiveDirective The imported file's effective directive.
|
|
130
|
+
* @returns `true` if the import is blocked, as established in `effectiveDirectives_BlockedImports`.
|
|
131
131
|
*/
|
|
132
132
|
export const isImportBlocked = (
|
|
133
133
|
currentFileEffectiveDirective,
|
|
@@ -142,9 +142,9 @@ export const isImportBlocked = (
|
|
|
142
142
|
/* makeMessageFromCurrentFileEffectiveDirective */
|
|
143
143
|
|
|
144
144
|
/**
|
|
145
|
-
*
|
|
146
|
-
* @param {EffectiveDirective} effectiveDirective
|
|
147
|
-
* @returns
|
|
145
|
+
* Lists in an message the effective modules incompatible with a effective module based on its effective directive.
|
|
146
|
+
* @param {EffectiveDirective} effectiveDirective The effective directive of the effective module.
|
|
147
|
+
* @returns The message listing the incompatible effective modules.
|
|
148
148
|
*/
|
|
149
149
|
export const makeMessageFromCurrentFileEffectiveDirective = (
|
|
150
150
|
effectiveDirective
|
|
@@ -157,10 +157,10 @@ export const makeMessageFromCurrentFileEffectiveDirective = (
|
|
|
157
157
|
/* findSpecificViolationMessage */
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
|
-
*
|
|
161
|
-
* @param {EffectiveDirective} currentFileEffectiveDirective
|
|
162
|
-
* @param {EffectiveDirective} importedFileEffectiveDirective
|
|
163
|
-
* @returns
|
|
160
|
+
* Finds the `message` for the specific violation of effective directives import rules based on `effectiveDirectives_BlockedImports`.
|
|
161
|
+
* @param {EffectiveDirective} currentFileEffectiveDirective The current file's effective directive.
|
|
162
|
+
* @param {EffectiveDirective} importedFileEffectiveDirective The imported file's effective directive.
|
|
163
|
+
* @returns The corresponding `message`.
|
|
164
164
|
*/
|
|
165
165
|
export const findSpecificViolationMessage = (
|
|
166
166
|
currentFileEffectiveDirective,
|
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param {Plugin} plugin
|
|
17
|
-
* @returns
|
|
15
|
+
* Makes the agnostic20 config for the use-agnostic ESLint plugin.
|
|
16
|
+
* @param {Plugin} plugin The use-agnostic ESLint plugin itself.
|
|
17
|
+
* @returns The agnostic20 config's name as a key and its config as its value.
|
|
18
18
|
*/
|
|
19
19
|
export const makeAgnostic20Config = (plugin) => ({
|
|
20
20
|
[agnostic20ConfigName]: defineConfig([
|