eslint-plugin-use-agnostic 1.3.2 → 1.3.4
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 +2788 -0
- package/jscomments/_commons/constants/bases.js +5 -1
- package/jscomments/jsdoc/composed-variables.js +6 -3
- package/library/_commons/utilities/helpers.js +21 -21
- package/library/agnostic20/_commons/constants/bases.js +58 -62
- 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 +86 -90
- package/library/directive21/_commons/utilities/flows.js +18 -18
- package/library/directive21/_commons/utilities/helpers.js +86 -86
- package/library/directive21/config.js +3 -3
- package/package.json +3 -2
|
@@ -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 the first comment from the source code
|
|
@@ -128,21 +128,21 @@ export const getCommentedDirectiveFromSourceCode = (sourceCode) => {
|
|
|
128
128
|
/* getCommentedDirectiveFromCurrentModule */
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
|
-
*
|
|
131
|
+
* Gets the commented directive of the current module.
|
|
132
132
|
*
|
|
133
|
-
*
|
|
134
|
-
* -
|
|
135
|
-
* -
|
|
136
|
-
* -
|
|
137
|
-
* -
|
|
138
|
-
* -
|
|
139
|
-
* -
|
|
140
|
-
* -
|
|
141
|
-
* -
|
|
142
|
-
* -
|
|
143
|
-
* -
|
|
144
|
-
* @param {Context} context
|
|
145
|
-
* @returns
|
|
133
|
+
* Accepted directives for the default Directive-First Architecture are (single or double quotes included):
|
|
134
|
+
* - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
|
|
135
|
+
* - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
|
|
136
|
+
* - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
|
|
137
|
+
* - `'use server components'`, `"use server components"` denoting a Server Components Module.
|
|
138
|
+
* - `'use client components'`, `"use client components"` denoting a Client Components Module.
|
|
139
|
+
* - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
|
|
140
|
+
* - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
|
|
141
|
+
* - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
|
|
142
|
+
* - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
|
|
143
|
+
* - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
|
|
144
|
+
* @param {Context} context The ESLint rule's `context` object.
|
|
145
|
+
* @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.)
|
|
146
146
|
*/
|
|
147
147
|
export const getCommentedDirectiveFromCurrentModule = (context) => {
|
|
148
148
|
const sourceCode = context.sourceCode;
|
|
@@ -154,21 +154,21 @@ export const getCommentedDirectiveFromCurrentModule = (context) => {
|
|
|
154
154
|
/* getCommentedDirectiveFromImportedModule */
|
|
155
155
|
|
|
156
156
|
/**
|
|
157
|
-
*
|
|
157
|
+
* Gets the commented directive of the imported module.
|
|
158
158
|
*
|
|
159
|
-
*
|
|
160
|
-
* -
|
|
161
|
-
* -
|
|
162
|
-
* -
|
|
163
|
-
* -
|
|
164
|
-
* -
|
|
165
|
-
* -
|
|
166
|
-
* -
|
|
167
|
-
* -
|
|
168
|
-
* -
|
|
169
|
-
* -
|
|
170
|
-
* @param {string} resolvedPath
|
|
171
|
-
* @returns
|
|
159
|
+
* Accepted directives for the default Directive-First Architecture are (single or double quotes included):
|
|
160
|
+
* - `'use server logics'`, `"use server logics"` denoting a Server Logics Module.
|
|
161
|
+
* - `'use client logics'`, `"use client logics"` denoting a Client Logics Module.
|
|
162
|
+
* - `'use agnostic logics'`, `"use agnostic logics"` denoting an Agnostic Logics Module.
|
|
163
|
+
* - `'use server components'`, `"use server components"` denoting a Server Components Module.
|
|
164
|
+
* - `'use client components'`, `"use client components"` denoting a Client Components Module.
|
|
165
|
+
* - `'use agnostic components'`, `"use agnostic components"` denoting an Agnostic Components Module.
|
|
166
|
+
* - `'use server functions'`, `"use server functions"` denoting a Server Functions Module.
|
|
167
|
+
* - `'use client contexts'`, `"use client contexts"` denoting a Client Contexts Module.
|
|
168
|
+
* - `'use agnostic conditions'`, `"use agnostic conditions"` denoting an Agnostic Conditions Module.
|
|
169
|
+
* - `'use agnostic strategies'`, `"use agnostic strategies"` denoting an Agnostic Strategies Module.
|
|
170
|
+
* @param {string} resolvedPath The resolved path of the imported module.
|
|
171
|
+
* @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.)
|
|
172
172
|
*/
|
|
173
173
|
export const getCommentedDirectiveFromImportedModule = (resolvedPath) => {
|
|
174
174
|
const sourceCode = getSourceCodeFromFilePath(resolvedPath);
|
|
@@ -180,20 +180,20 @@ export const getCommentedDirectiveFromImportedModule = (resolvedPath) => {
|
|
|
180
180
|
/* getVerifiedCommentedDirective */
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
|
-
*
|
|
184
|
-
* -
|
|
185
|
-
* -
|
|
186
|
-
* -
|
|
187
|
-
* -
|
|
188
|
-
* -
|
|
189
|
-
* -
|
|
190
|
-
* -
|
|
191
|
-
* -
|
|
192
|
-
* -
|
|
193
|
-
* -
|
|
194
|
-
* @param {CommentedDirective} directive
|
|
195
|
-
* @param {Extension} extension
|
|
196
|
-
* @returns
|
|
183
|
+
* Ensures that a module's commented directive is consistent with its file extension (depending on whether it ends with 'x' for JSX).
|
|
184
|
+
* - `'use server logics'`: Server Logics Modules do NOT export JSX.
|
|
185
|
+
* - `'use client logics'`: Client Logics Modules do NOT export JSX.
|
|
186
|
+
* - `'use agnostic logics'`: Agnostic Logics Modules do NOT export JSX.
|
|
187
|
+
* - `'use server components'`: Server Components Modules ONLY export JSX.
|
|
188
|
+
* - `'use client components'`: Client Components Modules ONLY export JSX.
|
|
189
|
+
* - `'use agnostic components'`: Agnostic Components Modules ONLY export JSX.
|
|
190
|
+
* - `'use server functions'`: Server Functions Modules do NOT export JSX.
|
|
191
|
+
* - `'use client contexts'`: Client Contexts Modules ONLY export JSX.
|
|
192
|
+
* - `'use agnostic conditions'`: Agnostic Conditions Modules ONLY export JSX.
|
|
193
|
+
* - `'use agnostic strategies'`: Agnostic Strategies Modules may export JSX.
|
|
194
|
+
* @param {CommentedDirective} directive The commented directive as written on top of the file (cannot be `null` at that stage).
|
|
195
|
+
* @param {Extension} extension The JavaScript (TypeScript) extension of the file.
|
|
196
|
+
* @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.
|
|
197
197
|
*/
|
|
198
198
|
export const getVerifiedCommentedDirective = (directive, extension) => {
|
|
199
199
|
const rule = commentedDirectives_extensionRules[directive];
|
|
@@ -209,10 +209,10 @@ export const getVerifiedCommentedDirective = (directive, extension) => {
|
|
|
209
209
|
/* getStrategizedDirective */
|
|
210
210
|
|
|
211
211
|
/**
|
|
212
|
-
*
|
|
213
|
-
* @param {Context} context
|
|
214
|
-
* @param {ImportDeclaration} node
|
|
215
|
-
* @returns
|
|
212
|
+
* Gets the interpreted directive from a specified commented Strategy (such as `@serverLogics`) nested inside the import declaration for an import from an Agnostic Strategies Module.
|
|
213
|
+
* @param {Context} context The ESLint rule's `context` object.
|
|
214
|
+
* @param {ImportDeclaration} node The ESLint `node` of the rule's current traversal.
|
|
215
|
+
* @returns The interpreted directive, a.k.a. strategized directive, or lack thereof via `null`.
|
|
216
216
|
*/
|
|
217
217
|
export const getStrategizedDirective = (context, node) => {
|
|
218
218
|
// gets the first nested `/* */` comment inside the node
|
|
@@ -240,18 +240,18 @@ export const getStrategizedDirective = (context, node) => {
|
|
|
240
240
|
/* addressDirectiveIfAgnosticStrategies */
|
|
241
241
|
|
|
242
242
|
/**
|
|
243
|
-
*
|
|
244
|
-
* @param {Context} context
|
|
245
|
-
* @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node
|
|
246
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
247
|
-
* @returns
|
|
243
|
+
* 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.
|
|
244
|
+
* @param {Context} context The ESLint rule's `context` object.
|
|
245
|
+
* @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node The ESLint `node` of the rule's current traversal.
|
|
246
|
+
* @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
|
|
247
|
+
* @returns The commented directive, the addressed strategy (as a commented directive) or `null` in case of failure.
|
|
248
248
|
*/
|
|
249
249
|
export const addressDirectiveIfAgnosticStrategies = (
|
|
250
250
|
context,
|
|
251
251
|
node,
|
|
252
252
|
currentFileCommentedDirective
|
|
253
253
|
) => {
|
|
254
|
-
// ignores if not addressing an Agnostic Strategies
|
|
254
|
+
// ignores if not addressing an Agnostic Strategies Module
|
|
255
255
|
if (currentFileCommentedDirective !== USE_AGNOSTIC_STRATEGIES)
|
|
256
256
|
return currentFileCommentedDirective;
|
|
257
257
|
|
|
@@ -270,10 +270,10 @@ export const addressDirectiveIfAgnosticStrategies = (
|
|
|
270
270
|
/* isImportBlocked */
|
|
271
271
|
|
|
272
272
|
/**
|
|
273
|
-
*
|
|
274
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective
|
|
275
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective
|
|
276
|
-
* @returns
|
|
273
|
+
* Returns a boolean deciding if an imported file's commented directive is incompatible with the current file's commented directive.
|
|
274
|
+
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective The current file's commented directive.
|
|
275
|
+
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective The imported file's commented directive.
|
|
276
|
+
* @returns `true` if the import is blocked, as established in `commentedDirectives_BlockedImports`.
|
|
277
277
|
*/
|
|
278
278
|
export const isImportBlocked = (
|
|
279
279
|
currentFileCommentedDirective,
|
|
@@ -288,9 +288,9 @@ export const isImportBlocked = (
|
|
|
288
288
|
/* makeMessageFromCurrentFileCommentedDirective */
|
|
289
289
|
|
|
290
290
|
/**
|
|
291
|
-
*
|
|
292
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} commentedDirective
|
|
293
|
-
* @returns
|
|
291
|
+
* Lists in an message the commented modules incompatible with a commented module based on its commented directive.
|
|
292
|
+
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} commentedDirective The commented directive of the commented module.
|
|
293
|
+
* @returns The message listing the incompatible commented modules.
|
|
294
294
|
*/
|
|
295
295
|
export const makeMessageFromCurrentFileCommentedDirective = (
|
|
296
296
|
commentedDirective
|
|
@@ -303,10 +303,10 @@ export const makeMessageFromCurrentFileCommentedDirective = (
|
|
|
303
303
|
/* findSpecificViolationMessage */
|
|
304
304
|
|
|
305
305
|
/**
|
|
306
|
-
*
|
|
307
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective
|
|
308
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective
|
|
309
|
-
* @returns
|
|
306
|
+
* Finds the `message` for the specific violation of commented directives import rules based on `commentedDirectives_BlockedImports`.
|
|
307
|
+
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective The current file's commented directive.
|
|
308
|
+
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective The imported file's commented directive.
|
|
309
|
+
* @returns The corresponding `message`.
|
|
310
310
|
*/
|
|
311
311
|
export const findSpecificViolationMessage = (
|
|
312
312
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-use-agnostic",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "Highlights problematic server-client imports in projects made with the Fullstack React Architecture.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"library",
|
|
24
24
|
"types/index.d.ts",
|
|
25
25
|
"jscomments",
|
|
26
|
-
"comments.config.js"
|
|
26
|
+
"comments.config.js",
|
|
27
|
+
"comments.config.json"
|
|
27
28
|
],
|
|
28
29
|
"exports": {
|
|
29
30
|
".": {
|