eslint-plugin-use-agnostic 1.7.9 → 1.8.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.
@@ -4,8 +4,8 @@ import {
4
4
  noCommentedDirectiveMessageId,
5
5
  commentedDirectiveVerificationFailedMessageId,
6
6
  commentedDirectiveReactDirectiveFailedMessageId,
7
- importNotStrategizedMessageId,
8
- exportNotStrategizedMessageId,
7
+ // importNotStrategizedMessageId,
8
+ // exportNotStrategizedMessageId,
9
9
  cantChainImportAcrossEnvironmentsMessageId,
10
10
  } from "../../../_commons/constants/bases.js";
11
11
  import {
@@ -50,10 +50,10 @@ All targeted modules need to be marked with their respective directives (\`// "u
50
50
  [commentedDirectiveVerificationFailedMessageId]: `The commented directive could not pass verification due to an incompatible combination with its file extension.
51
51
  In this context, {{ ${specificFailure} }} `,
52
52
  [commentedDirectiveReactDirectiveFailedMessageId]: `Commented directive "{{ ${verifiedCommentedDirective} }}" requires {{ ${expectedReactDirectiveAsText} }} directive in order to communicate accordingly with the React architecture at hand. `,
53
- [importNotStrategizedMessageId]: `Imports from Agnostic Strategies Modules must be strategized (\`/* @serverLogics */\`, etc.).
54
- Please include a Strategy that corresponds to the kind of module this import would be mapped to. `,
55
- [exportNotStrategizedMessageId]: `Exports from Agnostic Strategies Modules must be strategized (\`/* @serverLogics */\`, etc.).
56
- Please include a Strategy that corresponds to the kind of module this export would be mapped to. `,
53
+ // [importNotStrategizedMessageId]: `Imports from Agnostic Strategies Modules must be strategized (\`/* @serverLogics */\`, etc.).
54
+ // Please include a Strategy that corresponds to the kind of module this import would be mapped to. `,
55
+ // [exportNotStrategizedMessageId]: `Exports from Agnostic Strategies Modules must be strategized (\`/* @serverLogics */\`, etc.).
56
+ // Please include a Strategy that corresponds to the kind of module this export would be mapped to. `,
57
57
  [cantChainImportAcrossEnvironmentsMessageId]: `Because imports are actually references instead of modules across environments, it is not possible to chain-import between the {{ ${currentFileEnvironment} }} environment and the {{ ${importedFileEnvironment} }} environment. In these cases, only direct imports apply. `,
58
58
  },
59
59
  },
@@ -10,7 +10,7 @@ import {
10
10
  noCommentedDirectiveMessageId,
11
11
  commentedDirectiveVerificationFailedMessageId,
12
12
  commentedDirectiveReactDirectiveFailedMessageId,
13
- importNotStrategizedMessageId,
13
+ // importNotStrategizedMessageId,
14
14
  cantChainImportAcrossEnvironmentsMessageId,
15
15
  skip,
16
16
  } from "../../../_commons/constants/bases.js";
@@ -29,6 +29,7 @@ import {
29
29
  environments_allowedChainImportEnvironments,
30
30
  commentedDirectives_reactDirectives,
31
31
  reactDirectives_asTexts,
32
+ USE_AGNOSTIC_CONDITIONS,
32
33
  } from "../constants/bases.js";
33
34
 
34
35
  import { highlightFirstLineOfCode } from "../../../_commons/utilities/helpers.js";
@@ -40,7 +41,7 @@ import {
40
41
  isImportBlocked,
41
42
  makeMessageFromCurrentFileCommentedDirective,
42
43
  findSpecificViolationMessage,
43
- getStrategizedDirective,
44
+ // getStrategizedDirective,
44
45
  addressDirectiveIfAgnosticStrategies,
45
46
  } from "./helpers.js";
46
47
  import { analyzeExportsForReExports } from "./analyze-exports-re.js";
@@ -192,13 +193,12 @@ export const currentFileFlow = (context) => {
192
193
  }
193
194
 
194
195
  // NEW
195
- // do not report if the module is a non-Extra JavaScript Agnostic Strategies Module, in order to allow them the freedom of doing whatever they want so they can behave in any which way they need to as convention files
196
- if (
197
- !(
198
- fileIsRegularJavaScript(context.filename) &&
199
- verifiedCommentedDirective === USE_AGNOSTIC_STRATEGIES
200
- )
201
- )
196
+ const isRegularJavaScriptAgnosticStrategies =
197
+ fileIsRegularJavaScript(context.filename) &&
198
+ verifiedCommentedDirective === USE_AGNOSTIC_STRATEGIES;
199
+
200
+ // do not report if the module is a non-Extra JavaScript Agnostic Strategies Module, in order to allow them the freedom of doing whatever they want so they can behave in any which way they need to as convention files (JSX extension still required though)
201
+ if (!isRegularJavaScriptAgnosticStrategies)
202
202
  context.report({
203
203
  loc: highlightFirstLineOfCode(context),
204
204
  messageId: commentedDirectiveReactDirectiveFailedMessageId,
@@ -271,26 +271,29 @@ const importedFileFlow = (context, node) => {
271
271
  (Consequently, details below are currently at the stage of wishful thinking.)
272
272
  Strategy exports are planned to be linting in the future within their own Agnostic Strategies Modules to ensure they respect import rules within their own scopes. It may also become possible to check whether the export and import Strategies are the same in the future when identifiers are defined and the same, especially for components modules where a convention could be for all non-type exports to be named and PascalCase. */
273
273
 
274
- if (importedFileCommentedDirective === USE_AGNOSTIC_STRATEGIES) {
275
- const importingFileCommentedDirective = getStrategizedDirective(
276
- context,
277
- node
278
- );
279
-
280
- if (
281
- importingFileCommentedDirective === null &&
282
- fileIsExtraJavaScript(context.filename)
283
- ) {
284
- context.report({
285
- node,
286
- messageId: importNotStrategizedMessageId,
287
- });
288
- return skipTrue;
289
- }
290
-
291
- // FOR NOW, we consider the importingFileCommentedDirective (which is strategized) and the importedFileCommentedDirective (which should be strategized on its own imported file) to be same, given the limitation highlighted above.
292
- importedFileCommentedDirective = importingFileCommentedDirective;
293
- }
274
+ // NEW!!
275
+ // No changes anymore. Agnostic Strategies Modules from now on are going to be considered regularly checked module that simply CANNOT be imported anywhere.
276
+
277
+ // if (importedFileCommentedDirective === USE_AGNOSTIC_STRATEGIES) {
278
+ // const importingFileCommentedDirective = getStrategizedDirective(
279
+ // context,
280
+ // node
281
+ // );
282
+
283
+ // if (
284
+ // importingFileCommentedDirective === null &&
285
+ // fileIsExtraJavaScript(context.filename)
286
+ // ) {
287
+ // context.report({
288
+ // node,
289
+ // messageId: importNotStrategizedMessageId,
290
+ // });
291
+ // return skipTrue;
292
+ // }
293
+
294
+ // // FOR NOW, we consider the importingFileCommentedDirective (which is strategized) and the importedFileCommentedDirective (which should be strategized on its own imported file) to be same, given the limitation highlighted above.
295
+ // importedFileCommentedDirective = importingFileCommentedDirective;
296
+ // }
294
297
 
295
298
  // you never know
296
299
  if (!importedFileSourceCode) {
@@ -380,26 +383,26 @@ const importedFileFlowRequire = (context, node) => {
380
383
  (Consequently, details below are currently at the stage of wishful thinking.)
381
384
  Strategy exports are planned to be linting in the future within their own Agnostic Strategies Modules to ensure they respect import rules within their own scopes. It may also become possible to check whether the export and import Strategies are the same in the future when identifiers are defined and the same, especially for components modules where a convention could be for all non-type exports to be named and PascalCase. */
382
385
 
383
- if (importedFileCommentedDirective === USE_AGNOSTIC_STRATEGIES) {
384
- const importingFileCommentedDirective = getStrategizedDirective(
385
- context,
386
- node
387
- );
388
-
389
- if (
390
- importingFileCommentedDirective === null &&
391
- fileIsExtraJavaScript(context.filename)
392
- ) {
393
- context.report({
394
- node,
395
- messageId: importNotStrategizedMessageId,
396
- });
397
- return skipTrue;
398
- }
399
-
400
- // FOR NOW, we consider the importingFileCommentedDirective (which is strategized) and the importedFileCommentedDirective (which should be strategized on its own imported file) to be same, given the limitation highlighted above.
401
- importedFileCommentedDirective = importingFileCommentedDirective;
402
- }
386
+ // if (importedFileCommentedDirective === USE_AGNOSTIC_STRATEGIES) {
387
+ // const importingFileCommentedDirective = getStrategizedDirective(
388
+ // context,
389
+ // node
390
+ // );
391
+
392
+ // if (
393
+ // importingFileCommentedDirective === null &&
394
+ // fileIsExtraJavaScript(context.filename)
395
+ // ) {
396
+ // context.report({
397
+ // node,
398
+ // messageId: importNotStrategizedMessageId,
399
+ // });
400
+ // return skipTrue;
401
+ // }
402
+
403
+ // // FOR NOW, we consider the importingFileCommentedDirective (which is strategized) and the importedFileCommentedDirective (which should be strategized on its own imported file) to be same, given the limitation highlighted above.
404
+ // importedFileCommentedDirective = importingFileCommentedDirective;
405
+ // }
403
406
 
404
407
  // you never know
405
408
  if (!importedFileSourceCode) {
@@ -443,8 +446,8 @@ export const importsFlow = (context, node, currentFileCommentedDirective) => {
443
446
  if (result.skip) return;
444
447
  const { importedFileCommentedDirective } = result;
445
448
 
446
- // returns early is the current file is an Agnostic Strategies Module
447
- if (currentFileCommentedDirective === USE_AGNOSTIC_STRATEGIES) return;
449
+ // returns early is the current file is an Agnostic Strategies Module // not anymore
450
+ // if (currentFileCommentedDirective === USE_AGNOSTIC_STRATEGIES) return;
448
451
 
449
452
  if (
450
453
  isImportBlocked(
@@ -519,8 +522,8 @@ export const importsFlowRequire = (
519
522
  if (result.skip) return;
520
523
  const { importedFileCommentedDirective } = result;
521
524
 
522
- // returns early is the current file is an Agnostic Strategies Module
523
- if (currentFileCommentedDirective === USE_AGNOSTIC_STRATEGIES) return;
525
+ // returns early is the current file is an Agnostic Strategies Module // not anymore
526
+ // if (currentFileCommentedDirective === USE_AGNOSTIC_STRATEGIES) return;
524
527
 
525
528
  if (
526
529
  isImportBlocked(
@@ -618,12 +621,42 @@ export const allExportsFlow = (
618
621
  currentFileCommentedDirective
619
622
  );
620
623
 
621
- // returns early if an address has been made
622
- if (!addressedDirective) return;
624
+ // // returns early if an address has been made
625
+ // if (!addressedDirective) return;
623
626
  // moves on to the re-export check otherwise
624
- else currentFileCommentedDirective = addressedDirective;
627
+ // else
628
+ currentFileCommentedDirective = addressedDirective; // to still keep compatibility with strategies
625
629
 
626
- if (currentFileCommentedDirective !== importedFileCommentedDirective) {
630
+ // Lints imports of Agnostic Strategies Modules beyond strategy resolution, such as to warn imports of Special Agnostic Modules. Does the same with Agnostic Conditions Modules, since they are the only other modules which cannot import themselves.
631
+ if (
632
+ currentFileCommentedDirective === USE_AGNOSTIC_STRATEGIES ||
633
+ currentFileCommentedDirective === USE_AGNOSTIC_CONDITIONS
634
+ ) {
635
+ // Basically, all modules need to do reexports that correspond to their own modules, but not Agnostic Strategies Modules and Agnostic Conditions Modules, the latter which are in fact NOT allowed to do re-exports.
636
+ if (
637
+ isImportBlocked(
638
+ currentFileCommentedDirective,
639
+ importedFileCommentedDirective
640
+ )
641
+ ) {
642
+ context.report({
643
+ node,
644
+ messageId: importBreaksCommentedImportRulesMessageId,
645
+ data: {
646
+ [commentedDirectiveMessage]:
647
+ makeMessageFromCurrentFileCommentedDirective(
648
+ currentFileCommentedDirective
649
+ ),
650
+ [specificViolationMessage]: findSpecificViolationMessage(
651
+ currentFileCommentedDirective,
652
+ importedFileCommentedDirective
653
+ ),
654
+ },
655
+ });
656
+ }
657
+ } else if (
658
+ currentFileCommentedDirective !== importedFileCommentedDirective
659
+ ) {
627
660
  context.report({
628
661
  node,
629
662
  messageId: reExportNotSameMessageId,
@@ -1,6 +1,6 @@
1
1
  import { getSourceCodeFromFilePath } from "get-sourcecode-from-file-path";
2
2
 
3
- import { exportNotStrategizedMessageId } from "../../../_commons/constants/bases.js";
3
+ // import { exportNotStrategizedMessageId } from "../../../_commons/constants/bases.js";
4
4
  import {
5
5
  USE_AGNOSTIC_STRATEGIES,
6
6
  commentedDirectivesArray,
@@ -323,25 +323,30 @@ export const addressDirectiveIfAgnosticStrategies = (
323
323
 
324
324
  const exportStrategizedDirective = getStrategizedDirective(context, node);
325
325
 
326
- if (
327
- exportStrategizedDirective === null &&
328
- fileIsExtraJavaScript(context.filename)
329
- ) {
330
- context.report({
331
- node,
332
- messageId: exportNotStrategizedMessageId,
333
- });
334
- }
335
-
336
- return exportStrategizedDirective; // null indicates failure
326
+ // NEW!!
327
+ // Now entirely neutralized. Agnostic Strategies Modules are now going to be vetted module just like the others from now on.
328
+ // BUT!!
329
+ // Still acknowledges ongoing strategies since they are indeed still acknowledged, though in a unreliable way, by the eXtra JSX's TypeScript server plugin.
330
+
331
+ // if (
332
+ // exportStrategizedDirective === null &&
333
+ // fileIsExtraJavaScript(context.filename)
334
+ // ) {
335
+ // context.report({
336
+ // node,
337
+ // messageId: exportNotStrategizedMessageId,
338
+ // });
339
+ // }
340
+
341
+ return exportStrategizedDirective ?? currentFileCommentedDirective; // null indicates failure, but now that Agnostic Strategies Modules are regularly linted like any other modules, they need to surface
337
342
  };
338
343
 
339
344
  /* isImportBlocked */
340
345
 
341
346
  /**
342
347
  * Returns a boolean deciding if an imported file's commented directive is incompatible with the current file's commented directive.
343
- * @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective The current file's commented directive.
344
- * @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective The imported file's commented directive.
348
+ * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
349
+ * @param {CommentedDirective} importedFileCommentedDirective The imported file's commented directive.
345
350
  * @returns `true` if the import is blocked, as established in `commentedDirectives_BlockedImports`.
346
351
  */
347
352
  export const isImportBlocked = (
@@ -373,8 +378,8 @@ export const makeMessageFromCurrentFileCommentedDirective = (
373
378
 
374
379
  /**
375
380
  * Finds the `message` for the specific violation of commented directives import rules based on `commentedDirectives_BlockedImports`.
376
- * @param {CommentedDirectiveWithoutUseAgnosticStrategies} currentFileCommentedDirective The current file's commented directive.
377
- * @param {CommentedDirectiveWithoutUseAgnosticStrategies} importedFileCommentedDirective The imported file's commented directive.
381
+ * @param {CommentedDirective} currentFileCommentedDirective The current file's commented directive.
382
+ * @param {CommentedDirective} importedFileCommentedDirective The imported file's commented directive.
378
383
  * @returns The corresponding `message`.
379
384
  */
380
385
  export const findSpecificViolationMessage = (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-use-agnostic",
3
- "version": "1.7.9",
3
+ "version": "1.8.1",
4
4
  "description": "Highlights problematic server-client imports in projects made with the Fullstack React Architecture.",
5
5
  "keywords": [
6
6
  "eslint",