@akanjs/lint 0.0.44 → 0.0.45
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/index.js +328 -325
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,351 +1,354 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
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);
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
// pkgs/@akanjs/lint/index.ts
|
|
30
|
+
var lint_exports = {};
|
|
31
|
+
__export(lint_exports, {
|
|
32
|
+
default: () => lint_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(lint_exports);
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
if (filename === "layout.tsx") {
|
|
53
|
-
if (filePaths.at(-2) === "app")
|
|
54
|
-
return false;
|
|
55
|
-
else
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
if (serverFileNameSet.has(filename))
|
|
59
|
-
return true;
|
|
60
|
-
if (clientFileNameSet.has(filename))
|
|
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"))
|
|
61
52
|
return false;
|
|
62
|
-
|
|
53
|
+
else
|
|
63
54
|
return true;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
55
|
+
}
|
|
56
|
+
if (filename === "layout.tsx") {
|
|
57
|
+
if (filePaths.at(-2) === "app")
|
|
67
58
|
return false;
|
|
68
|
-
|
|
69
|
-
|
|
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
|
+
};
|
|
70
74
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
+
};
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
// pkgs/@akanjs/lint/util/fileHasContent.ts
|
|
82
|
+
var fileHasContent = (context, node) => {
|
|
83
|
+
const firstToken = context.sourceCode.getFirstToken(node);
|
|
84
|
+
return !!firstToken;
|
|
85
|
+
};
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
};
|
|
105
109
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
// pkgs/@akanjs/lint/util/getFilename.ts
|
|
111
|
+
var getFilename = (absFilePath) => {
|
|
112
|
+
const filePaths = absFilePath.split("/");
|
|
113
|
+
return filePaths.at(-1) ?? "";
|
|
114
|
+
};
|
|
111
115
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
+
};
|
|
150
154
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
+
};
|
|
174
178
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
+
};
|
|
181
185
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
},
|
|
190
|
-
messages: {
|
|
191
|
-
noImportClientFunctions: "Error: Client functions should not be imported."
|
|
192
|
-
},
|
|
193
|
-
// fixable: "code",
|
|
194
|
-
schema: []
|
|
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."
|
|
195
193
|
},
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
+
}
|
|
209
290
|
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
});
|
|
213
295
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
// fixable: "code",
|
|
227
|
-
schema: []
|
|
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.'
|
|
228
308
|
},
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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)
|
|
237
318
|
return {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
319
|
+
Program(node) {
|
|
320
|
+
if (!fileHasContent(context, node))
|
|
321
|
+
return;
|
|
322
|
+
const { hasUseClient, firstLineIdx } = fileHasUseClient(context);
|
|
323
|
+
if (hasUseClient)
|
|
241
324
|
context.report({
|
|
242
|
-
node,
|
|
243
|
-
messageId: "
|
|
244
|
-
// fix(fixer) {
|
|
245
|
-
// return fixer.remove(node);
|
|
246
|
-
// },
|
|
325
|
+
node: node.body[firstLineIdx],
|
|
326
|
+
messageId: "noUseClient"
|
|
247
327
|
});
|
|
248
328
|
}
|
|
249
329
|
};
|
|
250
|
-
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
// pkgs/@akanjs/lint/rules/nonScalarPropsRestricted.ts
|
|
254
|
-
var import_utils3 = __require("@typescript-eslint/utils");
|
|
255
|
-
var allowedPropKeySet = /* @__PURE__ */ new Set(["loader", "render", "of"]);
|
|
256
|
-
var nonScalarPropsRestricted = import_utils3.ESLintUtils.RuleCreator(() => __filename)({
|
|
257
|
-
name: "nonScalarPropsRestricted",
|
|
258
|
-
meta: {
|
|
259
|
-
type: "problem",
|
|
260
|
-
docs: {
|
|
261
|
-
description: "Enforce that non-scalar props are not used."
|
|
262
|
-
},
|
|
263
|
-
messages: {
|
|
264
|
-
nonScalarPropsRestricted: "Error: Non-scalar props should not be used."
|
|
265
|
-
},
|
|
266
|
-
// fixable: "code",
|
|
267
|
-
schema: []
|
|
268
|
-
},
|
|
269
|
-
defaultOptions: [],
|
|
270
|
-
create(context) {
|
|
271
|
-
const filename = getFilename(context.filename);
|
|
272
|
-
const isServerFile = fileIsServerFile(context.filename, context.sourceCode.text);
|
|
273
|
-
if (!isServerFile || !["page.tsx", "layout.tsx"].includes(filename))
|
|
274
|
-
return {};
|
|
330
|
+
else
|
|
275
331
|
return {
|
|
276
|
-
|
|
277
|
-
if (node
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
}
|
|
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
|
+
});
|
|
287
341
|
}
|
|
288
342
|
};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
// pkgs/@akanjs/lint/rules/useClientByFile.ts
|
|
293
|
-
var import_utils4 = __require("@typescript-eslint/utils");
|
|
294
|
-
var useClientByFile = import_utils4.ESLintUtils.RuleCreator(() => __filename)({
|
|
295
|
-
name: "useClientByFile",
|
|
296
|
-
meta: {
|
|
297
|
-
type: "problem",
|
|
298
|
-
docs: {
|
|
299
|
-
description: "Enforce that `use client` is not used in `server` files."
|
|
300
|
-
},
|
|
301
|
-
messages: {
|
|
302
|
-
noUseClient: 'Error: "use client" should not be used at the top of a `server` file.',
|
|
303
|
-
forceUseClient: 'Error: "use client" should be used at the top of a `client` file.'
|
|
304
|
-
},
|
|
305
|
-
// fixable: "code",
|
|
306
|
-
schema: []
|
|
307
|
-
},
|
|
308
|
-
defaultOptions: [],
|
|
309
|
-
create(context) {
|
|
310
|
-
const isServerFile = fileIsServerFile(context.filename, context.sourceCode.text);
|
|
311
|
-
if (isServerFile === null)
|
|
312
|
-
return {};
|
|
313
|
-
if (isServerFile)
|
|
314
|
-
return {
|
|
315
|
-
Program(node) {
|
|
316
|
-
if (!fileHasContent(context, node))
|
|
317
|
-
return;
|
|
318
|
-
const { hasUseClient, firstLineIdx } = fileHasUseClient(context);
|
|
319
|
-
if (hasUseClient)
|
|
320
|
-
context.report({
|
|
321
|
-
node: node.body[firstLineIdx],
|
|
322
|
-
messageId: "noUseClient"
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
else
|
|
327
|
-
return {
|
|
328
|
-
Program(node) {
|
|
329
|
-
if (!fileHasContent(context, node))
|
|
330
|
-
return;
|
|
331
|
-
const { hasUseClient, firstLineIdx } = fileHasUseClient(context);
|
|
332
|
-
if (!hasUseClient)
|
|
333
|
-
context.report({
|
|
334
|
-
node: node.body[firstLineIdx],
|
|
335
|
-
messageId: "forceUseClient"
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
});
|
|
343
|
+
}
|
|
344
|
+
});
|
|
341
345
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
})();
|
|
346
|
+
// pkgs/@akanjs/lint/index.ts
|
|
347
|
+
var lint_default = {
|
|
348
|
+
rules: {
|
|
349
|
+
noImportExternalLibrary,
|
|
350
|
+
noImportClientFunctions,
|
|
351
|
+
nonScalarPropsRestricted,
|
|
352
|
+
useClientByFile
|
|
353
|
+
}
|
|
354
|
+
};
|