@akanjs/lint 0.0.46 → 0.0.48

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 (31) hide show
  1. package/index.js +8 -328
  2. package/jest.config.js +31 -0
  3. package/package.json +1 -1
  4. package/pkgs/@akanjs/lint/jest.config.d.ts +11 -0
  5. package/src/rules/noImportClientFunctions.js +54 -0
  6. package/src/rules/noImportExternalLibrary.js +60 -0
  7. package/src/rules/nonScalarPropsRestricted.js +60 -0
  8. package/src/rules/useClientByFile.js +71 -0
  9. package/src/util/fileHasClientFunction.js +43 -0
  10. package/src/util/fileHasContent.js +26 -0
  11. package/src/util/fileHasUseClient.js +26 -0
  12. package/src/util/fileIsPureImportFile.js +59 -0
  13. package/src/util/fileIsServerFile.js +56 -0
  14. package/src/util/getAppName.js +27 -0
  15. package/src/util/getFilename.js +26 -0
  16. package/src/util/index.js +37 -0
  17. package/src/util/isInternalImport.js +54 -0
  18. /package/{index.d.ts → pkgs/@akanjs/lint/index.d.ts} +0 -0
  19. /package/{rules → pkgs/@akanjs/lint/src/rules}/noImportClientFunctions.d.ts +0 -0
  20. /package/{rules → pkgs/@akanjs/lint/src/rules}/noImportExternalLibrary.d.ts +0 -0
  21. /package/{rules → pkgs/@akanjs/lint/src/rules}/nonScalarPropsRestricted.d.ts +0 -0
  22. /package/{rules → pkgs/@akanjs/lint/src/rules}/useClientByFile.d.ts +0 -0
  23. /package/{util → pkgs/@akanjs/lint/src/util}/fileHasClientFunction.d.ts +0 -0
  24. /package/{util → pkgs/@akanjs/lint/src/util}/fileHasContent.d.ts +0 -0
  25. /package/{util → pkgs/@akanjs/lint/src/util}/fileHasUseClient.d.ts +0 -0
  26. /package/{util → pkgs/@akanjs/lint/src/util}/fileIsPureImportFile.d.ts +0 -0
  27. /package/{util → pkgs/@akanjs/lint/src/util}/fileIsServerFile.d.ts +0 -0
  28. /package/{util → pkgs/@akanjs/lint/src/util}/getAppName.d.ts +0 -0
  29. /package/{util → pkgs/@akanjs/lint/src/util}/getFilename.d.ts +0 -0
  30. /package/{util → pkgs/@akanjs/lint/src/util}/index.d.ts +0 -0
  31. /package/{util → pkgs/@akanjs/lint/src/util}/isInternalImport.d.ts +0 -0
package/index.js CHANGED
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,339 +14,21 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // pkgs/@akanjs/lint/index.ts
30
18
  var lint_exports = {};
31
19
  __export(lint_exports, {
32
20
  default: () => lint_default
33
21
  });
34
22
  module.exports = __toCommonJS(lint_exports);
35
-
36
- // pkgs/@akanjs/lint/rules/noImportClientFunctions.ts
37
- var import_utils = require("@typescript-eslint/utils");
38
-
39
- // pkgs/@akanjs/lint/util/fileIsServerFile.ts
40
- var serverFileNameSet = /* @__PURE__ */ new Set();
41
- var clientFileNameSet = /* @__PURE__ */ new Set(["st.ts", "store.ts"]);
42
- var serverFileSuffixSet = /* @__PURE__ */ new Set(["page.tsx", "layout.tsx", "Unit.tsx", "View.tsx"]);
43
- var clientFileSuffixSet = /* @__PURE__ */ new Set(["Zone.tsx", "Util.tsx", "Template.tsx"]);
44
- var fileIsServerFile = (absFilePath, sourceCode) => {
45
- if (absFilePath.includes("eslint-rules"))
46
- return true;
47
- const filePaths = absFilePath.split("/");
48
- const filename = filePaths.at(-1) ?? "";
49
- const fileLastName = absFilePath.split(".").slice(-2).join(".");
50
- if (filename === "page.tsx") {
51
- if (filePaths.includes("admin"))
52
- return false;
53
- else
54
- return true;
55
- }
56
- if (filename === "layout.tsx") {
57
- if (filePaths.at(-2) === "app")
58
- return false;
59
- else
60
- return true;
61
- }
62
- if (serverFileNameSet.has(filename))
63
- return true;
64
- if (clientFileNameSet.has(filename))
65
- return false;
66
- if (serverFileSuffixSet.has(fileLastName))
67
- return true;
68
- if (clientFileSuffixSet.has(fileLastName))
69
- return false;
70
- if (new RegExp(/useEffect|useState|useContext|st\.do\.|st\.use\./g).test(sourceCode))
71
- return false;
72
- return null;
73
- };
74
-
75
- // pkgs/@akanjs/lint/util/fileHasUseClient.ts
76
- var fileHasUseClient = (context) => {
77
- const firstLineIdx = context.sourceCode.lines.findIndex((line) => line.trim() !== "");
78
- return { hasUseClient: context.sourceCode.lines[firstLineIdx].includes('"use client"'), firstLineIdx };
79
- };
80
-
81
- // pkgs/@akanjs/lint/util/fileHasContent.ts
82
- var fileHasContent = (context, node) => {
83
- const firstToken = context.sourceCode.getFirstToken(node);
84
- return !!firstToken;
85
- };
86
-
87
- // pkgs/@akanjs/lint/util/fileHasClientFunction.ts
88
- var reactClientFunctionSet = /* @__PURE__ */ new Set([
89
- "useState",
90
- "useEffect",
91
- "useContext",
92
- "useReducer",
93
- "useCallback",
94
- "useMemo",
95
- "useRef",
96
- "useImperativeHandle",
97
- "useLayoutEffect",
98
- "useDebugValue"
99
- ]);
100
- var frameworkClientFunctionSet = /* @__PURE__ */ new Set(["st"]);
101
- var fileHasClientFunction = (node) => {
102
- if (node.source.value === "react")
103
- return node.specifiers.some((specifier) => reactClientFunctionSet.has(specifier.local.name));
104
- else if (node.specifiers.some((specifier) => frameworkClientFunctionSet.has(specifier.local.name)))
105
- return true;
106
- else
107
- return false;
108
- };
109
-
110
- // pkgs/@akanjs/lint/util/getFilename.ts
111
- var getFilename = (absFilePath) => {
112
- const filePaths = absFilePath.split("/");
113
- return filePaths.at(-1) ?? "";
114
- };
115
-
116
- // pkgs/@akanjs/lint/util/fileIsPureImportFile.ts
117
- var fileSuffixSet = /* @__PURE__ */ new Set([
118
- "page.tsx",
119
- "layout.tsx",
120
- "index.ts",
121
- "cnst_.ts",
122
- "cnst.ts",
123
- "db.ts",
124
- "dict.ts",
125
- "fetch.ts",
126
- "option.ts",
127
- "sig.ts",
128
- "srv.ts",
129
- "st.ts",
130
- "usePage.ts",
131
- "_server.ts",
132
- "constant.ts",
133
- "dictionary.ts",
134
- "document.ts",
135
- "service.ts",
136
- "signal.ts",
137
- "spec.ts",
138
- "test.ts",
139
- "store.ts",
140
- "Template.tsx",
141
- "Unit.tsx",
142
- "Util.tsx",
143
- "View.tsx",
144
- "Zone.tsx",
145
- "index.tsx"
146
- ]);
147
- var fileIsPureImportFile = (filename) => {
148
- const suffixFilename = filename.split("/").at(-1)?.split(".").slice(-2).join(".") ?? "";
149
- if (fileSuffixSet.has(suffixFilename))
150
- return true;
151
- else
152
- return false;
153
- };
154
-
155
- // pkgs/@akanjs/lint/util/isInternalImport.ts
156
- var fs = __toESM(require("fs"));
157
- var projectRoot = process.cwd();
158
- var libNames = [...fs.readdirSync(`${projectRoot}/libs`), ...fs.readdirSync(`${projectRoot}/pkgs`)];
159
- var internalImportSet = /* @__PURE__ */ new Set([
160
- ...libNames.map((libName) => `@${libName}`),
161
- "react-icons",
162
- "react",
163
- "next",
164
- "@radix-ui",
165
- "@playwright",
166
- "@akanjs",
167
- ".",
168
- ".."
169
- ]);
170
- var isInternalImport = (importPaths, appName) => {
171
- if (internalImportSet.has(importPaths[0]))
172
- return true;
173
- else if (importPaths[0] === appName)
174
- return true;
175
- else
176
- return false;
177
- };
178
-
179
- // pkgs/@akanjs/lint/util/getAppName.ts
180
- var getAppName = (filePaths) => {
181
- const appsIdx = filePaths.findIndex((part) => part === "apps");
182
- const appName = appsIdx === -1 ? null : filePaths[appsIdx + 1];
183
- return appName;
184
- };
185
-
186
- // pkgs/@akanjs/lint/rules/noImportClientFunctions.ts
187
- var noImportClientFunctions = import_utils.ESLintUtils.RuleCreator(() => __filename)({
188
- name: "noImportClientFunctions",
189
- meta: {
190
- type: "problem",
191
- docs: {
192
- description: "Enforce that client functions are not imported."
193
- },
194
- messages: {
195
- noImportClientFunctions: "Error: Client functions should not be imported."
196
- },
197
- // fixable: "code",
198
- schema: []
199
- },
200
- defaultOptions: [],
201
- create(context) {
202
- const isServerFile = fileIsServerFile(context.filename, context.sourceCode.text);
203
- if (!isServerFile)
204
- return {};
205
- return {
206
- ImportDeclaration(node) {
207
- const hasClientFunction = fileHasClientFunction(node);
208
- if (hasClientFunction)
209
- context.report({
210
- node,
211
- messageId: "noImportClientFunctions"
212
- });
213
- }
214
- };
215
- }
216
- });
217
-
218
- // pkgs/@akanjs/lint/rules/noImportExternalLibrary.ts
219
- var import_utils2 = require("@typescript-eslint/utils");
220
- var noImportExternalLibrary = import_utils2.ESLintUtils.RuleCreator(() => __filename)({
221
- name: "noImportExternalLibrary",
222
- meta: {
223
- type: "problem",
224
- docs: {
225
- description: "Enforce that external libraries are not imported."
226
- },
227
- messages: {
228
- noImportExternalLibrary: "Error: External libraries should not be imported."
229
- },
230
- // fixable: "code",
231
- schema: []
232
- },
233
- defaultOptions: [],
234
- create(context) {
235
- const isPureImportFile = fileIsPureImportFile(context.filename);
236
- if (!isPureImportFile)
237
- return {};
238
- const filePaths = context.filename.split("/");
239
- const appName = getAppName(filePaths);
240
- const appPath = appName ? `@${appName}` : null;
241
- return {
242
- ImportDeclaration(node) {
243
- const importPaths = node.source.value.split("/");
244
- if (!isInternalImport(importPaths, appPath))
245
- context.report({
246
- node,
247
- messageId: "noImportExternalLibrary"
248
- // fix(fixer) {
249
- // return fixer.remove(node);
250
- // },
251
- });
252
- }
253
- };
254
- }
255
- });
256
-
257
- // pkgs/@akanjs/lint/rules/nonScalarPropsRestricted.ts
258
- var import_utils3 = require("@typescript-eslint/utils");
259
- var allowedPropKeySet = /* @__PURE__ */ new Set(["loader", "render", "of"]);
260
- var nonScalarPropsRestricted = import_utils3.ESLintUtils.RuleCreator(() => __filename)({
261
- name: "nonScalarPropsRestricted",
262
- meta: {
263
- type: "problem",
264
- docs: {
265
- description: "Enforce that non-scalar props are not used."
266
- },
267
- messages: {
268
- nonScalarPropsRestricted: "Error: Non-scalar props should not be used."
269
- },
270
- // fixable: "code",
271
- schema: []
272
- },
273
- defaultOptions: [],
274
- create(context) {
275
- const filename = getFilename(context.filename);
276
- const isServerFile = fileIsServerFile(context.filename, context.sourceCode.text);
277
- if (!isServerFile || !["page.tsx", "layout.tsx"].includes(filename))
278
- return {};
279
- return {
280
- JSXAttribute(node) {
281
- if (node.value?.expression) {
282
- const { expression, parent } = node.value;
283
- if (expression.type === "ArrowFunctionExpression" || expression.type === "FunctionExpression") {
284
- if (!allowedPropKeySet.has(parent.name.name))
285
- context.report({
286
- node,
287
- messageId: "nonScalarPropsRestricted"
288
- });
289
- }
290
- }
291
- }
292
- };
293
- }
294
- });
295
-
296
- // pkgs/@akanjs/lint/rules/useClientByFile.ts
297
- var import_utils4 = require("@typescript-eslint/utils");
298
- var useClientByFile = import_utils4.ESLintUtils.RuleCreator(() => __filename)({
299
- name: "useClientByFile",
300
- meta: {
301
- type: "problem",
302
- docs: {
303
- description: "Enforce that `use client` is not used in `server` files."
304
- },
305
- messages: {
306
- noUseClient: 'Error: "use client" should not be used at the top of a `server` file.',
307
- forceUseClient: 'Error: "use client" should be used at the top of a `client` file.'
308
- },
309
- // fixable: "code",
310
- schema: []
311
- },
312
- defaultOptions: [],
313
- create(context) {
314
- const isServerFile = fileIsServerFile(context.filename, context.sourceCode.text);
315
- if (isServerFile === null)
316
- return {};
317
- if (isServerFile)
318
- return {
319
- Program(node) {
320
- if (!fileHasContent(context, node))
321
- return;
322
- const { hasUseClient, firstLineIdx } = fileHasUseClient(context);
323
- if (hasUseClient)
324
- context.report({
325
- node: node.body[firstLineIdx],
326
- messageId: "noUseClient"
327
- });
328
- }
329
- };
330
- else
331
- return {
332
- Program(node) {
333
- if (!fileHasContent(context, node))
334
- return;
335
- const { hasUseClient, firstLineIdx } = fileHasUseClient(context);
336
- if (!hasUseClient)
337
- context.report({
338
- node: node.body[firstLineIdx],
339
- messageId: "forceUseClient"
340
- });
341
- }
342
- };
343
- }
344
- });
345
-
346
- // pkgs/@akanjs/lint/index.ts
23
+ var import_noImportClientFunctions = require("./src/rules/noImportClientFunctions");
24
+ var import_noImportExternalLibrary = require("./src/rules/noImportExternalLibrary");
25
+ var import_nonScalarPropsRestricted = require("./src/rules/nonScalarPropsRestricted");
26
+ var import_useClientByFile = require("./src/rules/useClientByFile");
347
27
  var lint_default = {
348
28
  rules: {
349
- noImportExternalLibrary,
350
- noImportClientFunctions,
351
- nonScalarPropsRestricted,
352
- useClientByFile
29
+ noImportExternalLibrary: import_noImportExternalLibrary.noImportExternalLibrary,
30
+ noImportClientFunctions: import_noImportClientFunctions.noImportClientFunctions,
31
+ nonScalarPropsRestricted: import_nonScalarPropsRestricted.nonScalarPropsRestricted,
32
+ useClientByFile: import_useClientByFile.useClientByFile
353
33
  }
354
34
  };
package/jest.config.js ADDED
@@ -0,0 +1,31 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var jest_config_exports = {};
19
+ __export(jest_config_exports, {
20
+ default: () => jest_config_default
21
+ });
22
+ module.exports = __toCommonJS(jest_config_exports);
23
+ var jest_config_default = {
24
+ displayName: "eslint-rules",
25
+ // preset: "../../pkgs/@akanjs/config/src/jest.preset.js",
26
+ transform: {
27
+ "^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }]
28
+ },
29
+ moduleFileExtensions: ["ts", "js", "html"],
30
+ coverageDirectory: "../../../coverage/pkgs/@akanjs/lint"
31
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/lint",
3
- "version": "0.0.46",
3
+ "version": "0.0.48",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -0,0 +1,11 @@
1
+ declare const _default: {
2
+ displayName: string;
3
+ transform: {
4
+ "^.+\\.[tj]s$": (string | {
5
+ tsconfig: string;
6
+ })[];
7
+ };
8
+ moduleFileExtensions: string[];
9
+ coverageDirectory: string;
10
+ };
11
+ export default _default;
@@ -0,0 +1,54 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var noImportClientFunctions_exports = {};
19
+ __export(noImportClientFunctions_exports, {
20
+ noImportClientFunctions: () => noImportClientFunctions
21
+ });
22
+ module.exports = __toCommonJS(noImportClientFunctions_exports);
23
+ var import_utils = require("@typescript-eslint/utils");
24
+ var import_util = require("../util");
25
+ const noImportClientFunctions = import_utils.ESLintUtils.RuleCreator(() => __filename)({
26
+ name: "noImportClientFunctions",
27
+ meta: {
28
+ type: "problem",
29
+ docs: {
30
+ description: "Enforce that client functions are not imported."
31
+ },
32
+ messages: {
33
+ noImportClientFunctions: "Error: Client functions should not be imported."
34
+ },
35
+ // fixable: "code",
36
+ schema: []
37
+ },
38
+ defaultOptions: [],
39
+ create(context) {
40
+ const isServerFile = (0, import_util.fileIsServerFile)(context.filename, context.sourceCode.text);
41
+ if (!isServerFile)
42
+ return {};
43
+ return {
44
+ ImportDeclaration(node) {
45
+ const hasClientFunction = (0, import_util.fileHasClientFunction)(node);
46
+ if (hasClientFunction)
47
+ context.report({
48
+ node,
49
+ messageId: "noImportClientFunctions"
50
+ });
51
+ }
52
+ };
53
+ }
54
+ });
@@ -0,0 +1,60 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var noImportExternalLibrary_exports = {};
19
+ __export(noImportExternalLibrary_exports, {
20
+ noImportExternalLibrary: () => noImportExternalLibrary
21
+ });
22
+ module.exports = __toCommonJS(noImportExternalLibrary_exports);
23
+ var import_utils = require("@typescript-eslint/utils");
24
+ var import_util = require("../util");
25
+ const noImportExternalLibrary = import_utils.ESLintUtils.RuleCreator(() => __filename)({
26
+ name: "noImportExternalLibrary",
27
+ meta: {
28
+ type: "problem",
29
+ docs: {
30
+ description: "Enforce that external libraries are not imported."
31
+ },
32
+ messages: {
33
+ noImportExternalLibrary: "Error: External libraries should not be imported."
34
+ },
35
+ // fixable: "code",
36
+ schema: []
37
+ },
38
+ defaultOptions: [],
39
+ create(context) {
40
+ const isPureImportFile = (0, import_util.fileIsPureImportFile)(context.filename);
41
+ if (!isPureImportFile)
42
+ return {};
43
+ const filePaths = context.filename.split("/");
44
+ const appName = (0, import_util.getAppName)(filePaths);
45
+ const appPath = appName ? `@${appName}` : null;
46
+ return {
47
+ ImportDeclaration(node) {
48
+ const importPaths = node.source.value.split("/");
49
+ if (!(0, import_util.isInternalImport)(importPaths, appPath))
50
+ context.report({
51
+ node,
52
+ messageId: "noImportExternalLibrary"
53
+ // fix(fixer) {
54
+ // return fixer.remove(node);
55
+ // },
56
+ });
57
+ }
58
+ };
59
+ }
60
+ });
@@ -0,0 +1,60 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var nonScalarPropsRestricted_exports = {};
19
+ __export(nonScalarPropsRestricted_exports, {
20
+ nonScalarPropsRestricted: () => nonScalarPropsRestricted
21
+ });
22
+ module.exports = __toCommonJS(nonScalarPropsRestricted_exports);
23
+ var import_utils = require("@typescript-eslint/utils");
24
+ var import_util = require("../util");
25
+ const allowedPropKeySet = /* @__PURE__ */ new Set(["loader", "render", "of"]);
26
+ const nonScalarPropsRestricted = import_utils.ESLintUtils.RuleCreator(() => __filename)({
27
+ name: "nonScalarPropsRestricted",
28
+ meta: {
29
+ type: "problem",
30
+ docs: {
31
+ description: "Enforce that non-scalar props are not used."
32
+ },
33
+ messages: {
34
+ nonScalarPropsRestricted: "Error: Non-scalar props should not be used."
35
+ },
36
+ // fixable: "code",
37
+ schema: []
38
+ },
39
+ defaultOptions: [],
40
+ create(context) {
41
+ const filename = (0, import_util.getFilename)(context.filename);
42
+ const isServerFile = (0, import_util.fileIsServerFile)(context.filename, context.sourceCode.text);
43
+ if (!isServerFile || !["page.tsx", "layout.tsx"].includes(filename))
44
+ return {};
45
+ return {
46
+ JSXAttribute(node) {
47
+ if (node.value?.expression) {
48
+ const { expression, parent } = node.value;
49
+ if (expression.type === "ArrowFunctionExpression" || expression.type === "FunctionExpression") {
50
+ if (!allowedPropKeySet.has(parent.name.name))
51
+ context.report({
52
+ node,
53
+ messageId: "nonScalarPropsRestricted"
54
+ });
55
+ }
56
+ }
57
+ }
58
+ };
59
+ }
60
+ });
@@ -0,0 +1,71 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var useClientByFile_exports = {};
19
+ __export(useClientByFile_exports, {
20
+ useClientByFile: () => useClientByFile
21
+ });
22
+ module.exports = __toCommonJS(useClientByFile_exports);
23
+ var import_utils = require("@typescript-eslint/utils");
24
+ var import_util = require("../util");
25
+ const useClientByFile = import_utils.ESLintUtils.RuleCreator(() => __filename)({
26
+ name: "useClientByFile",
27
+ meta: {
28
+ type: "problem",
29
+ docs: {
30
+ description: "Enforce that `use client` is not used in `server` files."
31
+ },
32
+ messages: {
33
+ noUseClient: 'Error: "use client" should not be used at the top of a `server` file.',
34
+ forceUseClient: 'Error: "use client" should be used at the top of a `client` file.'
35
+ },
36
+ // fixable: "code",
37
+ schema: []
38
+ },
39
+ defaultOptions: [],
40
+ create(context) {
41
+ const isServerFile = (0, import_util.fileIsServerFile)(context.filename, context.sourceCode.text);
42
+ if (isServerFile === null)
43
+ return {};
44
+ if (isServerFile)
45
+ return {
46
+ Program(node) {
47
+ if (!(0, import_util.fileHasContent)(context, node))
48
+ return;
49
+ const { hasUseClient, firstLineIdx } = (0, import_util.fileHasUseClient)(context);
50
+ if (hasUseClient)
51
+ context.report({
52
+ node: node.body[firstLineIdx],
53
+ messageId: "noUseClient"
54
+ });
55
+ }
56
+ };
57
+ else
58
+ return {
59
+ Program(node) {
60
+ if (!(0, import_util.fileHasContent)(context, node))
61
+ return;
62
+ const { hasUseClient, firstLineIdx } = (0, import_util.fileHasUseClient)(context);
63
+ if (!hasUseClient)
64
+ context.report({
65
+ node: node.body[firstLineIdx],
66
+ messageId: "forceUseClient"
67
+ });
68
+ }
69
+ };
70
+ }
71
+ });
@@ -0,0 +1,43 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var fileHasClientFunction_exports = {};
19
+ __export(fileHasClientFunction_exports, {
20
+ fileHasClientFunction: () => fileHasClientFunction
21
+ });
22
+ module.exports = __toCommonJS(fileHasClientFunction_exports);
23
+ const reactClientFunctionSet = /* @__PURE__ */ new Set([
24
+ "useState",
25
+ "useEffect",
26
+ "useContext",
27
+ "useReducer",
28
+ "useCallback",
29
+ "useMemo",
30
+ "useRef",
31
+ "useImperativeHandle",
32
+ "useLayoutEffect",
33
+ "useDebugValue"
34
+ ]);
35
+ const frameworkClientFunctionSet = /* @__PURE__ */ new Set(["st"]);
36
+ const fileHasClientFunction = (node) => {
37
+ if (node.source.value === "react")
38
+ return node.specifiers.some((specifier) => reactClientFunctionSet.has(specifier.local.name));
39
+ else if (node.specifiers.some((specifier) => frameworkClientFunctionSet.has(specifier.local.name)))
40
+ return true;
41
+ else
42
+ return false;
43
+ };
@@ -0,0 +1,26 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var fileHasContent_exports = {};
19
+ __export(fileHasContent_exports, {
20
+ fileHasContent: () => fileHasContent
21
+ });
22
+ module.exports = __toCommonJS(fileHasContent_exports);
23
+ const fileHasContent = (context, node) => {
24
+ const firstToken = context.sourceCode.getFirstToken(node);
25
+ return !!firstToken;
26
+ };
@@ -0,0 +1,26 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var fileHasUseClient_exports = {};
19
+ __export(fileHasUseClient_exports, {
20
+ fileHasUseClient: () => fileHasUseClient
21
+ });
22
+ module.exports = __toCommonJS(fileHasUseClient_exports);
23
+ const fileHasUseClient = (context) => {
24
+ const firstLineIdx = context.sourceCode.lines.findIndex((line) => line.trim() !== "");
25
+ return { hasUseClient: context.sourceCode.lines[firstLineIdx].includes('"use client"'), firstLineIdx };
26
+ };
@@ -0,0 +1,59 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var fileIsPureImportFile_exports = {};
19
+ __export(fileIsPureImportFile_exports, {
20
+ fileIsPureImportFile: () => fileIsPureImportFile
21
+ });
22
+ module.exports = __toCommonJS(fileIsPureImportFile_exports);
23
+ const fileSuffixSet = /* @__PURE__ */ new Set([
24
+ "page.tsx",
25
+ "layout.tsx",
26
+ "index.ts",
27
+ "cnst_.ts",
28
+ "cnst.ts",
29
+ "db.ts",
30
+ "dict.ts",
31
+ "fetch.ts",
32
+ "option.ts",
33
+ "sig.ts",
34
+ "srv.ts",
35
+ "st.ts",
36
+ "usePage.ts",
37
+ "_server.ts",
38
+ "constant.ts",
39
+ "dictionary.ts",
40
+ "document.ts",
41
+ "service.ts",
42
+ "signal.ts",
43
+ "spec.ts",
44
+ "test.ts",
45
+ "store.ts",
46
+ "Template.tsx",
47
+ "Unit.tsx",
48
+ "Util.tsx",
49
+ "View.tsx",
50
+ "Zone.tsx",
51
+ "index.tsx"
52
+ ]);
53
+ const fileIsPureImportFile = (filename) => {
54
+ const suffixFilename = filename.split("/").at(-1)?.split(".").slice(-2).join(".") ?? "";
55
+ if (fileSuffixSet.has(suffixFilename))
56
+ return true;
57
+ else
58
+ return false;
59
+ };
@@ -0,0 +1,56 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var fileIsServerFile_exports = {};
19
+ __export(fileIsServerFile_exports, {
20
+ fileIsServerFile: () => fileIsServerFile
21
+ });
22
+ module.exports = __toCommonJS(fileIsServerFile_exports);
23
+ const serverFileNameSet = /* @__PURE__ */ new Set();
24
+ const clientFileNameSet = /* @__PURE__ */ new Set(["st.ts", "store.ts"]);
25
+ const serverFileSuffixSet = /* @__PURE__ */ new Set(["page.tsx", "layout.tsx", "Unit.tsx", "View.tsx"]);
26
+ const clientFileSuffixSet = /* @__PURE__ */ new Set(["Zone.tsx", "Util.tsx", "Template.tsx"]);
27
+ const fileIsServerFile = (absFilePath, sourceCode) => {
28
+ if (absFilePath.includes("eslint-rules"))
29
+ return true;
30
+ const filePaths = absFilePath.split("/");
31
+ const filename = filePaths.at(-1) ?? "";
32
+ const fileLastName = absFilePath.split(".").slice(-2).join(".");
33
+ if (filename === "page.tsx") {
34
+ if (filePaths.includes("admin"))
35
+ return false;
36
+ else
37
+ return true;
38
+ }
39
+ if (filename === "layout.tsx") {
40
+ if (filePaths.at(-2) === "app")
41
+ return false;
42
+ else
43
+ return true;
44
+ }
45
+ if (serverFileNameSet.has(filename))
46
+ return true;
47
+ if (clientFileNameSet.has(filename))
48
+ return false;
49
+ if (serverFileSuffixSet.has(fileLastName))
50
+ return true;
51
+ if (clientFileSuffixSet.has(fileLastName))
52
+ return false;
53
+ if (new RegExp(/useEffect|useState|useContext|st\.do\.|st\.use\./g).test(sourceCode))
54
+ return false;
55
+ return null;
56
+ };
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var getAppName_exports = {};
19
+ __export(getAppName_exports, {
20
+ getAppName: () => getAppName
21
+ });
22
+ module.exports = __toCommonJS(getAppName_exports);
23
+ const getAppName = (filePaths) => {
24
+ const appsIdx = filePaths.findIndex((part) => part === "apps");
25
+ const appName = appsIdx === -1 ? null : filePaths[appsIdx + 1];
26
+ return appName;
27
+ };
@@ -0,0 +1,26 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var getFilename_exports = {};
19
+ __export(getFilename_exports, {
20
+ getFilename: () => getFilename
21
+ });
22
+ module.exports = __toCommonJS(getFilename_exports);
23
+ const getFilename = (absFilePath) => {
24
+ const filePaths = absFilePath.split("/");
25
+ return filePaths.at(-1) ?? "";
26
+ };
@@ -0,0 +1,37 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var util_exports = {};
19
+ __export(util_exports, {
20
+ fileHasClientFunction: () => import_fileHasClientFunction.fileHasClientFunction,
21
+ fileHasContent: () => import_fileHasContent.fileHasContent,
22
+ fileHasUseClient: () => import_fileHasUseClient.fileHasUseClient,
23
+ fileIsPureImportFile: () => import_fileIsPureImportFile.fileIsPureImportFile,
24
+ fileIsServerFile: () => import_fileIsServerFile.fileIsServerFile,
25
+ getAppName: () => import_getAppName.getAppName,
26
+ getFilename: () => import_getFilename.getFilename,
27
+ isInternalImport: () => import_isInternalImport.isInternalImport
28
+ });
29
+ module.exports = __toCommonJS(util_exports);
30
+ var import_fileIsServerFile = require("./fileIsServerFile");
31
+ var import_fileHasUseClient = require("./fileHasUseClient");
32
+ var import_fileHasContent = require("./fileHasContent");
33
+ var import_fileHasClientFunction = require("./fileHasClientFunction");
34
+ var import_getFilename = require("./getFilename");
35
+ var import_fileIsPureImportFile = require("./fileIsPureImportFile");
36
+ var import_isInternalImport = require("./isInternalImport");
37
+ var import_getAppName = require("./getAppName");
@@ -0,0 +1,54 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var isInternalImport_exports = {};
29
+ __export(isInternalImport_exports, {
30
+ isInternalImport: () => isInternalImport
31
+ });
32
+ module.exports = __toCommonJS(isInternalImport_exports);
33
+ var fs = __toESM(require("fs"));
34
+ const projectRoot = process.cwd();
35
+ const libNames = [...fs.readdirSync(`${projectRoot}/libs`), ...fs.readdirSync(`${projectRoot}/pkgs`)];
36
+ const internalImportSet = /* @__PURE__ */ new Set([
37
+ ...libNames.map((libName) => `@${libName}`),
38
+ "react-icons",
39
+ "react",
40
+ "next",
41
+ "@radix-ui",
42
+ "@playwright",
43
+ "@akanjs",
44
+ ".",
45
+ ".."
46
+ ]);
47
+ const isInternalImport = (importPaths, appName) => {
48
+ if (internalImportSet.has(importPaths[0]))
49
+ return true;
50
+ else if (importPaths[0] === appName)
51
+ return true;
52
+ else
53
+ return false;
54
+ };
File without changes
File without changes