@next-vibe/checker 1.0.14 → 1.0.15

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.
@@ -1,4 +1,381 @@
1
- (function() {
2
- "use strict";
3
- })();
4
- //# sourceMappingURL=i18n.js.map
1
+ import { createRequire } from "node:module";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
7
+ var __toCommonJS = (from) => {
8
+ var entry = __moduleCache.get(from), desc;
9
+ if (entry)
10
+ return entry;
11
+ entry = __defProp({}, "__esModule", { value: true });
12
+ if (from && typeof from === "object" || typeof from === "function")
13
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ }));
17
+ __moduleCache.set(from, entry);
18
+ return entry;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, {
23
+ get: all[name],
24
+ enumerable: true,
25
+ configurable: true,
26
+ set: (newValue) => all[name] = () => newValue
27
+ });
28
+ };
29
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
30
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
31
+
32
+ // src/app/api/[locale]/system/check/oxlint/plugins/shared/config-loader.ts
33
+ var exports_config_loader = {};
34
+ __export(exports_config_loader, {
35
+ loadPluginConfig: () => loadPluginConfig,
36
+ getCheckConfig: () => getCheckConfig,
37
+ createPluginMessages: () => createPluginMessages,
38
+ clearConfigCache: () => clearConfigCache
39
+ });
40
+ import { existsSync } from "node:fs";
41
+ import { dirname, resolve } from "node:path";
42
+ function findProjectRoot() {
43
+ const cwd = process.cwd();
44
+ let currentDir = cwd;
45
+ const root = resolve("/");
46
+ while (currentDir !== root) {
47
+ const configPath = resolve(currentDir, "check.config.ts");
48
+ if (existsSync(configPath)) {
49
+ return currentDir;
50
+ }
51
+ const jsConfigPath = resolve(currentDir, "check.config.js");
52
+ if (existsSync(jsConfigPath)) {
53
+ return currentDir;
54
+ }
55
+ currentDir = dirname(currentDir);
56
+ }
57
+ return cwd;
58
+ }
59
+ function getConfigPaths() {
60
+ const projectRoot = findProjectRoot();
61
+ return [
62
+ resolve(projectRoot, "check.config.ts"),
63
+ resolve(projectRoot, "check.config.js"),
64
+ resolve(projectRoot, "node_modules", "next-vibe", "check.config.js"),
65
+ resolve(projectRoot, "node_modules", "next-vibe", "dist", "check.config.js")
66
+ ];
67
+ }
68
+ function loadCheckConfigSync() {
69
+ if (configLoadAttempted) {
70
+ return cachedCheckConfig;
71
+ }
72
+ configLoadAttempted = true;
73
+ const configPaths = getConfigPaths();
74
+ for (const configPath of configPaths) {
75
+ if (!existsSync(configPath)) {
76
+ continue;
77
+ }
78
+ try {
79
+ const configModule = __require(configPath);
80
+ const exportedValue = configModule.default ?? configModule.config;
81
+ if (!exportedValue) {
82
+ continue;
83
+ }
84
+ const config = typeof exportedValue === "function" ? exportedValue() : exportedValue;
85
+ cachedCheckConfig = config;
86
+ return config;
87
+ } catch {
88
+ continue;
89
+ }
90
+ }
91
+ return null;
92
+ }
93
+ function extractPluginOptions(checkConfig, pluginName) {
94
+ if (!checkConfig.oxlint.enabled) {
95
+ return null;
96
+ }
97
+ const rules = checkConfig.oxlint.rules;
98
+ if (!rules) {
99
+ return null;
100
+ }
101
+ const ruleConfig = rules[pluginName];
102
+ if (Array.isArray(ruleConfig) && ruleConfig.length >= 2) {
103
+ return ruleConfig[1];
104
+ }
105
+ return null;
106
+ }
107
+ function loadPluginConfig(pluginName, defaultConfig) {
108
+ const cached = pluginConfigCache.get(pluginName);
109
+ if (cached) {
110
+ return cached;
111
+ }
112
+ const checkConfig = loadCheckConfigSync();
113
+ if (checkConfig) {
114
+ const pluginOptions = extractPluginOptions(checkConfig, pluginName);
115
+ if (pluginOptions) {
116
+ const result2 = {
117
+ success: true,
118
+ config: pluginOptions,
119
+ source: "rule-config"
120
+ };
121
+ pluginConfigCache.set(pluginName, result2);
122
+ return result2;
123
+ }
124
+ }
125
+ if (defaultConfig) {
126
+ const result2 = {
127
+ success: true,
128
+ config: defaultConfig,
129
+ source: "default"
130
+ };
131
+ pluginConfigCache.set(pluginName, result2);
132
+ return result2;
133
+ }
134
+ const result = {
135
+ success: false,
136
+ config: null,
137
+ source: "error",
138
+ error: `No configuration found for ${pluginName}`
139
+ };
140
+ pluginConfigCache.set(pluginName, result);
141
+ return result;
142
+ }
143
+ function getCheckConfig() {
144
+ return loadCheckConfigSync();
145
+ }
146
+ function clearConfigCache() {
147
+ cachedCheckConfig = null;
148
+ configLoadAttempted = false;
149
+ pluginConfigCache.clear();
150
+ }
151
+ function createPluginMessages(defaults, overrides) {
152
+ return { ...defaults, ...overrides };
153
+ }
154
+ var cachedCheckConfig = null, configLoadAttempted = false, pluginConfigCache;
155
+ var init_config_loader = __esm(() => {
156
+ pluginConfigCache = new Map;
157
+ });
158
+
159
+ // src/app/api/[locale]/system/check/oxlint/plugins/i18n/src/index.ts
160
+ var DEFAULT_CONFIG = {
161
+ words: {
162
+ exclude: [
163
+ String.raw`^[\[\]{}—<>•+%#@.:_*;,/()\-]+$`,
164
+ String.raw`^\s+$`,
165
+ String.raw`^\d+$`,
166
+ String.raw`^[^\s]+\.[^\s]+$`,
167
+ String.raw`^(?:https?://|/)[^\s]*$`
168
+ ]
169
+ },
170
+ "jsx-attributes": {
171
+ exclude: [
172
+ "className",
173
+ "href",
174
+ "src",
175
+ "alt",
176
+ "id",
177
+ "name",
178
+ "type",
179
+ "value",
180
+ "key",
181
+ "ref",
182
+ "*ClassName",
183
+ "*Style",
184
+ "*Variant",
185
+ "*Size",
186
+ "*Color"
187
+ ]
188
+ },
189
+ "object-properties": {
190
+ exclude: []
191
+ }
192
+ };
193
+ var DEFAULT_MESSAGES = {
194
+ jsxText: 'Literal string "{value}" should be translated using i18n.',
195
+ jsxExpression: 'Literal string "{value}" in JSX expression should be translated.',
196
+ jsxAttribute: 'Literal string "{value}" in JSX attribute should be translated.'
197
+ };
198
+ var configLoader = null;
199
+ var cachedConfig = null;
200
+ var cachedMessages = null;
201
+ function getConfigLoader() {
202
+ if (configLoader) {
203
+ return configLoader;
204
+ }
205
+ try {
206
+ configLoader = (init_config_loader(), __toCommonJS(exports_config_loader));
207
+ return configLoader;
208
+ } catch {
209
+ return null;
210
+ }
211
+ }
212
+ function loadI18nConfig() {
213
+ if (cachedConfig !== null) {
214
+ return cachedConfig;
215
+ }
216
+ const loader = getConfigLoader();
217
+ if (loader) {
218
+ const result = loader.loadPluginConfig("oxlint-plugin-i18n/no-literal-string", DEFAULT_CONFIG);
219
+ cachedConfig = result.config ?? DEFAULT_CONFIG;
220
+ } else {
221
+ cachedConfig = loadConfigFallback();
222
+ }
223
+ return cachedConfig;
224
+ }
225
+ function loadConfigFallback() {
226
+ try {
227
+ const config = __require(`${process.cwd()}/check.config.ts`);
228
+ const checkConfig = config.default ?? config;
229
+ const exported = typeof checkConfig === "function" ? checkConfig() : checkConfig;
230
+ const ruleConfig = exported?.oxlint?.rules?.["oxlint-plugin-i18n/no-literal-string"];
231
+ if (Array.isArray(ruleConfig) && ruleConfig[1]) {
232
+ return ruleConfig[1];
233
+ }
234
+ } catch {}
235
+ return DEFAULT_CONFIG;
236
+ }
237
+ function getMessages() {
238
+ if (cachedMessages !== null) {
239
+ return cachedMessages;
240
+ }
241
+ cachedMessages = DEFAULT_MESSAGES;
242
+ return cachedMessages;
243
+ }
244
+ function formatMessage(template, value) {
245
+ return template.replaceAll("{value}", value);
246
+ }
247
+ var noLiteralStringRule = {
248
+ meta: {
249
+ type: "problem",
250
+ docs: {
251
+ description: "Disallow literal strings that should be internationalized",
252
+ category: "Best Practices",
253
+ recommended: true
254
+ },
255
+ schema: [
256
+ {
257
+ type: "object",
258
+ properties: {
259
+ words: {
260
+ type: "object",
261
+ properties: {
262
+ exclude: { type: "array", items: { type: "string" } }
263
+ }
264
+ },
265
+ "jsx-attributes": {
266
+ type: "object",
267
+ properties: {
268
+ exclude: { type: "array", items: { type: "string" } }
269
+ }
270
+ },
271
+ "object-properties": {
272
+ type: "object",
273
+ properties: {
274
+ exclude: { type: "array", items: { type: "string" } }
275
+ }
276
+ }
277
+ }
278
+ }
279
+ ]
280
+ },
281
+ create(context) {
282
+ const configFromFile = loadI18nConfig();
283
+ const ruleOptions = context.options?.[0] ?? {};
284
+ const options = {
285
+ ...configFromFile,
286
+ ...ruleOptions,
287
+ words: {
288
+ ...configFromFile.words,
289
+ ...ruleOptions.words
290
+ },
291
+ "jsx-attributes": {
292
+ ...configFromFile["jsx-attributes"],
293
+ ...ruleOptions["jsx-attributes"]
294
+ }
295
+ };
296
+ const messages = getMessages();
297
+ const wordExclusionPatterns = (options.words?.exclude ?? []).map((pattern) => new RegExp(pattern, "u"));
298
+ const excludedAttributes = options["jsx-attributes"]?.exclude ?? [];
299
+ const shouldExcludeString = (value) => {
300
+ if (!value || typeof value !== "string") {
301
+ return true;
302
+ }
303
+ for (const pattern of wordExclusionPatterns) {
304
+ if (pattern.test(value)) {
305
+ return true;
306
+ }
307
+ }
308
+ return false;
309
+ };
310
+ const isExcludedAttribute = (attrName) => {
311
+ return excludedAttributes.some((excluded) => {
312
+ if (excluded.startsWith("*")) {
313
+ return attrName.endsWith(excluded.slice(1));
314
+ }
315
+ return attrName === excluded;
316
+ });
317
+ };
318
+ return {
319
+ JSXText(node) {
320
+ const value = node.value;
321
+ if (typeof value !== "string") {
322
+ return;
323
+ }
324
+ const trimmed = value.trim();
325
+ if (trimmed && !shouldExcludeString(trimmed)) {
326
+ context.report({
327
+ node,
328
+ message: formatMessage(messages.jsxText, trimmed)
329
+ });
330
+ }
331
+ },
332
+ "JSXExpressionContainer > Literal"(node) {
333
+ const value = node.value;
334
+ if (typeof value === "string" && !shouldExcludeString(value)) {
335
+ context.report({
336
+ node,
337
+ message: formatMessage(messages.jsxExpression, value)
338
+ });
339
+ }
340
+ },
341
+ JSXAttribute(node) {
342
+ const attrNode = node;
343
+ const nameNode = attrNode.name;
344
+ if (!nameNode) {
345
+ return;
346
+ }
347
+ const attrName = nameNode.name ?? String(nameNode);
348
+ if (isExcludedAttribute(attrName)) {
349
+ return;
350
+ }
351
+ const valueNode = attrNode.value;
352
+ if (!valueNode) {
353
+ return;
354
+ }
355
+ if (valueNode.type === "Literal") {
356
+ const literalValue = valueNode.value;
357
+ if (typeof literalValue === "string" && !shouldExcludeString(literalValue)) {
358
+ context.report({
359
+ node: valueNode,
360
+ message: formatMessage(messages.jsxAttribute, literalValue)
361
+ });
362
+ }
363
+ }
364
+ }
365
+ };
366
+ }
367
+ };
368
+ var src_default = {
369
+ meta: {
370
+ name: "oxlint-plugin-i18n",
371
+ version: "1.0.0"
372
+ },
373
+ rules: {
374
+ "no-literal-string": noLiteralStringRule
375
+ }
376
+ };
377
+ export {
378
+ DEFAULT_MESSAGES as defaultMessages,
379
+ DEFAULT_CONFIG as defaultConfig,
380
+ src_default as default
381
+ };