eslint-plugin-use-agnostic 2.0.6 → 2.0.8

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.
@@ -88,8 +88,6 @@ In this context, {{ ${specificFailure} }} `,
88
88
  const rootPath = /** @type {string | undefined} */ (
89
89
  context.settings.eXtraJSX?.rootPath
90
90
  );
91
- console.debug("context.settings are:", context.settings);
92
- console.debug("context.settings.eXtraJSX are:", context.settings.eXtraJSX);
93
91
  console.debug("reactFolder is:", reactFolder);
94
92
  console.debug("rootPath is:", rootPath);
95
93
 
@@ -98,7 +96,12 @@ In this context, {{ ${specificFailure} }} `,
98
96
  // pass the resolver to importsFlow, allExportsFlow, importsFlowRequire (resolver.resolveFileSync, getCommentedDirectiveFromModule)
99
97
 
100
98
  const tsConfigPaths = getTsConfigPaths(rootPath);
101
- const absoluteTsConfigPaths = makeAbsoluteFromTsConfigPaths(tsConfigPaths);
99
+ console.debug("tsConfigPaths is:", tsConfigPaths);
100
+ const absoluteTsConfigPaths = makeAbsoluteFromTsConfigPaths(
101
+ rootPath,
102
+ tsConfigPaths,
103
+ );
104
+ console.debug("absoluteTsConfigPaths is:", absoluteTsConfigPaths);
102
105
  const resolver = makeResolverFromAbsoluteTsConfigPaths(
103
106
  absoluteTsConfigPaths,
104
107
  );
@@ -109,17 +112,17 @@ In this context, {{ ${specificFailure} }} `,
109
112
 
110
113
  return {
111
114
  ImportDeclaration: (node) =>
112
- importsFlow(context, node, verifiedCommentedDirective),
115
+ importsFlow(context, node, verifiedCommentedDirective, resolver),
113
116
  ImportExpression: (node) =>
114
- importsFlow(context, node, verifiedCommentedDirective),
117
+ importsFlow(context, node, verifiedCommentedDirective, resolver),
115
118
  ExportNamedDeclaration: (node) =>
116
- allExportsFlow(context, node, verifiedCommentedDirective),
119
+ allExportsFlow(context, node, verifiedCommentedDirective, resolver),
117
120
  ExportAllDeclaration: (node) =>
118
- allExportsFlow(context, node, verifiedCommentedDirective),
121
+ allExportsFlow(context, node, verifiedCommentedDirective, resolver),
119
122
  ExportDefaultDeclaration: (node) =>
120
- allExportsFlow(context, node, verifiedCommentedDirective),
123
+ allExportsFlow(context, node, verifiedCommentedDirective, resolver),
121
124
  CallExpression: (node) =>
122
- importsFlowRequire(context, node, verifiedCommentedDirective),
125
+ importsFlowRequire(context, node, verifiedCommentedDirective, resolver),
123
126
 
124
127
  FunctionDeclaration: (node) =>
125
128
  functionDeclarationFlow(context, node, verifiedCommentedDirective),
@@ -132,8 +135,9 @@ In this context, {{ ${specificFailure} }} `,
132
135
  };
133
136
 
134
137
  const getTsConfigPaths = (rootPath) => {
138
+ const tsConfigJsonPath = path.join(rootPath, "tsconfig.json");
135
139
  const parsed = ts.getParsedCommandLineOfConfigFile(
136
- path.join(rootPath, "tsconfig.json"),
140
+ tsConfigJsonPath,
137
141
  {},
138
142
  ts.sys,
139
143
  );
@@ -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,18 @@ const importedFileFlow = (context, node) => {
244
246
  };
245
247
 
246
248
  // finds the full path of the import
247
- const resolvedImportPath = resolveImportingPath(
248
- path.dirname(context.filename),
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 = resolver.resolveFileSync(
257
+ context.filename,
249
258
  node.source.value,
250
- findUpSync("tsconfig.json", {
251
- cwd: path.dirname(context.filename),
252
- }) ?? context.cwd,
253
- );
259
+ ).path;
260
+ console.debug("resolvedImportPath is:", resolvedImportPath);
254
261
 
255
262
  // does not operate on paths it did not resolve
256
263
  if (resolvedImportPath === null) return skipTrue;
@@ -336,9 +343,10 @@ const importedFileFlow = (context, node) => {
336
343
  * $COMMENT#JSDOC#DEFINITIONS#DIRECTIVE21#IMPORTEDFILEFLOWREQUIRE
337
344
  * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
338
345
  * @param {CallExpression} node $COMMENT#JSDOC#PARAMS#NODE
346
+ * @param {ResolverFactory} resolver
339
347
  * @returns $COMMENT#JSDOC#RETURNS#DIRECTIVE21#IMPORTEDFILEFLOW
340
348
  */
341
- const importedFileFlowRequire = (context, node) => {
349
+ const importedFileFlowRequire = (context, node, resolver) => {
342
350
  const skipTrue = {
343
351
  ...skip,
344
352
  importedFileCommentedDirective: undefined,
@@ -356,13 +364,18 @@ const importedFileFlowRequire = (context, node) => {
356
364
  if (typeof importPath !== "string") return skipTrue;
357
365
 
358
366
  // finds the full path of the import
359
- const resolvedImportPath = resolveImportingPath(
360
- path.dirname(context.filename),
367
+ // const resolvedImportPath = resolveImportingPath(
368
+ // path.dirname(context.filename),
369
+ // importPath,
370
+ // findUpSync("tsconfig.json", {
371
+ // cwd: path.dirname(context.filename),
372
+ // }) ?? context.cwd,
373
+ // );
374
+ const resolvedImportPath = resolver.resolveFileSync(
375
+ context.filename,
361
376
  importPath,
362
- findUpSync("tsconfig.json", {
363
- cwd: path.dirname(context.filename),
364
- }) ?? context.cwd,
365
- );
377
+ ).path;
378
+ console.debug("resolvedImportPath (require) is:", resolvedImportPath);
366
379
 
367
380
  // does not operate on paths it did not resolve
368
381
  if (resolvedImportPath === null) return skipTrue;
@@ -448,13 +461,19 @@ const importedFileFlowRequire = (context, node) => {
448
461
  * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
449
462
  * @param {ImportDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
450
463
  * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
464
+ * @param {ResolverFactory} resolver
451
465
  * @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
452
466
  */
453
- export const importsFlow = (context, node, currentFileCommentedDirective) => {
467
+ export const importsFlow = (
468
+ context,
469
+ node,
470
+ currentFileCommentedDirective,
471
+ resolver,
472
+ ) => {
454
473
  // does not operate on `import type`
455
474
  if (node.importKind === "type") return;
456
475
 
457
- const result = importedFileFlow(context, node);
476
+ const result = importedFileFlow(context, node, resolver);
458
477
 
459
478
  if (result.skip) return;
460
479
  const { importedFileCommentedDirective } = result;
@@ -525,14 +544,16 @@ export const importsFlow = (context, node, currentFileCommentedDirective) => {
525
544
  * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
526
545
  * @param {CallExpression} node $COMMENT#JSDOC#PARAMS#NODE
527
546
  * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
547
+ * @param {ResolverFactory} resolver
528
548
  * @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
529
549
  */
530
550
  export const importsFlowRequire = (
531
551
  context,
532
552
  node,
533
553
  currentFileCommentedDirective,
554
+ resolver,
534
555
  ) => {
535
- const result = importedFileFlowRequire(context, node);
556
+ const result = importedFileFlowRequire(context, node, resolver);
536
557
 
537
558
  if (result.skip) return;
538
559
  const { importedFileCommentedDirective } = result;
@@ -604,12 +625,14 @@ export const importsFlowRequire = (
604
625
  * @param {Context} context $COMMENT#JSDOC#PARAMS#CONTEXTB
605
626
  * @param {ExportNamedDeclaration | ExportAllDeclaration | ExportDefaultDeclaration} node $COMMENT#JSDOC#PARAMS#NODE
606
627
  * @param {CommentedDirective} currentFileCommentedDirective $COMMENT#JSDOC#PARAMS#DIRECTIVE21#CURRENTFILECOMMENTEDDIRECTIVE
628
+ * @param {ResolverFactory} resolver
607
629
  * @returns $COMMENT#JSDOC#FORALIASVARIABLES#FLOWRETURNSEARLY
608
630
  */
609
631
  export const allExportsFlow = (
610
632
  context,
611
633
  node,
612
634
  currentFileCommentedDirective,
635
+ resolver,
613
636
  ) => {
614
637
  // saving the original commented directive (speficially for "use agnostic strategies")
615
638
  const originalCurrentFileCommentedDirective = currentFileCommentedDirective;
@@ -627,7 +650,7 @@ export const allExportsFlow = (
627
650
  }
628
651
  // re-exports scenarios
629
652
  else {
630
- const result = importedFileFlow(context, node);
653
+ const result = importedFileFlow(context, node, resolver);
631
654
 
632
655
  if (result.skip) return;
633
656
  const { importedFileCommentedDirective } = result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-use-agnostic",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "description": "Highlights problematic server-client imports in projects made with the Fullstack React Architecture.",
5
5
  "keywords": [
6
6
  "eslint",