eslint-plugin-react-rsc 2.9.1-beta.0 → 2.9.1-beta.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.
- package/dist/index.js +13 -10
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ const rules$4 = { "react-rsc/function-definition": "off" };
|
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region package.json
|
|
34
34
|
var name$4 = "eslint-plugin-react-rsc";
|
|
35
|
-
var version = "2.9.1-beta.
|
|
35
|
+
var version = "2.9.1-beta.1";
|
|
36
36
|
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/utils/create-rule.ts
|
|
@@ -49,7 +49,10 @@ var function_definition_default = createRule({
|
|
|
49
49
|
type: "problem",
|
|
50
50
|
docs: { description: "Validate and transform React Client/Server Function definitions." },
|
|
51
51
|
fixable: "code",
|
|
52
|
-
messages: {
|
|
52
|
+
messages: {
|
|
53
|
+
file: "Functions exported from files with `use server` directive are React Server Functions and therefore must be async.",
|
|
54
|
+
local: "Functions with `use server` directive are React Server Functions and therefore must be async."
|
|
55
|
+
},
|
|
53
56
|
schema: []
|
|
54
57
|
},
|
|
55
58
|
name: RULE_NAME,
|
|
@@ -58,7 +61,7 @@ var function_definition_default = createRule({
|
|
|
58
61
|
});
|
|
59
62
|
function create(context) {
|
|
60
63
|
if (!context.sourceCode.text.includes("use server")) return {};
|
|
61
|
-
const hasFileLevelUseServerDirective = ast.getFileDirectives(context.sourceCode.ast).some((d) => d.
|
|
64
|
+
const hasFileLevelUseServerDirective = ast.getFileDirectives(context.sourceCode.ast).some((d) => d.directive === "use server");
|
|
62
65
|
/**
|
|
63
66
|
* Check if `node` is an async function, and report if not
|
|
64
67
|
* @param node The function node to check
|
|
@@ -73,11 +76,11 @@ function create(context) {
|
|
|
73
76
|
if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) return (fixer) => fixer.insertTextBefore(node, "async ");
|
|
74
77
|
return null;
|
|
75
78
|
}
|
|
76
|
-
function reportNonAsyncFunction(node) {
|
|
79
|
+
function reportNonAsyncFunction(node, messageId) {
|
|
77
80
|
if (!ast.isFunction(node)) return false;
|
|
78
81
|
if (!node.async) {
|
|
79
82
|
context.report({
|
|
80
|
-
messageId
|
|
83
|
+
messageId,
|
|
81
84
|
node,
|
|
82
85
|
fix: getAsyncFix(node)
|
|
83
86
|
});
|
|
@@ -90,7 +93,7 @@ function create(context) {
|
|
|
90
93
|
* @param node The function node to check
|
|
91
94
|
*/
|
|
92
95
|
function checkLocalServerFunction(node) {
|
|
93
|
-
if (ast.getFunctionDirectives(node).some((d) => d.
|
|
96
|
+
if (ast.getFunctionDirectives(node).some((d) => d.directive === "use server")) reportNonAsyncFunction(node, "local");
|
|
94
97
|
}
|
|
95
98
|
/**
|
|
96
99
|
* Find function declarations from exports and check them
|
|
@@ -100,7 +103,7 @@ function create(context) {
|
|
|
100
103
|
function findAndCheckExportedFunctionDeclarations(id, node) {
|
|
101
104
|
const variableNode = getVariableDefinitionNode(findVariable(id.name, context.sourceCode.getScope(node)), 0);
|
|
102
105
|
if (variableNode == null) return;
|
|
103
|
-
reportNonAsyncFunction(variableNode);
|
|
106
|
+
reportNonAsyncFunction(variableNode, "file");
|
|
104
107
|
}
|
|
105
108
|
return {
|
|
106
109
|
ArrowFunctionExpression(node) {
|
|
@@ -109,15 +112,15 @@ function create(context) {
|
|
|
109
112
|
ExportDefaultDeclaration(node) {
|
|
110
113
|
if (!hasFileLevelUseServerDirective) return;
|
|
111
114
|
const decl = node.declaration;
|
|
112
|
-
if (reportNonAsyncFunction(decl)) return;
|
|
115
|
+
if (reportNonAsyncFunction(decl, "file")) return;
|
|
113
116
|
if (ast.isIdentifier(decl)) findAndCheckExportedFunctionDeclarations(decl, node);
|
|
114
117
|
},
|
|
115
118
|
ExportNamedDeclaration(node) {
|
|
116
119
|
if (!hasFileLevelUseServerDirective) return;
|
|
117
120
|
if (node.declaration != null) {
|
|
118
121
|
const decl = node.declaration;
|
|
119
|
-
if (reportNonAsyncFunction(decl)) return;
|
|
120
|
-
if (decl.type === AST_NODE_TYPES.VariableDeclaration) for (const declarator of decl.declarations) reportNonAsyncFunction(declarator.init);
|
|
122
|
+
if (reportNonAsyncFunction(decl, "file")) return;
|
|
123
|
+
if (decl.type === AST_NODE_TYPES.VariableDeclaration) for (const declarator of decl.declarations) reportNonAsyncFunction(declarator.init, "file");
|
|
121
124
|
return;
|
|
122
125
|
}
|
|
123
126
|
if (node.source == null && node.specifiers.length > 0) for (const spec of node.specifiers) findAndCheckExportedFunctionDeclarations(spec.local, node);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-rsc",
|
|
3
|
-
"version": "2.9.1-beta.
|
|
3
|
+
"version": "2.9.1-beta.1",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for RSC related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"@typescript-eslint/types": "^8.54.0",
|
|
41
41
|
"@typescript-eslint/utils": "^8.54.0",
|
|
42
42
|
"ts-pattern": "^5.9.0",
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/
|
|
43
|
+
"@eslint-react/shared": "2.9.1-beta.1",
|
|
44
|
+
"@eslint-react/ast": "2.9.1-beta.1",
|
|
45
|
+
"@eslint-react/var": "2.9.1-beta.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/react": "^19.2.10",
|