eslint-plugin-use-agnostic 1.6.8 → 1.6.10
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/README.md +1 -1
- package/library/_commons/constants/bases.js +8 -4
- package/library/_commons/utilities/helpers.js +21 -21
- package/library/_commons/utilities/walk-ast.js +46 -0
- 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 +134 -85
- package/library/directive21/_commons/rules/import-rules.js +16 -8
- package/library/directive21/_commons/utilities/analyze-exports-re.js +100 -0
- package/library/directive21/_commons/utilities/flows.js +201 -28
- package/library/directive21/_commons/utilities/helpers.js +88 -88
- package/library/directive21/config.js +3 -3
- package/package.json +2 -2
- package/types/index.d.ts +100 -100
|
@@ -7,9 +7,11 @@ import {
|
|
|
7
7
|
EXTENSIONS,
|
|
8
8
|
reExportNotSameMessageId,
|
|
9
9
|
importBreaksCommentedImportRulesMessageId,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
noCommentedDirectiveMessageId,
|
|
11
|
+
commentedDirectiveVerificationFailedMessageId,
|
|
12
|
+
commentedDirectiveReactDirectiveFailedMessageId,
|
|
13
|
+
importNotStrategizedMessageId,
|
|
14
|
+
cantChainImportAcrossEnvironmentsMessageId,
|
|
13
15
|
skip,
|
|
14
16
|
} from "../../../_commons/constants/bases.js";
|
|
15
17
|
import {
|
|
@@ -17,12 +19,20 @@ import {
|
|
|
17
19
|
commentedDirectives_verificationReports,
|
|
18
20
|
// currentFileCommentedDirective,
|
|
19
21
|
// importedFileCommentedDirective,
|
|
22
|
+
// currentFileEnvironment,
|
|
23
|
+
// importedFileEnvironment,
|
|
20
24
|
commentedDirectiveMessage,
|
|
21
25
|
specificViolationMessage,
|
|
22
26
|
specificFailure,
|
|
27
|
+
// verifiedCommentedDirective,
|
|
28
|
+
// expectedReactDirectiveAsText,
|
|
29
|
+
environments_allowedChainImportEnvironments,
|
|
30
|
+
commentedDirectives_reactDirectives,
|
|
31
|
+
reactDirectives_asTexts,
|
|
23
32
|
} from "../constants/bases.js";
|
|
24
33
|
|
|
25
34
|
import { highlightFirstLineOfCode } from "../../../_commons/utilities/helpers.js";
|
|
35
|
+
import { getDirectiveFromCurrentModule } from "../../../agnostic20/_commons/utilities/helpers.js";
|
|
26
36
|
import {
|
|
27
37
|
getCommentedDirectiveFromCurrentModule,
|
|
28
38
|
getVerifiedCommentedDirective,
|
|
@@ -33,6 +43,7 @@ import {
|
|
|
33
43
|
getStrategizedDirective,
|
|
34
44
|
addressDirectiveIfAgnosticStrategies,
|
|
35
45
|
} from "./helpers.js";
|
|
46
|
+
import { analyzeExportsForReExports } from "./analyze-exports-re.js";
|
|
36
47
|
|
|
37
48
|
/**
|
|
38
49
|
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').Context} Context
|
|
@@ -41,14 +52,15 @@ import {
|
|
|
41
52
|
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').ExportNamedDeclaration} ExportNamedDeclaration
|
|
42
53
|
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').ExportAllDeclaration} ExportAllDeclaration
|
|
43
54
|
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').ExportDefaultDeclaration} ExportDefaultDeclaration
|
|
55
|
+
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').Environment} Environment
|
|
44
56
|
*/
|
|
45
57
|
|
|
46
58
|
/* currentFileFlow */
|
|
47
59
|
|
|
48
60
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @param {Context} context
|
|
51
|
-
* @returns
|
|
61
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#CURRENTFILEFLOW
|
|
62
|
+
* @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
|
|
63
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#CURRENTFILEFLOW
|
|
52
64
|
*/
|
|
53
65
|
export const currentFileFlow = (context) => {
|
|
54
66
|
const skipTrue = { ...skip, verifiedCommentedDirective: undefined };
|
|
@@ -74,7 +86,7 @@ export const currentFileFlow = (context) => {
|
|
|
74
86
|
if (!commentedDirective) {
|
|
75
87
|
context.report({
|
|
76
88
|
loc: highlightFirstLineOfCode(context),
|
|
77
|
-
messageId:
|
|
89
|
+
messageId: noCommentedDirectiveMessageId,
|
|
78
90
|
});
|
|
79
91
|
return skipTrue;
|
|
80
92
|
}
|
|
@@ -89,7 +101,7 @@ export const currentFileFlow = (context) => {
|
|
|
89
101
|
if (!verifiedCommentedDirective) {
|
|
90
102
|
context.report({
|
|
91
103
|
loc: highlightFirstLineOfCode(context),
|
|
92
|
-
messageId:
|
|
104
|
+
messageId: commentedDirectiveVerificationFailedMessageId,
|
|
93
105
|
data: {
|
|
94
106
|
[specificFailure]:
|
|
95
107
|
commentedDirectives_verificationReports[commentedDirective],
|
|
@@ -98,19 +110,56 @@ export const currentFileFlow = (context) => {
|
|
|
98
110
|
return skipTrue;
|
|
99
111
|
}
|
|
100
112
|
|
|
113
|
+
// GETTING THE DIRECTIVE (or lack thereof) OF THE CURRENT FILE
|
|
114
|
+
const currentFileDirective = getDirectiveFromCurrentModule(context);
|
|
115
|
+
|
|
116
|
+
if (
|
|
117
|
+
commentedDirectives_reactDirectives[verifiedCommentedDirective] !==
|
|
118
|
+
currentFileDirective
|
|
119
|
+
) {
|
|
120
|
+
const expectedReactDirective =
|
|
121
|
+
commentedDirectives_reactDirectives[verifiedCommentedDirective];
|
|
122
|
+
const expectedReactDirectiveAsText = reactDirectives_asTexts.get(
|
|
123
|
+
expectedReactDirective
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
if (!expectedReactDirectiveAsText) {
|
|
127
|
+
console.warn(
|
|
128
|
+
`Somehow, expectedReactDirectiveAsText for ${expectedReactDirective} is undefined.`
|
|
129
|
+
);
|
|
130
|
+
return { skip: undefined, verifiedCommentedDirective }; // at this time, behave as if the new implementation didn't exist yet
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
context.report({
|
|
134
|
+
loc: highlightFirstLineOfCode(context),
|
|
135
|
+
messageId: commentedDirectiveReactDirectiveFailedMessageId, // ADD NEW
|
|
136
|
+
data: {
|
|
137
|
+
// verifiedCommentedDirective
|
|
138
|
+
verifiedCommentedDirective,
|
|
139
|
+
// expectedReactDirectiveAsText
|
|
140
|
+
expectedReactDirectiveAsText,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
return skipTrue;
|
|
144
|
+
}
|
|
145
|
+
|
|
101
146
|
return { skip: undefined, verifiedCommentedDirective };
|
|
102
147
|
};
|
|
103
148
|
|
|
104
149
|
/* importedFileFlow */
|
|
105
150
|
|
|
106
151
|
/**
|
|
107
|
-
*
|
|
108
|
-
* @param {Context} context
|
|
109
|
-
* @param {ImportDeclaration} node
|
|
110
|
-
* @returns
|
|
152
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#IMPORTEDFILEFLOW
|
|
153
|
+
* @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
|
|
154
|
+
* @param {ImportDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
|
|
155
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#IMPORTEDFILEFLOW (And now we the added results of `analyzeExportsForReExports`.)
|
|
111
156
|
*/
|
|
112
157
|
const importedFileFlow = (context, node) => {
|
|
113
|
-
const skipTrue = {
|
|
158
|
+
const skipTrue = {
|
|
159
|
+
...skip,
|
|
160
|
+
importedFileCommentedDirective: undefined,
|
|
161
|
+
analyzeExportsForReExportsResults: undefined,
|
|
162
|
+
};
|
|
114
163
|
|
|
115
164
|
// finds the full path of the import
|
|
116
165
|
const resolvedImportPath = resolveImportingPath(
|
|
@@ -130,15 +179,17 @@ const importedFileFlow = (context, node) => {
|
|
|
130
179
|
if (!isImportedFileJS) return skipTrue;
|
|
131
180
|
|
|
132
181
|
// GETTING THE DIRECTIVE (or lack thereof) OF THE IMPORTED FILE
|
|
133
|
-
let
|
|
134
|
-
|
|
182
|
+
let {
|
|
183
|
+
commentedDirective: importedFileCommentedDirective,
|
|
184
|
+
sourceCode: importedFileSourceCode,
|
|
185
|
+
} = getCommentedDirectiveFromImportedModule(resolvedImportPath);
|
|
135
186
|
|
|
136
187
|
// returns early if there is no directive or no valid directive (same, but eventually no directive could have defaults)
|
|
137
188
|
if (!importedFileCommentedDirective) {
|
|
138
189
|
// Now silencing the warning as superfluous, in order to not warn on imports of files without a commented directive that are outside of linting range.
|
|
139
190
|
|
|
140
191
|
// console.warn(
|
|
141
|
-
// `WARNING. The imported file ${resolvedImportPath}, whose path has been resolved from ${context.filename}, has no commented
|
|
192
|
+
// `WARNING. The imported file ${resolvedImportPath}, whose path has been resolved from ${context.filename}, has no commented $COMMENT#JSDOC#FORCOMPOSEDVARIABLES#DIRECTIVEPERIOD It is thus ignored since the report on that circumstance would be available on the imported file itself.`
|
|
142
193
|
// ); // The decision not to report has been taken to not inflate the number of warnings.
|
|
143
194
|
return skipTrue;
|
|
144
195
|
}
|
|
@@ -160,7 +211,7 @@ const importedFileFlow = (context, node) => {
|
|
|
160
211
|
if (importingFileCommentedDirective === null) {
|
|
161
212
|
context.report({
|
|
162
213
|
node,
|
|
163
|
-
messageId:
|
|
214
|
+
messageId: importNotStrategizedMessageId,
|
|
164
215
|
});
|
|
165
216
|
return skipTrue;
|
|
166
217
|
}
|
|
@@ -169,17 +220,37 @@ const importedFileFlow = (context, node) => {
|
|
|
169
220
|
importedFileCommentedDirective = importingFileCommentedDirective;
|
|
170
221
|
}
|
|
171
222
|
|
|
172
|
-
|
|
223
|
+
// you never know
|
|
224
|
+
if (!importedFileSourceCode) {
|
|
225
|
+
console.warn(
|
|
226
|
+
`Somehow, file "${resolvedImportPath}" does not have a SourceCode object obtainable.`
|
|
227
|
+
);
|
|
228
|
+
return {
|
|
229
|
+
skip: undefined,
|
|
230
|
+
importedFileCommentedDirective,
|
|
231
|
+
analyzeExportsForReExportsResults: undefined,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const analyzeExportsForReExportsResults = analyzeExportsForReExports(
|
|
236
|
+
importedFileSourceCode
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
skip: undefined,
|
|
241
|
+
importedFileCommentedDirective,
|
|
242
|
+
analyzeExportsForReExportsResults,
|
|
243
|
+
};
|
|
173
244
|
};
|
|
174
245
|
|
|
175
246
|
/* importsFlow */
|
|
176
247
|
|
|
177
248
|
/**
|
|
178
|
-
*
|
|
179
|
-
* @param {Context} context
|
|
180
|
-
* @param {ImportDeclaration} node
|
|
181
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
182
|
-
* @returns
|
|
249
|
+
* $COMMENT#JSDOC#FORALIASVARIABLES#IMPORTSFLOW
|
|
250
|
+
* @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
|
|
251
|
+
* @param {ImportDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
|
|
252
|
+
* @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
|
|
253
|
+
* @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
|
|
183
254
|
*/
|
|
184
255
|
export const importsFlow = (context, node, currentFileCommentedDirective) => {
|
|
185
256
|
// does not operate on `import type`
|
|
@@ -214,22 +285,73 @@ export const importsFlow = (context, node, currentFileCommentedDirective) => {
|
|
|
214
285
|
},
|
|
215
286
|
});
|
|
216
287
|
}
|
|
288
|
+
|
|
289
|
+
// new
|
|
290
|
+
if (result.analyzeExportsForReExportsResults) {
|
|
291
|
+
const { reExportsWithSource, reExportsViaLocal } =
|
|
292
|
+
result.analyzeExportsForReExportsResults;
|
|
293
|
+
// console.debug("reExportsWithSource are:", reExportsWithSource);
|
|
294
|
+
// console.debug("reExportsViaLocal are:", reExportsViaLocal);
|
|
295
|
+
// console.debug(
|
|
296
|
+
// "currentFileCommentedDirective is:",
|
|
297
|
+
// currentFileCommentedDirective
|
|
298
|
+
// );
|
|
299
|
+
// console.debug(
|
|
300
|
+
// "importedFileCommentedDirective is:",
|
|
301
|
+
// importedFileCommentedDirective
|
|
302
|
+
// );
|
|
303
|
+
// console.debug(context.sourceCode.getText(node));
|
|
304
|
+
|
|
305
|
+
// immediately returns if no re-exports are found
|
|
306
|
+
if (reExportsWithSource.length === 0 && reExportsViaLocal.length === 0)
|
|
307
|
+
return;
|
|
308
|
+
|
|
309
|
+
/** @type {Environment} */
|
|
310
|
+
const currentFileEnvironment = currentFileCommentedDirective.split(" ")[1];
|
|
311
|
+
/** @type {Environment} */
|
|
312
|
+
const importedFileEnvironment =
|
|
313
|
+
importedFileCommentedDirective.split(" ")[1];
|
|
314
|
+
// console.debug("currentFileEnvironment is:", currentFileEnvironment);
|
|
315
|
+
// console.debug("importedFileEnvironment is:", importedFileEnvironment);
|
|
316
|
+
|
|
317
|
+
if (
|
|
318
|
+
!environments_allowedChainImportEnvironments[
|
|
319
|
+
currentFileEnvironment
|
|
320
|
+
].includes(importedFileEnvironment)
|
|
321
|
+
) {
|
|
322
|
+
// console.debug(cantChainImportAcrossEnvironmentsMessageId);
|
|
323
|
+
|
|
324
|
+
context.report({
|
|
325
|
+
node,
|
|
326
|
+
messageId: cantChainImportAcrossEnvironmentsMessageId,
|
|
327
|
+
data: {
|
|
328
|
+
// currentFileEnvironment:
|
|
329
|
+
currentFileEnvironment,
|
|
330
|
+
// importedFileEnvironment:
|
|
331
|
+
importedFileEnvironment,
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
217
336
|
};
|
|
218
337
|
|
|
219
338
|
/* allExportsFlow */
|
|
220
339
|
|
|
221
340
|
/**
|
|
222
|
-
*
|
|
223
|
-
* @param {Context} context
|
|
224
|
-
* @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node
|
|
225
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
226
|
-
* @returns
|
|
341
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#ALLEXPORTSFLOW
|
|
342
|
+
* @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
|
|
343
|
+
* @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
|
|
344
|
+
* @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
|
|
345
|
+
* @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
|
|
227
346
|
*/
|
|
228
347
|
export const allExportsFlow = (
|
|
229
348
|
context,
|
|
230
349
|
node,
|
|
231
350
|
currentFileCommentedDirective
|
|
232
351
|
) => {
|
|
352
|
+
// saving the original commented directive (speficially for "use agnostic strategies")
|
|
353
|
+
const originalCurrentFileCommentedDirective = currentFileCommentedDirective;
|
|
354
|
+
|
|
233
355
|
// does not operate on `export type`
|
|
234
356
|
if (node.exportKind === "type") return;
|
|
235
357
|
|
|
@@ -271,5 +393,56 @@ export const allExportsFlow = (
|
|
|
271
393
|
},
|
|
272
394
|
});
|
|
273
395
|
}
|
|
396
|
+
|
|
397
|
+
// new
|
|
398
|
+
if (result.analyzeExportsForReExportsResults) {
|
|
399
|
+
const { reExportsWithSource, reExportsViaLocal } =
|
|
400
|
+
result.analyzeExportsForReExportsResults;
|
|
401
|
+
// console.debug("reExportsWithSource are:", reExportsWithSource);
|
|
402
|
+
// console.debug("reExportsViaLocal are:", reExportsViaLocal);
|
|
403
|
+
// console.debug(
|
|
404
|
+
// "currentFileCommentedDirective is:",
|
|
405
|
+
// currentFileCommentedDirective
|
|
406
|
+
// );
|
|
407
|
+
// console.debug(
|
|
408
|
+
// "importedFileCommentedDirective is:",
|
|
409
|
+
// importedFileCommentedDirective
|
|
410
|
+
// );
|
|
411
|
+
// console.debug(context.sourceCode.getText(node));
|
|
412
|
+
|
|
413
|
+
// immediately returns if no re-exports are found
|
|
414
|
+
if (reExportsWithSource.length === 0 && reExportsViaLocal.length === 0)
|
|
415
|
+
return;
|
|
416
|
+
|
|
417
|
+
if (originalCurrentFileCommentedDirective !== USE_AGNOSTIC_STRATEGIES) {
|
|
418
|
+
/** @type {Environment} */
|
|
419
|
+
const currentFileEnvironment =
|
|
420
|
+
currentFileCommentedDirective.split(" ")[1];
|
|
421
|
+
/** @type {Environment} */
|
|
422
|
+
const importedFileEnvironment =
|
|
423
|
+
importedFileCommentedDirective.split(" ")[1];
|
|
424
|
+
// console.debug("currentFileEnvironment is:", currentFileEnvironment);
|
|
425
|
+
// console.debug("importedFileEnvironment is:", importedFileEnvironment);
|
|
426
|
+
|
|
427
|
+
if (
|
|
428
|
+
!environments_allowedChainImportEnvironments[
|
|
429
|
+
currentFileEnvironment
|
|
430
|
+
].includes(importedFileEnvironment)
|
|
431
|
+
) {
|
|
432
|
+
// console.debug(cantChainImportAcrossEnvironmentsMessageId);
|
|
433
|
+
|
|
434
|
+
context.report({
|
|
435
|
+
node,
|
|
436
|
+
messageId: cantChainImportAcrossEnvironmentsMessageId,
|
|
437
|
+
data: {
|
|
438
|
+
// currentFileEnvironment:
|
|
439
|
+
currentFileEnvironment,
|
|
440
|
+
// importedFileEnvironment:
|
|
441
|
+
importedFileEnvironment,
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
274
447
|
}
|
|
275
448
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getSourceCodeFromFilePath } from "get-sourcecode-from-file-path";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { exportNotStrategizedMessageId } from "../../../_commons/constants/bases.js";
|
|
4
4
|
import {
|
|
5
5
|
USE_AGNOSTIC_STRATEGIES,
|
|
6
6
|
commentedDirectivesArray,
|
|
@@ -31,9 +31,9 @@ import {
|
|
|
31
31
|
/* getCommentedDirectiveFromSourceCode */
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param {string} string
|
|
36
|
-
* @returns
|
|
34
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#DETECTQUOTETYPE
|
|
35
|
+
* @param {string} string $COMMENT#JSDOC#PARAMS#DIRECTIVE21#STRING
|
|
36
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#DETECTQUOTETYPE
|
|
37
37
|
*/
|
|
38
38
|
const detectQuoteType = (string) => {
|
|
39
39
|
if (string.startsWith("'") && string.endsWith("'")) {
|
|
@@ -46,9 +46,9 @@ const detectQuoteType = (string) => {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @param {string} string
|
|
51
|
-
* @returns
|
|
49
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#STRIPSINGLEQUOTES
|
|
50
|
+
* @param {string} string $COMMENT#JSDOC#PARAMS#DIRECTIVE21#STRING
|
|
51
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#STRIPSINGLEQUOTES
|
|
52
52
|
*/
|
|
53
53
|
const stripSingleQuotes = (string) => {
|
|
54
54
|
if (string.startsWith("'") && string.endsWith("'")) {
|
|
@@ -58,9 +58,9 @@ const stripSingleQuotes = (string) => {
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
62
|
-
* @param {string} string
|
|
63
|
-
* @returns
|
|
61
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#STRIPDOUBLEQUOTES
|
|
62
|
+
* @param {string} string $COMMENT#JSDOC#PARAMS#DIRECTIVE21#STRING
|
|
63
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#STRIPSINGLEQUOTES
|
|
64
64
|
*/
|
|
65
65
|
const stripDoubleQuotes = (string) => {
|
|
66
66
|
if (string.startsWith('"') && string.endsWith('"')) {
|
|
@@ -70,21 +70,21 @@ const stripDoubleQuotes = (string) => {
|
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
73
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE1
|
|
74
74
|
*
|
|
75
|
-
*
|
|
76
|
-
* -
|
|
77
|
-
* -
|
|
78
|
-
* -
|
|
79
|
-
* -
|
|
80
|
-
* -
|
|
81
|
-
* -
|
|
82
|
-
* -
|
|
83
|
-
* -
|
|
84
|
-
* -
|
|
85
|
-
* -
|
|
86
|
-
* @param {SourceCode} sourceCode
|
|
87
|
-
* @returns
|
|
75
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE2
|
|
76
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERLOGICSA
|
|
77
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTLOGICSA
|
|
78
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICLOGICSA
|
|
79
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERCOMPONENTSA
|
|
80
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCOMPONENTSA
|
|
81
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCOMPONENTSA
|
|
82
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERFUNCTIONSA
|
|
83
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCONTEXTSA
|
|
84
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCONDITIONSA
|
|
85
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICSTRATEGIESA
|
|
86
|
+
* @param {SourceCode} sourceCode $COMMENT#JSDOC#PARAMS#DIRECTIVE21#SOURCECODE
|
|
87
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE
|
|
88
88
|
*/
|
|
89
89
|
export const getCommentedDirectiveFromSourceCode = (sourceCode) => {
|
|
90
90
|
// gets all comments from the source code
|
|
@@ -132,21 +132,21 @@ export const getCommentedDirectiveFromSourceCode = (sourceCode) => {
|
|
|
132
132
|
/* getCommentedDirectiveFromCurrentModule */
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
135
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMCURRENTMODULE1
|
|
136
136
|
*
|
|
137
|
-
*
|
|
138
|
-
* -
|
|
139
|
-
* -
|
|
140
|
-
* -
|
|
141
|
-
* -
|
|
142
|
-
* -
|
|
143
|
-
* -
|
|
144
|
-
* -
|
|
145
|
-
* -
|
|
146
|
-
* -
|
|
147
|
-
* -
|
|
148
|
-
* @param {Context} context
|
|
149
|
-
* @returns
|
|
137
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE2
|
|
138
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERLOGICSA
|
|
139
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTLOGICSA
|
|
140
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICLOGICSA
|
|
141
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERCOMPONENTSA
|
|
142
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCOMPONENTSA
|
|
143
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCOMPONENTSA
|
|
144
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERFUNCTIONSA
|
|
145
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCONTEXTSA
|
|
146
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCONDITIONSA
|
|
147
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICSTRATEGIESA
|
|
148
|
+
* @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
|
|
149
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE
|
|
150
150
|
*/
|
|
151
151
|
export const getCommentedDirectiveFromCurrentModule = (context) => {
|
|
152
152
|
const sourceCode = context.sourceCode;
|
|
@@ -158,46 +158,46 @@ export const getCommentedDirectiveFromCurrentModule = (context) => {
|
|
|
158
158
|
/* getCommentedDirectiveFromImportedModule */
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
|
-
*
|
|
161
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMIMPORTEDMODULE1
|
|
162
162
|
*
|
|
163
|
-
*
|
|
164
|
-
* -
|
|
165
|
-
* -
|
|
166
|
-
* -
|
|
167
|
-
* -
|
|
168
|
-
* -
|
|
169
|
-
* -
|
|
170
|
-
* -
|
|
171
|
-
* -
|
|
172
|
-
* -
|
|
173
|
-
* -
|
|
174
|
-
* @param {string} resolvedPath
|
|
175
|
-
* @returns
|
|
163
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE2
|
|
164
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERLOGICSA
|
|
165
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTLOGICSA
|
|
166
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICLOGICSA
|
|
167
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERCOMPONENTSA
|
|
168
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCOMPONENTSA
|
|
169
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCOMPONENTSA
|
|
170
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERFUNCTIONSA
|
|
171
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCONTEXTSA
|
|
172
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCONDITIONSA
|
|
173
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICSTRATEGIESA
|
|
174
|
+
* @param {string} resolvedPath $COMMENT#JSDOC#PARAMS#RESOLVEDPATH
|
|
175
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETCOMMENTEDDIRECTIVEFROMSOURCECODE Now also provides the obtained SourceCode object.
|
|
176
176
|
*/
|
|
177
177
|
export const getCommentedDirectiveFromImportedModule = (resolvedPath) => {
|
|
178
178
|
const sourceCode = getSourceCodeFromFilePath(resolvedPath);
|
|
179
179
|
const commentedDirective = getCommentedDirectiveFromSourceCode(sourceCode);
|
|
180
180
|
|
|
181
|
-
return commentedDirective;
|
|
181
|
+
return { commentedDirective, sourceCode };
|
|
182
182
|
};
|
|
183
183
|
|
|
184
184
|
/* getVerifiedCommentedDirective */
|
|
185
185
|
|
|
186
186
|
/**
|
|
187
|
-
*
|
|
188
|
-
* -
|
|
189
|
-
* -
|
|
190
|
-
* -
|
|
191
|
-
* -
|
|
192
|
-
* -
|
|
193
|
-
* -
|
|
194
|
-
* -
|
|
195
|
-
* -
|
|
196
|
-
* -
|
|
197
|
-
* -
|
|
198
|
-
* @param {CommentedDirective} directive
|
|
199
|
-
* @param {Extension} extension
|
|
200
|
-
* @returns
|
|
187
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETVERIFIEDCOMMENTEDDIRECTIVE
|
|
188
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERLOGICSB
|
|
189
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTLOGICSB
|
|
190
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICLOGICSB
|
|
191
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERCOMPONENTSB
|
|
192
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCOMPONENTSB
|
|
193
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCOMPONENTSB
|
|
194
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USESERVERFUNCTIONSB
|
|
195
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USECLIENTCONTEXTSB
|
|
196
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICCONDITIONSB
|
|
197
|
+
* - $COMMENT#JSDOC#DETAILS#DIRECTIVE21#USEAGNOSTICSTRATEGIESB
|
|
198
|
+
* @param {CommentedDirective} directive $COMMENT#JSDOC#PARAMS#DIRECTIVE21#DIRECTIVE
|
|
199
|
+
* @param {Extension} extension $COMMENT#JSDOC#PARAMS#EXTENSION
|
|
200
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETVERIFIEDCOMMENTEDDIRECTIVE
|
|
201
201
|
*/
|
|
202
202
|
export const getVerifiedCommentedDirective = (directive, extension) => {
|
|
203
203
|
const rule = commentedDirectives_extensionRules[directive];
|
|
@@ -214,10 +214,10 @@ export const getVerifiedCommentedDirective = (directive, extension) => {
|
|
|
214
214
|
/* getStrategizedDirective */
|
|
215
215
|
|
|
216
216
|
/**
|
|
217
|
-
*
|
|
218
|
-
* @param {Context} context
|
|
219
|
-
* @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node
|
|
220
|
-
* @returns
|
|
217
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#GETSTRATEGIZEDDIRECTIVE
|
|
218
|
+
* @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
|
|
219
|
+
* @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
|
|
220
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#GETSTRATEGIZEDDIRECTIVE
|
|
221
221
|
*/
|
|
222
222
|
export const getStrategizedDirective = (context, node) => {
|
|
223
223
|
// gets the first nested `/* */` comment inside the node
|
|
@@ -246,11 +246,11 @@ export const getStrategizedDirective = (context, node) => {
|
|
|
246
246
|
/* addressDirectiveIfAgnosticStrategies */
|
|
247
247
|
|
|
248
248
|
/**
|
|
249
|
-
*
|
|
250
|
-
* @param {Context} context
|
|
251
|
-
* @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node
|
|
252
|
-
* @param {CommentedDirective} currentFileCommentedDirective
|
|
253
|
-
* @returns
|
|
249
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#ADDRESSDIRECTIVEIFAGNOSTICSTRATEGIES
|
|
250
|
+
* @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
|
|
251
|
+
* @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
|
|
252
|
+
* @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
|
|
253
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#ADDRESSDIRECTIVEIFAGNOSTICSTRATEGIES
|
|
254
254
|
*/
|
|
255
255
|
export const addressDirectiveIfAgnosticStrategies = (
|
|
256
256
|
context,
|
|
@@ -266,7 +266,7 @@ export const addressDirectiveIfAgnosticStrategies = (
|
|
|
266
266
|
if (exportStrategizedDirective === null) {
|
|
267
267
|
context.report({
|
|
268
268
|
node,
|
|
269
|
-
messageId:
|
|
269
|
+
messageId: exportNotStrategizedMessageId,
|
|
270
270
|
});
|
|
271
271
|
}
|
|
272
272
|
|
|
@@ -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
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#ISIMPORTBLOCKED
|
|
280
|
+
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
|
|
281
|
+
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#IMPORTEDFILECOMMENTEDDIRECTIVE
|
|
282
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#ISIMPORTBLOCKED
|
|
283
283
|
*/
|
|
284
284
|
export const isImportBlocked = (
|
|
285
285
|
currentFileCommentedDirective,
|
|
@@ -294,9 +294,9 @@ export const isImportBlocked = (
|
|
|
294
294
|
/* makeMessageFromCurrentFileCommentedDirective */
|
|
295
295
|
|
|
296
296
|
/**
|
|
297
|
-
*
|
|
298
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} commentedDirective
|
|
299
|
-
* @returns
|
|
297
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#MAKEMESSAGEFROMCURRENTFILECOMMENTEDDIRECTIVE
|
|
298
|
+
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} commentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#COMMENTEDDIRECTIVE
|
|
299
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#MAKEMESSAGEFROMCURRENTFILECOMMENTEDDIRECTIVE
|
|
300
300
|
*/
|
|
301
301
|
export const makeMessageFromCurrentFileCommentedDirective = (
|
|
302
302
|
commentedDirective
|
|
@@ -309,10 +309,10 @@ export const makeMessageFromCurrentFileCommentedDirective = (
|
|
|
309
309
|
/* findSpecificViolationMessage */
|
|
310
310
|
|
|
311
311
|
/**
|
|
312
|
-
*
|
|
313
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective
|
|
314
|
-
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective
|
|
315
|
-
* @returns
|
|
312
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#FINDSPECIFICVIOLATIONMESSAGE
|
|
313
|
+
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
|
|
314
|
+
* @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#IMPORTEDFILECOMMENTEDDIRECTIVE
|
|
315
|
+
* @returns $COMMENT#JSDOC#RETURNS#FINDSPECIFICVIOLATIONMESSAGE
|
|
316
316
|
*/
|
|
317
317
|
export const findSpecificViolationMessage = (
|
|
318
318
|
currentFileCommentedDirective,
|
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param {Plugin} plugin
|
|
17
|
-
* @returns
|
|
15
|
+
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#MAKEDIRECTIVE21CONFIG
|
|
16
|
+
* @param {Plugin} plugin $COMMENT#JSDOC#PARAMS#PLUGIN
|
|
17
|
+
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#MAKEDIRECTIVE21CONFIG
|
|
18
18
|
*/
|
|
19
19
|
export const makeDirective21Config = (plugin) => ({
|
|
20
20
|
[directive21ConfigName]: defineConfig([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-use-agnostic",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.10",
|
|
4
4
|
"description": "Highlights problematic server-client imports in projects made with the Fullstack React Architecture.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"find-up": "^8.0.0",
|
|
47
|
-
"get-sourcecode-from-file-path": "^1.1.
|
|
47
|
+
"get-sourcecode-from-file-path": "^1.1.3",
|
|
48
48
|
"resolve-importing-path": "^1.0.3",
|
|
49
49
|
"typescript-eslint": "^8.32.0"
|
|
50
50
|
},
|