eslint-plugin-use-agnostic 1.6.10 → 1.7.1
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 +87 -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/library/index.js +7 -0
- package/package.json +1 -1
- package/types/index.d.ts +125 -100
|
@@ -31,9 +31,9 @@ import {
|
|
|
31
31
|
/* getCommentedDirectiveFromSourceCode */
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param {string} string
|
|
36
|
-
* @returns
|
|
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.
|
|
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
|
-
*
|
|
50
|
-
* @param {string} string
|
|
51
|
-
* @returns
|
|
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.
|
|
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
|
-
*
|
|
62
|
-
* @param {string} string
|
|
63
|
-
* @returns
|
|
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.
|
|
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
|
-
*
|
|
73
|
+
* Gets the commented directive of a module from its ESLint `SourceCode` object.
|
|
74
74
|
*
|
|
75
|
-
*
|
|
76
|
-
* -
|
|
77
|
-
* -
|
|
78
|
-
* -
|
|
79
|
-
* -
|
|
80
|
-
* -
|
|
81
|
-
* -
|
|
82
|
-
* -
|
|
83
|
-
* -
|
|
84
|
-
* -
|
|
85
|
-
* -
|
|
86
|
-
* @param {SourceCode} sourceCode
|
|
87
|
-
* @returns
|
|
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.)
|
|
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
|
-
*
|
|
135
|
+
* Gets the commented directive of the current module.
|
|
136
136
|
*
|
|
137
|
-
*
|
|
138
|
-
* -
|
|
139
|
-
* -
|
|
140
|
-
* -
|
|
141
|
-
* -
|
|
142
|
-
* -
|
|
143
|
-
* -
|
|
144
|
-
* -
|
|
145
|
-
* -
|
|
146
|
-
* -
|
|
147
|
-
* -
|
|
148
|
-
* @param {Context} context
|
|
149
|
-
* @returns
|
|
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.)
|
|
150
150
|
*/
|
|
151
151
|
export const getCommentedDirectiveFromCurrentModule = (context) => {
|
|
152
152
|
const sourceCode = context.sourceCode;
|
|
@@ -158,21 +158,21 @@ export const getCommentedDirectiveFromCurrentModule = (context) => {
|
|
|
158
158
|
/* getCommentedDirectiveFromImportedModule */
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
|
-
*
|
|
161
|
+
* Gets the commented directive of the imported module.
|
|
162
162
|
*
|
|
163
|
-
*
|
|
164
|
-
* -
|
|
165
|
-
* -
|
|
166
|
-
* -
|
|
167
|
-
* -
|
|
168
|
-
* -
|
|
169
|
-
* -
|
|
170
|
-
* -
|
|
171
|
-
* -
|
|
172
|
-
* -
|
|
173
|
-
* -
|
|
174
|
-
* @param {string} resolvedPath
|
|
175
|
-
* @returns
|
|
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`. 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.)
|
|
176
176
|
*/
|
|
177
177
|
export const getCommentedDirectiveFromImportedModule = (resolvedPath) => {
|
|
178
178
|
const sourceCode = getSourceCodeFromFilePath(resolvedPath);
|
|
@@ -184,20 +184,20 @@ export const getCommentedDirectiveFromImportedModule = (resolvedPath) => {
|
|
|
184
184
|
/* getVerifiedCommentedDirective */
|
|
185
185
|
|
|
186
186
|
/**
|
|
187
|
-
*
|
|
188
|
-
* -
|
|
189
|
-
* -
|
|
190
|
-
* -
|
|
191
|
-
* -
|
|
192
|
-
* -
|
|
193
|
-
* -
|
|
194
|
-
* -
|
|
195
|
-
* -
|
|
196
|
-
* -
|
|
197
|
-
* -
|
|
198
|
-
* @param {CommentedDirective} directive
|
|
199
|
-
* @param {Extension} extension
|
|
200
|
-
* @returns
|
|
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.
|
|
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
|
-
*
|
|
218
|
-
* @param {Context} context
|
|
219
|
-
* @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node
|
|
220
|
-
* @returns
|
|
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`.
|
|
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
|
-
*
|
|
250
|
-
* @param {Context} context
|
|
251
|
-
* @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node
|
|
252
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
253
|
-
* @returns
|
|
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.
|
|
254
254
|
*/
|
|
255
255
|
export const addressDirectiveIfAgnosticStrategies = (
|
|
256
256
|
context,
|
|
@@ -276,10 +276,10 @@ export const addressDirectiveIfAgnosticStrategies = (
|
|
|
276
276
|
/* isImportBlocked */
|
|
277
277
|
|
|
278
278
|
/**
|
|
279
|
-
*
|
|
280
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective
|
|
281
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective
|
|
282
|
-
* @returns
|
|
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`.
|
|
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
|
-
*
|
|
298
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} commentedDirective
|
|
299
|
-
* @returns
|
|
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.
|
|
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
|
-
*
|
|
313
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective
|
|
314
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective
|
|
315
|
-
* @returns
|
|
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`.
|
|
316
316
|
*/
|
|
317
317
|
export const findSpecificViolationMessage = (
|
|
318
318
|
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
|
@@ -113,6 +113,13 @@ export {
|
|
|
113
113
|
commentedStrategiesSet,
|
|
114
114
|
// mapped commented strategies to their commented directives
|
|
115
115
|
commentedStrategies_commentedDirectives,
|
|
116
|
+
// environments
|
|
117
|
+
SERVER,
|
|
118
|
+
CLIENT,
|
|
119
|
+
AGNOSTIC,
|
|
120
|
+
environments_allowedChainImportEnvironments,
|
|
121
|
+
// mapped commented directives to their React directives
|
|
122
|
+
commentedDirectives_reactDirectives,
|
|
116
123
|
} from "./directive21/_commons/constants/bases.js";
|
|
117
124
|
|
|
118
125
|
export {
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -92,56 +92,56 @@ export const directives_effectiveDirectives: Readonly<{
|
|
|
92
92
|
}>;
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
96
|
-
* -
|
|
97
|
-
* -
|
|
98
|
-
* -
|
|
99
|
-
* -
|
|
100
|
-
* @param ast
|
|
101
|
-
* @returns
|
|
95
|
+
* Gets the directive of a module from its Abstract Syntax Tree.
|
|
96
|
+
* - `null` denotes a server-by-default module, ideally a Server Module.
|
|
97
|
+
* - `'use server'` denotes a Server Functions Module.
|
|
98
|
+
* - `'use client'` denotes a Client Module.
|
|
99
|
+
* - `'use agnostic'` denotes an Agnostic Module (formerly Shared Module).
|
|
100
|
+
* @param ast The module's AST (Abstract Syntax Tree).
|
|
101
|
+
* @returns The directive, or lack thereof via `null`. The lack of a directive is considered server-by-default.
|
|
102
102
|
*/
|
|
103
103
|
export const getDirectiveFromModule: (
|
|
104
104
|
ast: TSESLintSourceCode.Program
|
|
105
105
|
) => "use server" | "use client" | "use agnostic" | null;
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
109
|
-
* -
|
|
110
|
-
* -
|
|
111
|
-
* -
|
|
112
|
-
* -
|
|
113
|
-
* @param context
|
|
114
|
-
* @returns
|
|
108
|
+
* Gets the directive of the current module.
|
|
109
|
+
* - `null` denotes a server-by-default module, ideally a Server Module.
|
|
110
|
+
* - `'use server'` denotes a Server Functions Module.
|
|
111
|
+
* - `'use client'` denotes a Client Module.
|
|
112
|
+
* - `'use agnostic'` denotes an Agnostic Module (formerly Shared Module).
|
|
113
|
+
* @param context The ESLint rule's `context` object.
|
|
114
|
+
* @returns The directive, or lack thereof via `null`. The lack of a directive is considered server-by-default.
|
|
115
115
|
*/
|
|
116
116
|
export const getDirectiveFromCurrentModule: (
|
|
117
117
|
context: RuleContext<string, readonly unknown[]>
|
|
118
118
|
) => "use server" | "use client" | "use agnostic" | null;
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
122
|
-
* -
|
|
123
|
-
* -
|
|
124
|
-
* -
|
|
125
|
-
* -
|
|
126
|
-
* @param resolvedPath
|
|
127
|
-
* @returns
|
|
121
|
+
* Gets the directive of the imported module.
|
|
122
|
+
* - `null` denotes a server-by-default module, ideally a Server Module.
|
|
123
|
+
* - `'use server'` denotes a Server Functions Module.
|
|
124
|
+
* - `'use client'` denotes a Client Module.
|
|
125
|
+
* - `'use agnostic'` denotes an Agnostic Module (formerly Shared Module).
|
|
126
|
+
* @param resolvedPath The resolved path of the imported module.
|
|
127
|
+
* @returns The directive, or lack thereof via `null`. The lack of a directive is considered server-by-default.
|
|
128
128
|
*/
|
|
129
129
|
export const getDirectiveFromImportedModule: (
|
|
130
130
|
resolvedPath: string
|
|
131
131
|
) => "use server" | "use client" | "use agnostic" | null;
|
|
132
132
|
|
|
133
133
|
/**
|
|
134
|
-
*
|
|
135
|
-
* -
|
|
136
|
-
* -
|
|
137
|
-
* -
|
|
138
|
-
* -
|
|
139
|
-
* -
|
|
140
|
-
* -
|
|
141
|
-
* -
|
|
142
|
-
* @param directive
|
|
143
|
-
* @param extension
|
|
144
|
-
* @returns
|
|
134
|
+
* 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).
|
|
135
|
+
* - `'use server logics'` denotes a Server Logics Module.
|
|
136
|
+
* - `'use server components'` denotes a Server Components Module.
|
|
137
|
+
* - `'use server functions'` denotes a Server Functions Module.
|
|
138
|
+
* - `'use client logics'` denotes a Client Logics Module.
|
|
139
|
+
* - `'use client components'` denotes a Client Components Module.
|
|
140
|
+
* - `'use agnostic logics'` denotes an Agnostic Logics Module.
|
|
141
|
+
* - `'use agnostic components'` denotes an Agnostic Components Module.
|
|
142
|
+
* @param directive The directive as written on top of the file (`"no directive"` if no valid directive).
|
|
143
|
+
* @param extension The JavaScript (TypeScript) extension of the file.
|
|
144
|
+
* @returns The effective directive, from which imports rules are applied.
|
|
145
145
|
*/
|
|
146
146
|
export const getEffectiveDirective: (
|
|
147
147
|
directive: "use server" | "use client" | "use agnostic" | "no directive",
|
|
@@ -169,10 +169,10 @@ export const getEffectiveDirective: (
|
|
|
169
169
|
| null;
|
|
170
170
|
|
|
171
171
|
/**
|
|
172
|
-
*
|
|
173
|
-
* @param currentFileEffectiveDirective
|
|
174
|
-
* @param importedFileEffectiveDirective
|
|
175
|
-
* @returns
|
|
172
|
+
* Returns a boolean deciding if an imported file's effective directive is incompatible with the current file's effective directive.
|
|
173
|
+
* @param currentFileEffectiveDirective The current file's effective directive.
|
|
174
|
+
* @param importedFileEffectiveDirective The imported file's effective directive.
|
|
175
|
+
* @returns `true` if the import is blocked, as established in `effectiveDirectives_BlockedImports`.
|
|
176
176
|
*/
|
|
177
177
|
export const isImportBlockedAgnostic20: (
|
|
178
178
|
currentFileEffectiveDirective:
|
|
@@ -303,22 +303,47 @@ export const commentedStrategies_commentedDirectives: Readonly<{
|
|
|
303
303
|
[AT_AGNOSTIC_CONDITIONS]: "use agnostic conditions";
|
|
304
304
|
}>;
|
|
305
305
|
|
|
306
|
+
// environments
|
|
307
|
+
export const SERVER: "server";
|
|
308
|
+
export const CLIENT: "client";
|
|
309
|
+
export const AGNOSTIC: "agnostic";
|
|
310
|
+
|
|
311
|
+
export const environments_allowedChainImportEnvironments: Readonly<{
|
|
312
|
+
[SERVER]: readonly ["server", "agnostic"];
|
|
313
|
+
[CLIENT]: readonly ["client", "agnostic"];
|
|
314
|
+
[AGNOSTIC]: readonly ["agnostic"];
|
|
315
|
+
}>;
|
|
316
|
+
|
|
317
|
+
// mapped commented directives to their React directives
|
|
318
|
+
export const commentedDirectives_reactDirectives: Readonly<{
|
|
319
|
+
[USE_SERVER_LOGICS]: null;
|
|
320
|
+
[USE_CLIENT_LOGICS]: "use client";
|
|
321
|
+
[USE_AGNOSTIC_LOGICS]: "use agnostic";
|
|
322
|
+
[USE_SERVER_COMPONENTS]: null;
|
|
323
|
+
[USE_CLIENT_COMPONENTS]: "use client";
|
|
324
|
+
[USE_AGNOSTIC_COMPONENTS]: "use agnostic";
|
|
325
|
+
[USE_SERVER_FUNCTIONS]: "use server";
|
|
326
|
+
[USE_CLIENT_CONTEXTS]: "use client";
|
|
327
|
+
[USE_AGNOSTIC_CONDITIONS]: null;
|
|
328
|
+
[USE_AGNOSTIC_STRATEGIES]: null;
|
|
329
|
+
}>;
|
|
330
|
+
|
|
306
331
|
/**
|
|
307
|
-
*
|
|
332
|
+
* Gets the commented directive of a module from its ESLint `SourceCode` object.
|
|
308
333
|
*
|
|
309
|
-
*
|
|
310
|
-
* -
|
|
311
|
-
* -
|
|
312
|
-
* -
|
|
313
|
-
* -
|
|
314
|
-
* -
|
|
315
|
-
* -
|
|
316
|
-
* -
|
|
317
|
-
* -
|
|
318
|
-
* -
|
|
319
|
-
* -
|
|
320
|
-
* @param sourceCode
|
|
321
|
-
* @returns
|
|
334
|
+
* Accepted directives for the default Directive-First Architecture are (single or double quotes included):
|
|
335
|
+
* - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
|
|
336
|
+
* - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
|
|
337
|
+
* - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
|
|
338
|
+
* - `'use server components'`, `"use server components"` denoting a Server Components Module.
|
|
339
|
+
* - `'use client components'`, `"use client components"` denoting a Client Components Module.
|
|
340
|
+
* - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
|
|
341
|
+
* - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
|
|
342
|
+
* - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
|
|
343
|
+
* - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
|
|
344
|
+
* - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
|
|
345
|
+
* @param sourceCode The ESLint SourceCode object.
|
|
346
|
+
* @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.)
|
|
322
347
|
*/
|
|
323
348
|
export const getCommentedDirectiveFromSourceCode: (
|
|
324
349
|
sourceCode: ESLintSourceCode
|
|
@@ -336,21 +361,21 @@ export const getCommentedDirectiveFromSourceCode: (
|
|
|
336
361
|
| null;
|
|
337
362
|
|
|
338
363
|
/**
|
|
339
|
-
*
|
|
364
|
+
* Gets the commented directive of the current module.
|
|
340
365
|
*
|
|
341
|
-
*
|
|
342
|
-
* -
|
|
343
|
-
* -
|
|
344
|
-
* -
|
|
345
|
-
* -
|
|
346
|
-
* -
|
|
347
|
-
* -
|
|
348
|
-
* -
|
|
349
|
-
* -
|
|
350
|
-
* -
|
|
351
|
-
* -
|
|
352
|
-
* @param context
|
|
353
|
-
* @returns
|
|
366
|
+
* Accepted directives for the default Directive-First Architecture are (single or double quotes included):
|
|
367
|
+
* - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
|
|
368
|
+
* - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
|
|
369
|
+
* - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
|
|
370
|
+
* - `'use server components'`, `"use server components"` denoting a Server Components Module.
|
|
371
|
+
* - `'use client components'`, `"use client components"` denoting a Client Components Module.
|
|
372
|
+
* - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
|
|
373
|
+
* - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
|
|
374
|
+
* - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
|
|
375
|
+
* - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
|
|
376
|
+
* - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
|
|
377
|
+
* @param context The ESLint rule's `context` object.
|
|
378
|
+
* @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.)
|
|
354
379
|
*/
|
|
355
380
|
export const getCommentedDirectiveFromCurrentModule: (
|
|
356
381
|
context: RuleContext<string, readonly unknown[]>
|
|
@@ -368,21 +393,21 @@ export const getCommentedDirectiveFromCurrentModule: (
|
|
|
368
393
|
| null;
|
|
369
394
|
|
|
370
395
|
/**
|
|
371
|
-
*
|
|
396
|
+
* Gets the commented directive of the imported module.
|
|
372
397
|
*
|
|
373
|
-
*
|
|
374
|
-
* -
|
|
375
|
-
* -
|
|
376
|
-
* -
|
|
377
|
-
* -
|
|
378
|
-
* -
|
|
379
|
-
* -
|
|
380
|
-
* -
|
|
381
|
-
* -
|
|
382
|
-
* -
|
|
383
|
-
* -
|
|
384
|
-
* @param resolvedPath
|
|
385
|
-
* @returns
|
|
398
|
+
* Accepted directives for the default Directive-First Architecture are (single or double quotes included):
|
|
399
|
+
* - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
|
|
400
|
+
* - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
|
|
401
|
+
* - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
|
|
402
|
+
* - `'use server components'`, `"use server components"` denoting a Server Components Module.
|
|
403
|
+
* - `'use client components'`, `"use client components"` denoting a Client Components Module.
|
|
404
|
+
* - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
|
|
405
|
+
* - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
|
|
406
|
+
* - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
|
|
407
|
+
* - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
|
|
408
|
+
* - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
|
|
409
|
+
* @param resolvedPath The resolved path of the imported module.
|
|
410
|
+
* @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.)
|
|
386
411
|
*/
|
|
387
412
|
export const getCommentedDirectiveFromImportedModule: (
|
|
388
413
|
resolvedPath: string
|
|
@@ -400,20 +425,20 @@ export const getCommentedDirectiveFromImportedModule: (
|
|
|
400
425
|
| null;
|
|
401
426
|
|
|
402
427
|
/**
|
|
403
|
-
*
|
|
404
|
-
* -
|
|
405
|
-
* -
|
|
406
|
-
* -
|
|
407
|
-
* -
|
|
408
|
-
* -
|
|
409
|
-
* -
|
|
410
|
-
* -
|
|
411
|
-
* -
|
|
412
|
-
* -
|
|
413
|
-
* -
|
|
414
|
-
* @param directive
|
|
415
|
-
* @param extension
|
|
416
|
-
* @returns
|
|
428
|
+
* Ensures that a module's commented directive is consistent with its file extension (depending on whether it ends with 'x' for JSX).
|
|
429
|
+
* - `'use server logics'`: Server Logics Modules do NOT export JSX.
|
|
430
|
+
* - `'use client logics'`: Client Logics Modules do NOT export JSX.
|
|
431
|
+
* - `'use agnostic logics'`: Agnostic Logics Modules do NOT export JSX.
|
|
432
|
+
* - `'use server components'`: Server Components Modules ONLY export JSX.
|
|
433
|
+
* - `'use client components'`: Client Components Modules ONLY export JSX.
|
|
434
|
+
* - `'use agnostic components'`: Agnostic Components Modules ONLY export JSX.
|
|
435
|
+
* - `'use server functions'`: Server Functions Modules do NOT export JSX.
|
|
436
|
+
* - `'use client contexts'`: Client Contexts Modules ONLY export JSX.
|
|
437
|
+
* - `'use agnostic conditions'`: Agnostic Conditions Modules ONLY export JSX.
|
|
438
|
+
* - `'use agnostic strategies'`: Agnostic Strategies Modules may export JSX.
|
|
439
|
+
* @param directive The commented directive as written on top of the file (cannot be `null` at that stage).
|
|
440
|
+
* @param extension The JavaScript (TypeScript) extension of the file.
|
|
441
|
+
* @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.
|
|
417
442
|
*/
|
|
418
443
|
export const getVerifiedCommentedDirective: (
|
|
419
444
|
directive:
|
|
@@ -454,10 +479,10 @@ export const getVerifiedCommentedDirective: (
|
|
|
454
479
|
| null;
|
|
455
480
|
|
|
456
481
|
/**
|
|
457
|
-
*
|
|
458
|
-
* @param context
|
|
459
|
-
* @param node
|
|
460
|
-
* @returns
|
|
482
|
+
* 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.
|
|
483
|
+
* @param context The ESLint rule's `context` object.
|
|
484
|
+
* @param node The ESLint `node` of the rule's current traversal.
|
|
485
|
+
* @returns The interpreted directive, a.k.a. strategized directive, or lack thereof via `null`.
|
|
461
486
|
*/
|
|
462
487
|
export const getStrategizedDirective: (
|
|
463
488
|
context: RuleContext<string, readonly unknown[]>,
|
|
@@ -479,10 +504,10 @@ export const getStrategizedDirective: (
|
|
|
479
504
|
| null;
|
|
480
505
|
|
|
481
506
|
/**
|
|
482
|
-
*
|
|
483
|
-
* @param currentFileCommentedDirective
|
|
484
|
-
* @param importedFileCommentedDirective
|
|
485
|
-
* @returns
|
|
507
|
+
* Returns a boolean deciding if an imported file's commented directive is incompatible with the current file's commented directive.
|
|
508
|
+
* @param currentFileCommentedDirective The current file's commented directive.
|
|
509
|
+
* @param importedFileCommentedDirective The imported file's commented directive.
|
|
510
|
+
* @returns `true` if the import is blocked, as established in `commentedDirectives_BlockedImports`.
|
|
486
511
|
*/
|
|
487
512
|
export const isImportBlockedDirective21: (
|
|
488
513
|
currentFileCommentedDirective:
|