@nkzw/eslint-plugin-fbtee 1.7.0 → 1.7.1

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.
@@ -3,37 +3,6 @@ import { ESLintUtils } from "@typescript-eslint/utils";
3
3
  //#region package.json
4
4
  var name = "@nkzw/eslint-plugin-fbtee";
5
5
  var version = "1.7.0";
6
- var description = "";
7
- var keywords = [];
8
- var repository = {
9
- "type": "git",
10
- "url": "git+https://github.com/nkzw-tech/fbtee.git",
11
- "directory": "packages/eslint-plugin-fbtee"
12
- };
13
- var license = "MIT";
14
- var type = "module";
15
- var exports = {
16
- "import": "./lib/index.js",
17
- "require": "./lib/index.cjs"
18
- };
19
- var main = "lib/index.cjs";
20
- var scripts = { "build": "tsdown src/index.tsx -d lib --target=node22 --format=esm,cjs --clean --dts" };
21
- var dependencies = { "@typescript-eslint/utils": "^8.46.0" };
22
- var devDependencies = { "@typescript-eslint/rule-tester": "^8.46.0" };
23
- var package_default = {
24
- name,
25
- version,
26
- description,
27
- keywords,
28
- repository,
29
- license,
30
- type,
31
- exports,
32
- main,
33
- scripts,
34
- dependencies,
35
- devDependencies
36
- };
37
6
 
38
7
  //#endregion
39
8
  //#region src/utils.tsx
@@ -344,8 +313,8 @@ var src_default = {
344
313
  } }
345
314
  },
346
315
  meta: {
347
- name: package_default.name,
348
- version: package_default.version
316
+ name,
317
+ version
349
318
  },
350
319
  rules: {
351
320
  "no-empty-strings": no_empty_strings_default,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nkzw/eslint-plugin-fbtee",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -11,17 +11,16 @@
11
11
  "license": "MIT",
12
12
  "type": "module",
13
13
  "exports": {
14
- "import": "./lib/index.js",
15
- "require": "./lib/index.cjs"
14
+ "import": "./lib/index.mjs"
16
15
  },
17
- "main": "lib/index.cjs",
16
+ "main": "lib/index.mjs",
18
17
  "dependencies": {
19
- "@typescript-eslint/utils": "^8.46.0"
18
+ "@typescript-eslint/utils": "^8.46.3"
20
19
  },
21
20
  "devDependencies": {
22
- "@typescript-eslint/rule-tester": "^8.46.0"
21
+ "@typescript-eslint/rule-tester": "^8.46.3"
23
22
  },
24
23
  "scripts": {
25
- "build": "tsdown src/index.tsx -d lib --target=node22 --format=esm,cjs --clean --dts"
24
+ "build": "tsdown src/index.tsx -d lib --target=node22 --format=esm --clean --dts"
26
25
  }
27
26
  }
package/lib/index.cjs DELETED
@@ -1,382 +0,0 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
-
23
- //#endregion
24
- let __typescript_eslint_utils = require("@typescript-eslint/utils");
25
- __typescript_eslint_utils = __toESM(__typescript_eslint_utils);
26
-
27
- //#region package.json
28
- var name = "@nkzw/eslint-plugin-fbtee";
29
- var version = "1.7.0";
30
- var description = "";
31
- var keywords = [];
32
- var repository = {
33
- "type": "git",
34
- "url": "git+https://github.com/nkzw-tech/fbtee.git",
35
- "directory": "packages/eslint-plugin-fbtee"
36
- };
37
- var license = "MIT";
38
- var type = "module";
39
- var exports$1 = {
40
- "import": "./lib/index.js",
41
- "require": "./lib/index.cjs"
42
- };
43
- var main = "lib/index.cjs";
44
- var scripts = { "build": "tsdown src/index.tsx -d lib --target=node22 --format=esm,cjs --clean --dts" };
45
- var dependencies = { "@typescript-eslint/utils": "^8.46.0" };
46
- var devDependencies = { "@typescript-eslint/rule-tester": "^8.46.0" };
47
- var package_default = {
48
- name,
49
- version,
50
- description,
51
- keywords,
52
- repository,
53
- license,
54
- type,
55
- exports: exports$1,
56
- main,
57
- scripts,
58
- dependencies,
59
- devDependencies
60
- };
61
-
62
- //#endregion
63
- //#region src/utils.tsx
64
- const createRule = __typescript_eslint_utils.ESLintUtils.RuleCreator((name$1) => `https://github.com/nkzw-tech/fbtee/blob/main/packages/eslint-plugin-fbtee/docs/rules/${name$1}.md`);
65
- function resolveMemberExpressions(object, property) {
66
- if (object.type === "JSXMemberExpression") return `${resolveMemberExpressions(object.object, object.property)}.${property.name}`;
67
- return `${object.name}.${property.name}`;
68
- }
69
- function elementType(node) {
70
- if (node.type === "JSXFragment") return "<>";
71
- const { name: name$1 } = node.openingElement;
72
- switch (name$1.type) {
73
- case "JSXIdentifier": return name$1.name;
74
- case "JSXMemberExpression": {
75
- const { object, property } = name$1;
76
- return resolveMemberExpressions(object, property);
77
- }
78
- case "JSXNamespacedName": return `${name$1.namespace.name}:${name$1.name.name}`;
79
- default: throw new Error("Unsupported JSX node type.");
80
- }
81
- }
82
- function resolveJsxElementTextContent(node) {
83
- return node.children.map((child) => {
84
- if (child.type === "JSXText") return child.value.trim();
85
- if (child.type === "JSXExpressionContainer") return resolveNodeValue(child.expression) || "";
86
- return "";
87
- }).join("").trim();
88
- }
89
- function resolveBinaryExpression(node) {
90
- if (node.operator !== "+") return null;
91
- const leftValue = resolveNodeValue(node.left);
92
- const rightValue = resolveNodeValue(node.right);
93
- if (leftValue !== null && rightValue !== null) return leftValue + rightValue;
94
- return null;
95
- }
96
- function resolveNodeValue(node) {
97
- if (node.type === "Literal" && typeof node.value === "string") return node.value;
98
- if (node.type === "TemplateLiteral" && node.expressions.length === 0) return node.quasis.map((quasi) => quasi.value.raw).join("");
99
- if (node.type === "BinaryExpression") return resolveBinaryExpression(node);
100
- if (node.type === "JSXExpressionContainer") return resolveNodeValue(node.expression);
101
- if (node.type === "ConditionalExpression") {
102
- const consequent = resolveNodeValue(node.consequent);
103
- const alternate = resolveNodeValue(node.alternate);
104
- return consequent || alternate || null;
105
- }
106
- if (node.type === "LogicalExpression") {
107
- const left = resolveNodeValue(node.left);
108
- const right = resolveNodeValue(node.right);
109
- return left || right || null;
110
- }
111
- return null;
112
- }
113
- function getPropName(prop) {
114
- if (prop.name.type === "JSXNamespacedName") return `${prop.name.namespace.name}:${prop.name.name.name}`;
115
- return prop.name.name;
116
- }
117
- function hasFbtParent(node) {
118
- let current = node.parent;
119
- while (current) {
120
- if (isFbtNode(current)) return true;
121
- current = current.parent;
122
- }
123
- return false;
124
- }
125
- function isFbtNode(node) {
126
- if (!node) return null;
127
- if (node.type === "JSXElement") {
128
- const name$1 = elementType(node);
129
- return name$1 === "fbt" || name$1 === "fbs" || name$1?.startsWith("fbt:");
130
- }
131
- if (node.type === "CallExpression" && node.callee.type === "Identifier") {
132
- const name$1 = node.callee.name;
133
- return name$1 === "fbt" || name$1 === "fbs";
134
- }
135
- if (node.type === "MemberExpression" && node.object.type === "CallExpression" && node.object.callee.type === "Identifier") {
136
- const name$1 = node.object.callee.name;
137
- return name$1 === "fbt" || name$1 === "fbs";
138
- }
139
- return false;
140
- }
141
-
142
- //#endregion
143
- //#region src/rules/no-empty-strings.tsx
144
- var no_empty_strings_default = createRule({
145
- create(context) {
146
- return {
147
- CallExpression(node) {
148
- if (!isFbtNode(node)) return;
149
- const [text] = node.arguments;
150
- if (text && text.type !== "SpreadElement" && isEmptyString(text)) context.report({
151
- messageId: "emptyString",
152
- node: text
153
- });
154
- },
155
- JSXElement(node) {
156
- if (!isFbtNode(node)) return;
157
- if (node.openingElement.name.type === "JSXNamespacedName") return;
158
- if (!validateChildren(node)) context.report({
159
- messageId: "jsxEmptyString",
160
- node
161
- });
162
- }
163
- };
164
- },
165
- defaultOptions: [],
166
- meta: {
167
- docs: { description: "Disallow empty strings in fbt elements or function calls." },
168
- messages: {
169
- emptyString: "Empty strings are not allowed in fbt() and fbs() function arguments.",
170
- jsxEmptyString: "Empty strings are not allowed as children of `<fbt>` and `<fbs>` tags."
171
- },
172
- schema: [],
173
- type: "problem"
174
- },
175
- name: "no-empty-strings"
176
- });
177
- function validateChildren(node) {
178
- let hasTextContent = false;
179
- for (const child of node.children) {
180
- if (child.type === "JSXText" && child.value.trim() !== "") hasTextContent = true;
181
- if (child.type === "JSXExpressionContainer") {
182
- if (child.expression.type === "JSXEmptyExpression") continue;
183
- if (child.expression.type === "Identifier" && child.expression.name !== "undefined") {
184
- hasTextContent = true;
185
- continue;
186
- }
187
- if (resolveNodeValue(child.expression)?.trim()) hasTextContent = true;
188
- }
189
- if (child.type === "JSXElement" || child.type === "JSXFragment") {
190
- const childName = elementType(child);
191
- if (/^[A-Z]/.test(childName) || childName.startsWith("fbt:")) {
192
- hasTextContent = true;
193
- continue;
194
- }
195
- hasTextContent ||= validateChildren(child);
196
- }
197
- if (hasTextContent) break;
198
- }
199
- return hasTextContent;
200
- }
201
- function isEmptyString(node) {
202
- return resolveNodeValue(node)?.trim() === "";
203
- }
204
-
205
- //#endregion
206
- //#region src/rules/no-unhelpful-desc.tsx
207
- var no_unhelpful_desc_default = createRule({
208
- create(context) {
209
- return {
210
- CallExpression(node) {
211
- if (!isFbtNode(node)) return;
212
- const [textArg, descArg] = node.arguments;
213
- const desc = descArg && descArg.type !== "SpreadElement" ? resolveNodeValue(descArg)?.trim() : null;
214
- if (!desc) {
215
- context.report({
216
- messageId: "emptyDesc",
217
- node: descArg || node
218
- });
219
- return;
220
- }
221
- if (desc.length <= 4) {
222
- context.report({
223
- messageId: "shortDesc",
224
- node: descArg || node
225
- });
226
- return;
227
- }
228
- const text = textArg && textArg.type !== "SpreadElement" ? resolveNodeValue(textArg)?.trim() : null;
229
- if (desc.toLowerCase() === text?.toLowerCase()) context.report({
230
- messageId: "duplicateDesc",
231
- node: descArg || node
232
- });
233
- },
234
- JSXAttribute(node) {
235
- if (!isFbtNode(node.parent.parent)) return;
236
- if (node.name.name !== "desc" || !node.value) return;
237
- if (node.value.type === "JSXExpressionContainer" && (node.value.expression.type === "Identifier" || node.value.expression.type === "CallExpression")) return;
238
- const desc = resolveNodeValue(node.value)?.trim();
239
- if (!desc) {
240
- context.report({
241
- messageId: "jsxEmptyDesc",
242
- node: node.value
243
- });
244
- return;
245
- }
246
- if (desc.length <= 4) {
247
- context.report({
248
- messageId: "shortDesc",
249
- node: node.value
250
- });
251
- return;
252
- }
253
- const textContent = resolveJsxElementTextContent(node.parent.parent);
254
- if (desc.toLowerCase() === textContent.toLowerCase()) context.report({
255
- messageId: "duplicateDesc",
256
- node: node.value
257
- });
258
- }
259
- };
260
- },
261
- defaultOptions: [],
262
- meta: {
263
- docs: { description: "Enforce meaningful and non-empty descriptions in <fbt> elements and fbt()/fbs() function calls." },
264
- messages: {
265
- duplicateDesc: "The \"desc\" attribute or argument should not be a duplicate of the text content.",
266
- emptyDesc: "The \"desc\" argument in fbt() and fbs() must not be empty.",
267
- jsxEmptyDesc: "The \"desc\" attribute in <fbt> must not be empty.",
268
- shortDesc: "The \"desc\" attribute or argument is too short. Use a more descriptive and meaningful explanation."
269
- },
270
- schema: [],
271
- type: "problem"
272
- },
273
- name: "no-unhelpful-desc"
274
- });
275
-
276
- //#endregion
277
- //#region src/rules/no-untranslated-strings.tsx
278
- const attributes = new Set([
279
- "title",
280
- "placeholder",
281
- "alt",
282
- "label",
283
- "aria-label",
284
- "aria-errormessage"
285
- ]);
286
- const shouldIgnoreParent = (node) => {
287
- const { parent } = node;
288
- const openingElement = parent?.type === "JSXElement" ? parent?.openingElement : null;
289
- return openingElement?.type === "JSXOpeningElement" && openingElement.name.type === "JSXIdentifier" && (openingElement.name.name === "pre" || openingElement.name.name === "code");
290
- };
291
- var no_untranslated_strings_default = createRule({
292
- create(context, options) {
293
- const ignoredWords = new Set(options[0].ignoredWords.map((value) => value.trim().toLowerCase()));
294
- const isIgnoredWord = (value) => ignoredWords.has(value.replaceAll(/\s+/g, " ").toLowerCase());
295
- return {
296
- JSXAttribute(node) {
297
- const propName = getPropName(node);
298
- if (!attributes.has(propName)) return;
299
- const value = node.value ? resolveNodeValue(node.value) : null;
300
- if (!value) return;
301
- if (isIgnoredWord(value)) return;
302
- if (node.value?.type === "JSXExpressionContainer" && isFbtNode(node.value.expression)) return;
303
- context.report({
304
- messageId: "unwrappedString",
305
- node
306
- });
307
- },
308
- JSXExpressionContainer(node) {
309
- if (node.parent.type === "JSXAttribute") return;
310
- const value = resolveNodeValue(node.expression);
311
- if (!value) return;
312
- if (isIgnoredWord(value)) return;
313
- if (shouldIgnoreParent(node)) return;
314
- if (!hasFbtParent(node)) context.report({
315
- messageId: "unwrappedString",
316
- node
317
- });
318
- },
319
- JSXText(node) {
320
- const value = node.value.trim();
321
- if (!value) return;
322
- if (isIgnoredWord(value)) return;
323
- if (shouldIgnoreParent(node)) return;
324
- if (!hasFbtParent(node)) {
325
- const startOffset = node.range[0] + node.value.indexOf(value);
326
- const endOffset = startOffset + value.length;
327
- context.report({
328
- loc: {
329
- end: context.sourceCode.getLocFromIndex(endOffset),
330
- start: context.sourceCode.getLocFromIndex(startOffset)
331
- },
332
- messageId: "unwrappedString"
333
- });
334
- }
335
- }
336
- };
337
- },
338
- defaultOptions: [{ ignoredWords: [] }],
339
- meta: {
340
- docs: { description: "Enforce text content to be wrapped with `<fbt>`, `fbt()` or `fbs()`" },
341
- messages: { unwrappedString: "Text content must be wrapped in `<fbt>`, `fbt()` or `fbs()`" },
342
- schema: [{
343
- additionalProperties: false,
344
- properties: { ignoredWords: {
345
- items: { type: "string" },
346
- type: "array",
347
- uniqueItems: true
348
- } },
349
- type: "object"
350
- }],
351
- type: "problem"
352
- },
353
- name: "no-untranslated-strings"
354
- });
355
-
356
- //#endregion
357
- //#region src/index.tsx
358
- var src_default = {
359
- configs: {
360
- recommended: { rules: {
361
- "@nkzw/fbtee/no-empty-strings": 2,
362
- "@nkzw/fbtee/no-unhelpful-desc": 2
363
- } },
364
- strict: { rules: {
365
- "@nkzw/fbtee/no-empty-strings": 2,
366
- "@nkzw/fbtee/no-unhelpful-desc": 2,
367
- "@nkzw/fbtee/no-untranslated-strings": 2
368
- } }
369
- },
370
- meta: {
371
- name: package_default.name,
372
- version: package_default.version
373
- },
374
- rules: {
375
- "no-empty-strings": no_empty_strings_default,
376
- "no-unhelpful-desc": no_unhelpful_desc_default,
377
- "no-untranslated-strings": no_untranslated_strings_default
378
- }
379
- };
380
-
381
- //#endregion
382
- module.exports = src_default;
package/lib/index.d.cts DELETED
@@ -1,32 +0,0 @@
1
- import * as _typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
2
-
3
- //#region src/index.d.ts
4
- declare const _default: {
5
- configs: {
6
- recommended: {
7
- rules: {
8
- '@nkzw/fbtee/no-empty-strings': number;
9
- '@nkzw/fbtee/no-unhelpful-desc': number;
10
- };
11
- };
12
- strict: {
13
- rules: {
14
- '@nkzw/fbtee/no-empty-strings': number;
15
- '@nkzw/fbtee/no-unhelpful-desc': number;
16
- '@nkzw/fbtee/no-untranslated-strings': number;
17
- };
18
- };
19
- };
20
- meta: {
21
- name: string;
22
- version: string;
23
- };
24
- rules: {
25
- 'no-empty-strings': _typescript_eslint_utils_ts_eslint0.RuleModule<"emptyString" | "jsxEmptyString", [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
26
- 'no-unhelpful-desc': _typescript_eslint_utils_ts_eslint0.RuleModule<"emptyDesc" | "jsxEmptyDesc" | "duplicateDesc" | "shortDesc", [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
27
- 'no-untranslated-strings': _typescript_eslint_utils_ts_eslint0.RuleModule<"unwrappedString", [{
28
- ignoredWords: Array<string>;
29
- }], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
30
- };
31
- };
32
- export = _default;
File without changes