@next/eslint-plugin-next 13.4.8-canary.5 → 13.4.8-canary.7

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 CHANGED
@@ -6,6 +6,7 @@ module.exports = {
6
6
  "inline-script-id": require("./rules/inline-script-id"),
7
7
  "next-script-for-ga": require("./rules/next-script-for-ga"),
8
8
  "no-assign-module-variable": require("./rules/no-assign-module-variable"),
9
+ "no-async-client-component": require("./rules/no-async-client-component"),
9
10
  "no-before-interactive-script-outside-document": require("./rules/no-before-interactive-script-outside-document"),
10
11
  "no-css-tags": require("./rules/no-css-tags"),
11
12
  "no-document-import-in-page": require("./rules/no-document-import-in-page"),
@@ -32,6 +33,7 @@ module.exports = {
32
33
  "@next/next/google-font-display": "warn",
33
34
  "@next/next/google-font-preconnect": "warn",
34
35
  "@next/next/next-script-for-ga": "warn",
36
+ "@next/next/no-async-client-component": "warn",
35
37
  "@next/next/no-before-interactive-script-outside-document": "warn",
36
38
  "@next/next/no-css-tags": "warn",
37
39
  "@next/next/no-head-element": "warn",
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var _definerule = require("../utils/define-rule");
3
+ var url = "https://nextjs.org/docs/messages/no-async-client-component";
4
+ var description = "Prevent client components from being async functions.";
5
+ var message = "".concat(description, " See: ").concat(url);
6
+ function isCapitalized(str) {
7
+ return /[A-Z]/.test(str === null || str === void 0 ? void 0 : str[0]);
8
+ }
9
+ module.exports = (0, _definerule.defineRule)({
10
+ meta: {
11
+ docs: {
12
+ description: description,
13
+ recommended: true,
14
+ url: url
15
+ },
16
+ type: "problem",
17
+ schema: []
18
+ },
19
+ create: function create(context) {
20
+ return {
21
+ Program: function Program(node) {
22
+ var isClientComponent = false;
23
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
24
+ try {
25
+ var _loop = function() {
26
+ var block = _step.value;
27
+ if (block.type === "ExpressionStatement" && block.expression.type === "Literal" && block.expression.value === "use client") {
28
+ isClientComponent = true;
29
+ }
30
+ if (block.type === "ExportDefaultDeclaration" && isClientComponent) {
31
+ // export default async function MyComponent() {...}
32
+ if (block.declaration.type === "FunctionDeclaration" && block.declaration.async && isCapitalized(block.declaration.id.name)) {
33
+ context.report({
34
+ node: block,
35
+ message: message
36
+ });
37
+ }
38
+ // async function MyComponent() {...}; export default MyComponent;
39
+ if (block.declaration.type === "Identifier" && isCapitalized(block.declaration.name)) {
40
+ var functionName = block.declaration.name;
41
+ var functionDeclaration = node.body.find(function(localBlock) {
42
+ return localBlock.type === "FunctionDeclaration" && localBlock.id.name === functionName;
43
+ });
44
+ if (functionDeclaration.type === "FunctionDeclaration" && functionDeclaration.async) {
45
+ context.report({
46
+ node: functionDeclaration,
47
+ message: message
48
+ });
49
+ }
50
+ }
51
+ }
52
+ };
53
+ for(var _iterator = node.body[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
54
+ } catch (err) {
55
+ _didIteratorError = true;
56
+ _iteratorError = err;
57
+ } finally{
58
+ try {
59
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
60
+ _iterator.return();
61
+ }
62
+ } finally{
63
+ if (_didIteratorError) {
64
+ throw _iteratorError;
65
+ }
66
+ }
67
+ }
68
+ }
69
+ };
70
+ }
71
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/eslint-plugin-next",
3
- "version": "13.4.8-canary.5",
3
+ "version": "13.4.8-canary.7",
4
4
  "description": "ESLint plugin for NextJS.",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",