eslint-plugin-react-rsc 5.20.0 → 5.20.2

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.
Files changed (2) hide show
  1. package/dist/index.js +55 -52
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ const rules$4 = { "react-rsc/function-definition": "off" };
34
34
  //#endregion
35
35
  //#region package.json
36
36
  var name$4 = "eslint-plugin-react-rsc";
37
- var version = "5.20.0";
37
+ var version = "5.20.2";
38
38
 
39
39
  //#endregion
40
40
  //#region src/utils/create-rule.ts
@@ -400,28 +400,7 @@ var z = {
400
400
  };
401
401
 
402
402
  //#endregion
403
- //#region src/rules/function-definition/function-definition.ts
404
- const RULE_NAME = "function-definition";
405
- var function_definition_default = createRule({
406
- meta: {
407
- type: "problem",
408
- docs: { description: "Validates and transforms React Client/Server Function definitions." },
409
- fixable: "code",
410
- messages: {
411
- file: "Functions exported from files with `use server` directive are React Server Functions and therefore must be async.",
412
- fileDirectivePosition: "The '{{name}}' directive must be at the very beginning of the file, before any imports or other code.",
413
- fileDirectiveQuote: "The '{{name}}' directive must be written with single or double quotes, not backticks.",
414
- local: "Functions with `use server` directive are React Server Functions and therefore must be async.",
415
- localDirectivePosition: "The '{{name}}' directive must be at the very beginning of the function body.",
416
- localDirectiveQuote: "The '{{name}}' directive must be written with single or double quotes, not backticks.",
417
- localDirectiveUnexpected: "The '{{name}}' directive can only be used at the top of a file, not inside a function body."
418
- },
419
- schema: []
420
- },
421
- name: RULE_NAME,
422
- create,
423
- defaultOptions: []
424
- });
403
+ //#region src/rules/function-definition/lib.ts
425
404
  function isDirectiveName(value) {
426
405
  return value === "use client" || value === "use server";
427
406
  }
@@ -450,44 +429,40 @@ function matchDirective(stmt) {
450
429
  }
451
430
  return null;
452
431
  }
432
+
433
+ //#endregion
434
+ //#region src/rules/function-definition/function-definition.ts
435
+ const RULE_NAME = "function-definition";
436
+ var function_definition_default = createRule({
437
+ meta: {
438
+ type: "problem",
439
+ docs: { description: "Validates and transforms React Client/Server Function definitions." },
440
+ fixable: "code",
441
+ messages: {
442
+ file: "Functions exported from files with `use server` directive are React Server Functions and therefore must be async.",
443
+ fileDirectivePosition: "The '{{name}}' directive must be at the very beginning of the file, before any imports or other code.",
444
+ fileDirectiveQuote: "The '{{name}}' directive must be written with single or double quotes, not backticks.",
445
+ local: "Functions with `use server` directive are React Server Functions and therefore must be async.",
446
+ localDirectivePosition: "The '{{name}}' directive must be at the very beginning of the function body.",
447
+ localDirectiveQuote: "The '{{name}}' directive must be written with single or double quotes, not backticks.",
448
+ localDirectiveUnexpected: "The '{{name}}' directive can only be used at the top of a file, not inside a function body."
449
+ },
450
+ schema: []
451
+ },
452
+ name: RULE_NAME,
453
+ create,
454
+ defaultOptions: []
455
+ });
453
456
  function create(context) {
454
457
  const text = context.sourceCode.text;
455
458
  if (!text.includes("use server") && !text.includes("use client")) return {};
456
459
  const hasFileLevelUseServerDirective = context.sourceCode.ast.body.some((stmt) => Check.isDirective(stmt, "use server"));
457
- function buildFixForAsync(node) {
458
- if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) return (fixer) => fixer.insertTextBefore(node, "async ");
459
- if (node.type === AST_NODE_TYPES.FunctionExpression) {
460
- const { parent } = node;
461
- if (parent.type === AST_NODE_TYPES.Property && parent.value === node) {
462
- if (parent.kind !== "init") return null;
463
- if (parent.method) return (fixer) => fixer.insertTextBefore(parent, "async ");
464
- }
465
- if (parent.type === AST_NODE_TYPES.MethodDefinition && parent.value === node) {
466
- if (parent.kind !== "method") return null;
467
- let target = parent.key;
468
- if (parent.computed) {
469
- const openBracket = context.sourceCode.getTokenBefore(parent.key);
470
- if (openBracket?.value !== "[") return null;
471
- target = openBracket;
472
- }
473
- if (node.generator) {
474
- const star = context.sourceCode.getTokenBefore(target);
475
- if (star?.value !== "*") return null;
476
- target = star;
477
- }
478
- return (fixer) => fixer.insertTextBefore(target, "async ");
479
- }
480
- }
481
- const functionToken = context.sourceCode.getFirstToken(node);
482
- if (functionToken == null) return null;
483
- return (fixer) => fixer.insertTextBefore(functionToken, "async ");
484
- }
485
460
  function reportNonAsyncFunction(node, messageId) {
486
461
  if (node == null) return;
487
462
  const fn = Extract.unwrap(node);
488
463
  if (!Check.isFunction(fn) || fn.async) return;
489
464
  context.report({
490
- fix: buildFixForAsync(fn),
465
+ fix: buildFixForAsync(context.sourceCode, fn),
491
466
  messageId,
492
467
  node: fn
493
468
  });
@@ -532,6 +507,34 @@ function create(context) {
532
507
  }
533
508
  if (core.isFunctionHasDirective(node, "use server")) reportNonAsyncFunction(node, "local");
534
509
  }
510
+ function buildFixForAsync(sourceCode, node) {
511
+ if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) return (fixer) => fixer.insertTextBefore(node, "async ");
512
+ if (node.type === AST_NODE_TYPES.FunctionExpression) {
513
+ const { parent } = node;
514
+ if (parent.type === AST_NODE_TYPES.Property && parent.value === node) {
515
+ if (parent.kind !== "init") return null;
516
+ if (parent.method) return (fixer) => fixer.insertTextBefore(parent, "async ");
517
+ }
518
+ if (parent.type === AST_NODE_TYPES.MethodDefinition && parent.value === node) {
519
+ if (parent.kind !== "method") return null;
520
+ let target = parent.key;
521
+ if (parent.computed) {
522
+ const openBracket = sourceCode.getTokenBefore(parent.key);
523
+ if (openBracket?.value !== "[") return null;
524
+ target = openBracket;
525
+ }
526
+ if (node.generator) {
527
+ const star = sourceCode.getTokenBefore(target);
528
+ if (star?.value !== "*") return null;
529
+ target = star;
530
+ }
531
+ return (fixer) => fixer.insertTextBefore(target, "async ");
532
+ }
533
+ }
534
+ const functionToken = sourceCode.getFirstToken(node);
535
+ if (functionToken == null) return null;
536
+ return (fixer) => fixer.insertTextBefore(functionToken, "async ");
537
+ }
535
538
  return {
536
539
  ArrowFunctionExpression: checkFunction,
537
540
  ExportDefaultDeclaration(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-rsc",
3
- "version": "5.20.0",
3
+ "version": "5.20.2",
4
4
  "description": "ESLint React's ESLint plugin for RSC related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -36,11 +36,11 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@eslint-react/ast": "5.20.0",
40
- "@eslint-react/core": "5.20.0",
41
- "@eslint-react/eslint": "5.20.0",
42
- "@eslint-react/shared": "5.20.0",
43
- "@eslint-react/var": "5.20.0",
39
+ "@eslint-react/ast": "5.20.2",
40
+ "@eslint-react/core": "5.20.2",
41
+ "@eslint-react/eslint": "5.20.2",
42
+ "@eslint-react/shared": "5.20.2",
43
+ "@eslint-react/var": "5.20.2",
44
44
  "@typescript-eslint/types": "^8.70.0",
45
45
  "@typescript-eslint/utils": "^8.70.0"
46
46
  },
@@ -50,7 +50,7 @@
50
50
  "@types/react": "^19.3.0",
51
51
  "@types/react-dom": "^19.3.0",
52
52
  "dedent": "^1.7.2",
53
- "eslint": "^10.10.0",
53
+ "eslint": "^10.11.0",
54
54
  "tsdown": "^0.23.0",
55
55
  "typescript": "6.0.3"
56
56
  },