eslint-plugin-use-agnostic 2.0.7 → 2.0.9
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.
|
@@ -101,6 +101,7 @@ In this context, {{ ${specificFailure} }} `,
|
|
|
101
101
|
rootPath,
|
|
102
102
|
tsConfigPaths,
|
|
103
103
|
);
|
|
104
|
+
console.debug("absoluteTsConfigPaths is:", absoluteTsConfigPaths);
|
|
104
105
|
const resolver = makeResolverFromAbsoluteTsConfigPaths(
|
|
105
106
|
absoluteTsConfigPaths,
|
|
106
107
|
);
|
|
@@ -111,17 +112,17 @@ In this context, {{ ${specificFailure} }} `,
|
|
|
111
112
|
|
|
112
113
|
return {
|
|
113
114
|
ImportDeclaration: (node) =>
|
|
114
|
-
importsFlow(context, node, verifiedCommentedDirective),
|
|
115
|
+
importsFlow(context, node, verifiedCommentedDirective, resolver),
|
|
115
116
|
ImportExpression: (node) =>
|
|
116
|
-
importsFlow(context, node, verifiedCommentedDirective),
|
|
117
|
+
importsFlow(context, node, verifiedCommentedDirective, resolver),
|
|
117
118
|
ExportNamedDeclaration: (node) =>
|
|
118
|
-
allExportsFlow(context, node, verifiedCommentedDirective),
|
|
119
|
+
allExportsFlow(context, node, verifiedCommentedDirective, resolver),
|
|
119
120
|
ExportAllDeclaration: (node) =>
|
|
120
|
-
allExportsFlow(context, node, verifiedCommentedDirective),
|
|
121
|
+
allExportsFlow(context, node, verifiedCommentedDirective, resolver),
|
|
121
122
|
ExportDefaultDeclaration: (node) =>
|
|
122
|
-
allExportsFlow(context, node, verifiedCommentedDirective),
|
|
123
|
+
allExportsFlow(context, node, verifiedCommentedDirective, resolver),
|
|
123
124
|
CallExpression: (node) =>
|
|
124
|
-
importsFlowRequire(context, node, verifiedCommentedDirective),
|
|
125
|
+
importsFlowRequire(context, node, verifiedCommentedDirective, resolver),
|
|
125
126
|
|
|
126
127
|
FunctionDeclaration: (node) =>
|
|
127
128
|
functionDeclarationFlow(context, node, verifiedCommentedDirective),
|
|
@@ -135,14 +136,11 @@ In this context, {{ ${specificFailure} }} `,
|
|
|
135
136
|
|
|
136
137
|
const getTsConfigPaths = (rootPath) => {
|
|
137
138
|
const tsConfigJsonPath = path.join(rootPath, "tsconfig.json");
|
|
138
|
-
console.debug("tsConfigJsonPath is:", tsConfigJsonPath);
|
|
139
|
-
|
|
140
139
|
const parsed = ts.getParsedCommandLineOfConfigFile(
|
|
141
140
|
tsConfigJsonPath,
|
|
142
141
|
{},
|
|
143
142
|
ts.sys,
|
|
144
143
|
);
|
|
145
|
-
console.debug(tsConfigJsonPath);
|
|
146
144
|
|
|
147
145
|
if (!parsed) return {};
|
|
148
146
|
|
|
@@ -68,6 +68,7 @@ import { analyzeExportsForReExports } from "./analyze-exports-re.js";
|
|
|
68
68
|
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').JSXOpeningElement} JSXOpeningElement
|
|
69
69
|
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').Parameter} Parameter
|
|
70
70
|
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').Environment} Environment
|
|
71
|
+
* @typedef {import('../../../../types/directive21/_commons/typedefs.js').ResolverFactory} ResolverFactory
|
|
71
72
|
*/
|
|
72
73
|
|
|
73
74
|
/* currentFileFlow */
|
|
@@ -234,9 +235,10 @@ export const currentFileFlow = (context) => {
|
|
|
234
235
|
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#IMPORTEDFILEFLOW
|
|
235
236
|
* @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
|
|
236
237
|
* @param {ImportDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
|
|
238
|
+
* @param {ResolverFactory} resolver
|
|
237
239
|
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#IMPORTEDFILEFLOW
|
|
238
240
|
*/
|
|
239
|
-
const importedFileFlow = (context, node) => {
|
|
241
|
+
const importedFileFlow = (context, node, resolver) => {
|
|
240
242
|
const skipTrue = {
|
|
241
243
|
...skip,
|
|
242
244
|
importedFileCommentedDirective: undefined,
|
|
@@ -244,13 +246,16 @@ const importedFileFlow = (context, node) => {
|
|
|
244
246
|
};
|
|
245
247
|
|
|
246
248
|
// finds the full path of the import
|
|
247
|
-
const resolvedImportPath = resolveImportingPath(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
);
|
|
249
|
+
// const resolvedImportPath = resolveImportingPath(
|
|
250
|
+
// path.dirname(context.filename),
|
|
251
|
+
// node.source.value,
|
|
252
|
+
// findUpSync("tsconfig.json", {
|
|
253
|
+
// cwd: path.dirname(context.filename),
|
|
254
|
+
// }) ?? context.cwd,
|
|
255
|
+
// );
|
|
256
|
+
const resolvedImportPath =
|
|
257
|
+
resolver.resolveFileSync(context.filename, node.source.value).path ?? null;
|
|
258
|
+
console.debug("resolvedImportPath is:", resolvedImportPath);
|
|
254
259
|
|
|
255
260
|
// does not operate on paths it did not resolve
|
|
256
261
|
if (resolvedImportPath === null) return skipTrue;
|
|
@@ -336,9 +341,10 @@ const importedFileFlow = (context, node) => {
|
|
|
336
341
|
* $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#IMPORTEDFILEFLOWREQUIRE
|
|
337
342
|
* @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
|
|
338
343
|
* @param {CallExpression} node $COMMENT#JSDOC#PARAMS#NODE
|
|
344
|
+
* @param {ResolverFactory} resolver
|
|
339
345
|
* @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#IMPORTEDFILEFLOW
|
|
340
346
|
*/
|
|
341
|
-
const importedFileFlowRequire = (context, node) => {
|
|
347
|
+
const importedFileFlowRequire = (context, node, resolver) => {
|
|
342
348
|
const skipTrue = {
|
|
343
349
|
...skip,
|
|
344
350
|
importedFileCommentedDirective: undefined,
|
|
@@ -356,13 +362,16 @@ const importedFileFlowRequire = (context, node) => {
|
|
|
356
362
|
if (typeof importPath !== "string") return skipTrue;
|
|
357
363
|
|
|
358
364
|
// finds the full path of the import
|
|
359
|
-
const resolvedImportPath = resolveImportingPath(
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
);
|
|
365
|
+
// const resolvedImportPath = resolveImportingPath(
|
|
366
|
+
// path.dirname(context.filename),
|
|
367
|
+
// importPath,
|
|
368
|
+
// findUpSync("tsconfig.json", {
|
|
369
|
+
// cwd: path.dirname(context.filename),
|
|
370
|
+
// }) ?? context.cwd,
|
|
371
|
+
// );
|
|
372
|
+
const resolvedImportPath =
|
|
373
|
+
resolver.resolveFileSync(context.filename, importPath).path ?? null;
|
|
374
|
+
console.debug("resolvedImportPath (require) is:", resolvedImportPath);
|
|
366
375
|
|
|
367
376
|
// does not operate on paths it did not resolve
|
|
368
377
|
if (resolvedImportPath === null) return skipTrue;
|
|
@@ -448,13 +457,19 @@ const importedFileFlowRequire = (context, node) => {
|
|
|
448
457
|
* @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
|
|
449
458
|
* @param {ImportDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
|
|
450
459
|
* @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
|
|
460
|
+
* @param {ResolverFactory} resolver
|
|
451
461
|
* @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
|
|
452
462
|
*/
|
|
453
|
-
export const importsFlow = (
|
|
463
|
+
export const importsFlow = (
|
|
464
|
+
context,
|
|
465
|
+
node,
|
|
466
|
+
currentFileCommentedDirective,
|
|
467
|
+
resolver,
|
|
468
|
+
) => {
|
|
454
469
|
// does not operate on `import type`
|
|
455
470
|
if (node.importKind === "type") return;
|
|
456
471
|
|
|
457
|
-
const result = importedFileFlow(context, node);
|
|
472
|
+
const result = importedFileFlow(context, node, resolver);
|
|
458
473
|
|
|
459
474
|
if (result.skip) return;
|
|
460
475
|
const { importedFileCommentedDirective } = result;
|
|
@@ -525,14 +540,16 @@ export const importsFlow = (context, node, currentFileCommentedDirective) => {
|
|
|
525
540
|
* @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
|
|
526
541
|
* @param {CallExpression} node $COMMENT#JSDOC#PARAMS#NODE
|
|
527
542
|
* @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
|
|
543
|
+
* @param {ResolverFactory} resolver
|
|
528
544
|
* @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
|
|
529
545
|
*/
|
|
530
546
|
export const importsFlowRequire = (
|
|
531
547
|
context,
|
|
532
548
|
node,
|
|
533
549
|
currentFileCommentedDirective,
|
|
550
|
+
resolver,
|
|
534
551
|
) => {
|
|
535
|
-
const result = importedFileFlowRequire(context, node);
|
|
552
|
+
const result = importedFileFlowRequire(context, node, resolver);
|
|
536
553
|
|
|
537
554
|
if (result.skip) return;
|
|
538
555
|
const { importedFileCommentedDirective } = result;
|
|
@@ -604,12 +621,14 @@ export const importsFlowRequire = (
|
|
|
604
621
|
* @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
|
|
605
622
|
* @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
|
|
606
623
|
* @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
|
|
624
|
+
* @param {ResolverFactory} resolver
|
|
607
625
|
* @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
|
|
608
626
|
*/
|
|
609
627
|
export const allExportsFlow = (
|
|
610
628
|
context,
|
|
611
629
|
node,
|
|
612
630
|
currentFileCommentedDirective,
|
|
631
|
+
resolver,
|
|
613
632
|
) => {
|
|
614
633
|
// saving the original commented directive (speficially for "use agnostic strategies")
|
|
615
634
|
const originalCurrentFileCommentedDirective = currentFileCommentedDirective;
|
|
@@ -627,7 +646,7 @@ export const allExportsFlow = (
|
|
|
627
646
|
}
|
|
628
647
|
// re-exports scenarios
|
|
629
648
|
else {
|
|
630
|
-
const result = importedFileFlow(context, node);
|
|
649
|
+
const result = importedFileFlow(context, node, resolver);
|
|
631
650
|
|
|
632
651
|
if (result.skip) return;
|
|
633
652
|
const { importedFileCommentedDirective } = result;
|