eslint-plugin-use-agnostic 1.6.9 → 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.
|
@@ -46,6 +46,8 @@ export const importBreaksCommentedImportRulesMessageId =
|
|
|
46
46
|
export const noCommentedDirectiveMessageId = "no-commented-directive-detected";
|
|
47
47
|
export const commentedDirectiveVerificationFailedMessageId =
|
|
48
48
|
"commented-directive-verification-failed";
|
|
49
|
+
export const commentedDirectiveReactDirectiveFailedMessageId =
|
|
50
|
+
"commented-directive-correct-react-directive-failed";
|
|
49
51
|
export const importNotStrategizedMessageId =
|
|
50
52
|
"import-from-use-agnostic-strategies-not-strategized";
|
|
51
53
|
export const exportNotStrategizedMessageId =
|
|
@@ -11,6 +11,11 @@ import {
|
|
|
11
11
|
USE_AGNOSTIC_CONDITIONS as COMMONS_USE_AGNOSTIC_CONDITIONS,
|
|
12
12
|
USE_AGNOSTIC_STRATEGIES as COMMONS_USE_AGNOSTIC_STRATEGIES,
|
|
13
13
|
} from "../../../_commons/constants/bases.js";
|
|
14
|
+
import {
|
|
15
|
+
USE_SERVER,
|
|
16
|
+
USE_CLIENT,
|
|
17
|
+
USE_AGNOSTIC,
|
|
18
|
+
} from "../../../agnostic20/_commons/constants/bases.js";
|
|
14
19
|
|
|
15
20
|
import { makeIntroForSpecificViolationMessage } from "../../../_commons/utilities/helpers.js";
|
|
16
21
|
|
|
@@ -129,6 +134,8 @@ export const importedFileCommentedDirective = "importedFileCommentedDirective";
|
|
|
129
134
|
export const commentedDirectiveMessage = "commentedDirectiveMessage";
|
|
130
135
|
export const specificViolationMessage = "specificViolationMessage";
|
|
131
136
|
export const specificFailure = "specificFailure";
|
|
137
|
+
export const verifiedCommentedDirective = "verifiedCommentedDirective";
|
|
138
|
+
export const expectedReactDirectiveAsText = "expectedReactDirectiveAsText";
|
|
132
139
|
export const currentFileEnvironment = "currentFileEnvironment";
|
|
133
140
|
export const importedFileEnvironment = "importedFileEnvironment";
|
|
134
141
|
|
|
@@ -388,3 +395,24 @@ export const environments_allowedChainImportEnvironments = Object.freeze({
|
|
|
388
395
|
[CLIENT]: client_allowedChainImportEnvironments,
|
|
389
396
|
[AGNOSTIC]: agnostic_allowedChainImportEnvironments,
|
|
390
397
|
});
|
|
398
|
+
|
|
399
|
+
export const commentedDirectives_reactDirectives = Object.freeze({
|
|
400
|
+
[USE_SERVER_LOGICS]: null,
|
|
401
|
+
[USE_CLIENT_LOGICS]: "use client",
|
|
402
|
+
[USE_AGNOSTIC_LOGICS]: "use agnostic",
|
|
403
|
+
[USE_SERVER_COMPONENTS]: null,
|
|
404
|
+
[USE_CLIENT_COMPONENTS]: "use client",
|
|
405
|
+
[USE_AGNOSTIC_COMPONENTS]: "use agnostic",
|
|
406
|
+
[USE_SERVER_FUNCTIONS]: "use server",
|
|
407
|
+
[USE_CLIENT_CONTEXTS]: "use client",
|
|
408
|
+
[USE_AGNOSTIC_CONDITIONS]: null,
|
|
409
|
+
[USE_AGNOSTIC_STRATEGIES]: null,
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
/** @type {Map<typeof USE_SERVER | typeof USE_CLIENT | typeof USE_AGNOSTIC | null, `the React "${typeof USE_SERVER}"` | `the React "${typeof USE_CLIENT}"` | `the React "${typeof USE_AGNOSTIC}"` | "no React" `>} */
|
|
413
|
+
export const reactDirectives_asTexts = new Map([
|
|
414
|
+
[USE_SERVER, `the React "${USE_SERVER}"`],
|
|
415
|
+
[USE_CLIENT, `the React "${USE_CLIENT}"`],
|
|
416
|
+
[USE_AGNOSTIC, `the React "${USE_AGNOSTIC}"`],
|
|
417
|
+
[null, "no React"],
|
|
418
|
+
]);
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
importBreaksCommentedImportRulesMessageId,
|
|
4
4
|
noCommentedDirectiveMessageId,
|
|
5
5
|
commentedDirectiveVerificationFailedMessageId,
|
|
6
|
+
commentedDirectiveReactDirectiveFailedMessageId,
|
|
6
7
|
importNotStrategizedMessageId,
|
|
7
8
|
exportNotStrategizedMessageId,
|
|
8
9
|
cantChainImportAcrossEnvironmentsMessageId,
|
|
@@ -13,6 +14,8 @@ import {
|
|
|
13
14
|
commentedDirectiveMessage,
|
|
14
15
|
specificViolationMessage,
|
|
15
16
|
specificFailure,
|
|
17
|
+
verifiedCommentedDirective,
|
|
18
|
+
expectedReactDirectiveAsText,
|
|
16
19
|
currentFileEnvironment,
|
|
17
20
|
importedFileEnvironment,
|
|
18
21
|
} from "../constants/bases.js";
|
|
@@ -45,6 +48,7 @@ In this case, {{ ${specificViolationMessage} }} `,
|
|
|
45
48
|
All targeted modules need to be marked with their respective directives (\`// "use server logics"\`, etc.) for the purpose of this linting rule, evaluated from the first JavaScript comment starting on the first column within the first three lines of a module. `,
|
|
46
49
|
[commentedDirectiveVerificationFailedMessageId]: `The commented directive could not pass verification due to an incompatible combination with its file extension.
|
|
47
50
|
In this context, {{ ${specificFailure} }} `,
|
|
51
|
+
[commentedDirectiveReactDirectiveFailedMessageId]: `Commented directive "{{ ${verifiedCommentedDirective} }}" requires {{ ${expectedReactDirectiveAsText} }} directive in order to communicate accordingly with the React architecture at hand. `,
|
|
48
52
|
[importNotStrategizedMessageId]: `Imports from Agnostic Strategies Modules must be strategized (\`/* @serverLogics */\`, etc.).
|
|
49
53
|
Please include a Strategy that corresponds to the kind of module this import would be mapped to. `,
|
|
50
54
|
[exportNotStrategizedMessageId]: `Exports from Agnostic Strategies Modules must be strategized (\`/* @serverLogics */\`, etc.).
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
importBreaksCommentedImportRulesMessageId,
|
|
10
10
|
noCommentedDirectiveMessageId,
|
|
11
11
|
commentedDirectiveVerificationFailedMessageId,
|
|
12
|
+
commentedDirectiveReactDirectiveFailedMessageId,
|
|
12
13
|
importNotStrategizedMessageId,
|
|
13
14
|
cantChainImportAcrossEnvironmentsMessageId,
|
|
14
15
|
skip,
|
|
@@ -23,10 +24,15 @@ import {
|
|
|
23
24
|
commentedDirectiveMessage,
|
|
24
25
|
specificViolationMessage,
|
|
25
26
|
specificFailure,
|
|
27
|
+
// verifiedCommentedDirective,
|
|
28
|
+
// expectedReactDirectiveAsText,
|
|
26
29
|
environments_allowedChainImportEnvironments,
|
|
30
|
+
commentedDirectives_reactDirectives,
|
|
31
|
+
reactDirectives_asTexts,
|
|
27
32
|
} from "../constants/bases.js";
|
|
28
33
|
|
|
29
34
|
import { highlightFirstLineOfCode } from "../../../_commons/utilities/helpers.js";
|
|
35
|
+
import { getDirectiveFromCurrentModule } from "../../../agnostic20/_commons/utilities/helpers.js";
|
|
30
36
|
import {
|
|
31
37
|
getCommentedDirectiveFromCurrentModule,
|
|
32
38
|
getVerifiedCommentedDirective,
|
|
@@ -104,6 +110,39 @@ export const currentFileFlow = (context) => {
|
|
|
104
110
|
return skipTrue;
|
|
105
111
|
}
|
|
106
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
|
+
|
|
107
146
|
return { skip: undefined, verifiedCommentedDirective };
|
|
108
147
|
};
|
|
109
148
|
|