@conorroberts/utils 0.0.35 → 0.0.38

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 (42) hide show
  1. package/dist/{env.d.ts → env.d.mts} +10 -7
  2. package/dist/env.mjs +32 -0
  3. package/dist/env.mjs.map +1 -0
  4. package/dist/images.d.mts +79 -0
  5. package/dist/images.mjs +129 -0
  6. package/dist/images.mjs.map +1 -0
  7. package/dist/oxlint/config.d.mts +46 -0
  8. package/dist/oxlint/config.mjs +71 -0
  9. package/dist/oxlint/config.mjs.map +1 -0
  10. package/dist/oxlint/jsx-component-pascal-case.d.mts +25 -0
  11. package/dist/oxlint/jsx-component-pascal-case.mjs +159 -0
  12. package/dist/oxlint/jsx-component-pascal-case.mjs.map +1 -0
  13. package/dist/oxlint/no-component-date-instantiation.d.mts +27 -0
  14. package/dist/oxlint/no-component-date-instantiation.mjs +160 -0
  15. package/dist/oxlint/no-component-date-instantiation.mjs.map +1 -0
  16. package/dist/oxlint/no-emoji.d.mts +16 -0
  17. package/dist/oxlint/no-emoji.mjs +89 -0
  18. package/dist/oxlint/no-emoji.mjs.map +1 -0
  19. package/dist/oxlint/no-finally.d.mts +16 -0
  20. package/dist/oxlint/no-finally.mjs +32 -0
  21. package/dist/oxlint/no-finally.mjs.map +1 -0
  22. package/dist/oxlint/no-inline-components.d.mts +44 -0
  23. package/dist/oxlint/no-inline-components.mjs +350 -0
  24. package/dist/oxlint/no-inline-components.mjs.map +1 -0
  25. package/dist/oxlint/no-react-namespace.d.mts +16 -0
  26. package/dist/oxlint/no-react-namespace.mjs +75 -0
  27. package/dist/oxlint/no-react-namespace.mjs.map +1 -0
  28. package/dist/oxlint/no-switch-plugin.d.mts +15 -0
  29. package/dist/oxlint/no-switch-plugin.mjs +31 -0
  30. package/dist/oxlint/no-switch-plugin.mjs.map +1 -0
  31. package/dist/oxlint/no-top-level-let.d.mts +16 -0
  32. package/dist/oxlint/no-top-level-let.mjs +66 -0
  33. package/dist/oxlint/no-top-level-let.mjs.map +1 -0
  34. package/dist/oxlint/no-type-cast.d.mts +16 -0
  35. package/dist/oxlint/no-type-cast.mjs +49 -0
  36. package/dist/oxlint/no-type-cast.mjs.map +1 -0
  37. package/package.json +47 -6
  38. package/dist/env.js +0 -30
  39. package/dist/env.js.map +0 -1
  40. package/dist/images.d.ts +0 -77
  41. package/dist/images.js +0 -151
  42. package/dist/images.js.map +0 -1
@@ -0,0 +1,160 @@
1
+ import { defineRule } from "oxlint";
2
+
3
+ //#region src/oxlint-plugins/no-component-date-instantiation.js
4
+ /**
5
+ * @typedef {import("oxlint").Context} RuleContext
6
+ * @typedef {import("oxlint").ESTree.Node} ESTNode
7
+ * @typedef {import("oxlint").ESTree.NewExpression} NewExpressionNode
8
+ * @typedef {import("oxlint").ESTree.ReturnStatement} ReturnStatementNode
9
+ * @typedef {import("oxlint").ESTree.Function | import("oxlint").ESTree.ArrowFunctionExpression} FunctionLikeNode
10
+ */
11
+ /**
12
+ * @typedef {object} FunctionContext
13
+ * @property {FunctionLikeNode} node
14
+ * @property {FunctionContext | null} parent
15
+ * @property {string} name
16
+ * @property {boolean} returnsJsx
17
+ * @property {NewExpressionNode[]} dateInstantiations
18
+ */
19
+ const FUNCTION_NODE_TYPES = new Set([
20
+ "FunctionDeclaration",
21
+ "FunctionExpression",
22
+ "ArrowFunctionExpression"
23
+ ]);
24
+ /**
25
+ * @param {unknown} node
26
+ * @returns {node is ESTNode & { type: string }}
27
+ */
28
+ const isNode = (node) => Boolean(node && typeof node === "object" && "type" in node);
29
+ /**
30
+ * @param {unknown} node
31
+ * @returns {node is FunctionLikeNode}
32
+ */
33
+ const isFunctionLike = (node) => isNode(node) && FUNCTION_NODE_TYPES.has(node.type);
34
+ /**
35
+ * Check if a function name follows React component naming convention (PascalCase)
36
+ * @param {unknown} name
37
+ * @returns {name is string}
38
+ */
39
+ const isComponentName = (name) => typeof name === "string" && /^[A-Z]/.test(name);
40
+ /**
41
+ * Get the name of a function node
42
+ * @param {FunctionLikeNode} node
43
+ * @returns {string}
44
+ */
45
+ const getFunctionName = (node) => {
46
+ if (node.type === "FunctionDeclaration" && node.id && node.id.type === "Identifier") return node.id.name;
47
+ if ((node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") && node.id) {
48
+ if (node.id.type === "Identifier") return node.id.name;
49
+ }
50
+ const parent = node.parent;
51
+ if (!parent || !isNode(parent)) return "";
52
+ if (parent.type === "VariableDeclarator") return parent.id && parent.id.type === "Identifier" ? parent.id.name : "";
53
+ if (parent.type === "AssignmentExpression") return parent.left && parent.left.type === "Identifier" ? parent.left.name : "";
54
+ if (parent.type === "Property" || parent.type === "MethodDefinition") return parent.key && parent.key.type === "Identifier" ? parent.key.name : "";
55
+ return "";
56
+ };
57
+ /**
58
+ * Check if a node is a JSX element or fragment
59
+ * @param {ESTNode | null | undefined} node
60
+ * @returns {boolean}
61
+ */
62
+ const isJSXNode = (node) => {
63
+ if (!node || !isNode(node)) return false;
64
+ return node.type === "JSXElement" || node.type === "JSXFragment";
65
+ };
66
+ /**
67
+ * Check if a NewExpression is creating a Date instance
68
+ * @param {NewExpressionNode} node
69
+ * @returns {boolean}
70
+ */
71
+ const isDateInstantiation = (node) => {
72
+ if (node.callee.type === "Identifier" && node.callee.name === "Date") return true;
73
+ return false;
74
+ };
75
+ const rule = defineRule({
76
+ meta: {
77
+ type: "problem",
78
+ docs: {
79
+ description: "Disallow Date instantiation in the top scope of React components. Date instances declared on every render are bad because they change every render.",
80
+ recommended: true
81
+ },
82
+ schema: []
83
+ },
84
+ createOnce(context) {
85
+ /** @type {FunctionContext[]} */
86
+ const functionStack = [];
87
+ const currentFunction = () => functionStack[functionStack.length - 1] ?? null;
88
+ /**
89
+ * @param {FunctionLikeNode} node
90
+ */
91
+ const enterFunction = (node) => {
92
+ /** @type {FunctionContext} */
93
+ const fnCtx = {
94
+ node,
95
+ parent: currentFunction(),
96
+ name: getFunctionName(node),
97
+ returnsJsx: false,
98
+ dateInstantiations: []
99
+ };
100
+ functionStack.push(fnCtx);
101
+ if (node.type === "ArrowFunctionExpression" && node.body && node.body.type !== "BlockStatement") {
102
+ if (isJSXNode(node.body)) fnCtx.returnsJsx = true;
103
+ }
104
+ };
105
+ const exitFunction = () => {
106
+ const fnCtx = functionStack.pop();
107
+ if (!fnCtx) return;
108
+ if (!fnCtx.returnsJsx) return;
109
+ if (!isComponentName(fnCtx.name)) return;
110
+ for (const dateNode of fnCtx.dateInstantiations) context.report({
111
+ node: dateNode,
112
+ message: `Avoid instantiating Date in the top scope of component '${fnCtx.name}'. Date instances change on every render. Move it inside an effect, event handler, or use useMemo/useCallback.`
113
+ });
114
+ };
115
+ /** @param {ReturnStatementNode} node */
116
+ const handleReturnStatement = (node) => {
117
+ const fnCtx = currentFunction();
118
+ if (!fnCtx) return;
119
+ const argument = node.argument;
120
+ if (!argument) return;
121
+ if (isJSXNode(argument)) fnCtx.returnsJsx = true;
122
+ };
123
+ /** @param {NewExpressionNode} node */
124
+ const handleNewExpression = (node) => {
125
+ if (!isDateInstantiation(node)) return;
126
+ const fnCtx = currentFunction();
127
+ if (!fnCtx) return;
128
+ fnCtx.dateInstantiations.push(node);
129
+ };
130
+ return {
131
+ FunctionDeclaration(node) {
132
+ if (isFunctionLike(node)) enterFunction(node);
133
+ },
134
+ "FunctionDeclaration:exit": exitFunction,
135
+ FunctionExpression(node) {
136
+ if (isFunctionLike(node)) enterFunction(node);
137
+ },
138
+ "FunctionExpression:exit": exitFunction,
139
+ ArrowFunctionExpression(node) {
140
+ if (isFunctionLike(node)) enterFunction(node);
141
+ },
142
+ "ArrowFunctionExpression:exit": exitFunction,
143
+ ReturnStatement(node) {
144
+ if (node.type === "ReturnStatement") handleReturnStatement(node);
145
+ },
146
+ NewExpression(node) {
147
+ if (node.type === "NewExpression") handleNewExpression(node);
148
+ }
149
+ };
150
+ }
151
+ });
152
+ const noComponentDateInstantiationRule = rule;
153
+ var no_component_date_instantiation_default = {
154
+ meta: { name: "no-component-date-instantiation" },
155
+ rules: { "no-component-date-instantiation": rule }
156
+ };
157
+
158
+ //#endregion
159
+ export { no_component_date_instantiation_default as default, noComponentDateInstantiationRule };
160
+ //# sourceMappingURL=no-component-date-instantiation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-component-date-instantiation.mjs","names":[],"sources":["../../src/oxlint-plugins/no-component-date-instantiation.js"],"sourcesContent":["import { defineRule } from \"oxlint\";\r\n\r\n/**\r\n * @typedef {import(\"oxlint\").Context} RuleContext\r\n * @typedef {import(\"oxlint\").ESTree.Node} ESTNode\r\n * @typedef {import(\"oxlint\").ESTree.NewExpression} NewExpressionNode\r\n * @typedef {import(\"oxlint\").ESTree.ReturnStatement} ReturnStatementNode\r\n * @typedef {import(\"oxlint\").ESTree.Function | import(\"oxlint\").ESTree.ArrowFunctionExpression} FunctionLikeNode\r\n */\r\n\r\n/**\r\n * @typedef {object} FunctionContext\r\n * @property {FunctionLikeNode} node\r\n * @property {FunctionContext | null} parent\r\n * @property {string} name\r\n * @property {boolean} returnsJsx\r\n * @property {NewExpressionNode[]} dateInstantiations\r\n */\r\n\r\nconst FUNCTION_NODE_TYPES = new Set([\"FunctionDeclaration\", \"FunctionExpression\", \"ArrowFunctionExpression\"]);\r\n\r\n/**\r\n * @param {unknown} node\r\n * @returns {node is ESTNode & { type: string }}\r\n */\r\nconst isNode = (node) => Boolean(node && typeof node === \"object\" && \"type\" in node);\r\n\r\n/**\r\n * @param {unknown} node\r\n * @returns {node is FunctionLikeNode}\r\n */\r\nconst isFunctionLike = (node) => isNode(node) && FUNCTION_NODE_TYPES.has(node.type);\r\n\r\n/**\r\n * Check if a function name follows React component naming convention (PascalCase)\r\n * @param {unknown} name\r\n * @returns {name is string}\r\n */\r\nconst isComponentName = (name) => typeof name === \"string\" && /^[A-Z]/.test(name);\r\n\r\n/**\r\n * Get the name of a function node\r\n * @param {FunctionLikeNode} node\r\n * @returns {string}\r\n */\r\nconst getFunctionName = (node) => {\r\n if (node.type === \"FunctionDeclaration\" && node.id && node.id.type === \"Identifier\") {\r\n return node.id.name;\r\n }\r\n\r\n if ((node.type === \"FunctionExpression\" || node.type === \"ArrowFunctionExpression\") && node.id) {\r\n if (node.id.type === \"Identifier\") return node.id.name;\r\n }\r\n\r\n const parent = node.parent;\r\n if (!parent || !isNode(parent)) return \"\";\r\n\r\n if (parent.type === \"VariableDeclarator\") {\r\n return parent.id && parent.id.type === \"Identifier\" ? parent.id.name : \"\";\r\n }\r\n\r\n if (parent.type === \"AssignmentExpression\") {\r\n return parent.left && parent.left.type === \"Identifier\" ? parent.left.name : \"\";\r\n }\r\n\r\n if (parent.type === \"Property\" || parent.type === \"MethodDefinition\") {\r\n return parent.key && parent.key.type === \"Identifier\" ? parent.key.name : \"\";\r\n }\r\n\r\n return \"\";\r\n};\r\n\r\n/**\r\n * Check if a node is a JSX element or fragment\r\n * @param {ESTNode | null | undefined} node\r\n * @returns {boolean}\r\n */\r\nconst isJSXNode = (node) => {\r\n if (!node || !isNode(node)) return false;\r\n return node.type === \"JSXElement\" || node.type === \"JSXFragment\";\r\n};\r\n\r\n/**\r\n * Check if a NewExpression is creating a Date instance\r\n * @param {NewExpressionNode} node\r\n * @returns {boolean}\r\n */\r\nconst isDateInstantiation = (node) => {\r\n if (node.callee.type === \"Identifier\" && node.callee.name === \"Date\") {\r\n return true;\r\n }\r\n return false;\r\n};\r\n\r\n/**\r\n * Find the enclosing function for a node\r\n * @param {ESTNode | null | undefined} node\r\n * @returns {FunctionLikeNode | null}\r\n */\r\nconst getEnclosingFunction = (node) => {\r\n const findFunction = (current) => {\r\n if (!current) return null;\r\n if (isFunctionLike(current)) {\r\n return current;\r\n }\r\n return findFunction(isNode(current) ? (current.parent ?? null) : null);\r\n };\r\n return findFunction(isNode(node) ? (node.parent ?? null) : null);\r\n};\r\n\r\nconst rule = defineRule({\r\n meta: {\r\n type: \"problem\",\r\n docs: {\r\n description:\r\n \"Disallow Date instantiation in the top scope of React components. Date instances declared on every render are bad because they change every render.\",\r\n recommended: true,\r\n },\r\n schema: [],\r\n },\r\n createOnce(context) {\r\n /** @type {FunctionContext[]} */\r\n const functionStack = [];\r\n\r\n const currentFunction = () => functionStack[functionStack.length - 1] ?? null;\r\n\r\n /**\r\n * @param {FunctionLikeNode} node\r\n */\r\n const enterFunction = (node) => {\r\n const parent = currentFunction();\r\n /** @type {FunctionContext} */\r\n const fnCtx = {\r\n node,\r\n parent,\r\n name: getFunctionName(node),\r\n returnsJsx: false,\r\n dateInstantiations: [],\r\n };\r\n\r\n functionStack.push(fnCtx);\r\n\r\n // Check for arrow functions with expression body that returns JSX\r\n if (node.type === \"ArrowFunctionExpression\" && node.body && node.body.type !== \"BlockStatement\") {\r\n if (isJSXNode(node.body)) {\r\n fnCtx.returnsJsx = true;\r\n }\r\n }\r\n };\r\n\r\n const exitFunction = () => {\r\n const fnCtx = functionStack.pop();\r\n if (!fnCtx) return;\r\n\r\n // Only report if this is a React component (PascalCase name + returns JSX)\r\n if (!fnCtx.returnsJsx) return;\r\n if (!isComponentName(fnCtx.name)) return;\r\n\r\n // Report all Date instantiations in the top scope of this component\r\n for (const dateNode of fnCtx.dateInstantiations) {\r\n context.report({\r\n node: dateNode,\r\n message: `Avoid instantiating Date in the top scope of component '${fnCtx.name}'. Date instances change on every render. Move it inside an effect, event handler, or use useMemo/useCallback.`,\r\n });\r\n }\r\n };\r\n\r\n /** @param {ReturnStatementNode} node */\r\n const handleReturnStatement = (node) => {\r\n const fnCtx = currentFunction();\r\n if (!fnCtx) return;\r\n\r\n const argument = node.argument;\r\n if (!argument) return;\r\n\r\n if (isJSXNode(argument)) {\r\n fnCtx.returnsJsx = true;\r\n }\r\n };\r\n\r\n /** @param {NewExpressionNode} node */\r\n const handleNewExpression = (node) => {\r\n if (!isDateInstantiation(node)) return;\r\n\r\n const fnCtx = currentFunction();\r\n if (!fnCtx) return;\r\n\r\n // Record this Date instantiation - we'll check if it's in top scope when the function exits\r\n fnCtx.dateInstantiations.push(node);\r\n };\r\n\r\n return /** @type {import(\"oxlint\").VisitorWithHooks} */ ({\r\n FunctionDeclaration(node) {\r\n if (isFunctionLike(node)) enterFunction(node);\r\n },\r\n \"FunctionDeclaration:exit\": exitFunction,\r\n FunctionExpression(node) {\r\n if (isFunctionLike(node)) enterFunction(node);\r\n },\r\n \"FunctionExpression:exit\": exitFunction,\r\n ArrowFunctionExpression(node) {\r\n if (isFunctionLike(node)) enterFunction(node);\r\n },\r\n \"ArrowFunctionExpression:exit\": exitFunction,\r\n ReturnStatement(node) {\r\n if (node.type === \"ReturnStatement\") handleReturnStatement(node);\r\n },\r\n NewExpression(node) {\r\n if (node.type === \"NewExpression\") handleNewExpression(node);\r\n },\r\n });\r\n },\r\n});\r\n\r\nexport const noComponentDateInstantiationRule = rule;\r\n\r\nexport default {\r\n meta: { name: \"no-component-date-instantiation\" },\r\n rules: { \"no-component-date-instantiation\": rule },\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAM,sBAAsB,IAAI,IAAI;CAAC;CAAuB;CAAsB;CAA0B,CAAC;;;;;AAM7G,MAAM,UAAU,SAAS,QAAQ,QAAQ,OAAO,SAAS,YAAY,UAAU,KAAK;;;;;AAMpF,MAAM,kBAAkB,SAAS,OAAO,KAAK,IAAI,oBAAoB,IAAI,KAAK,KAAK;;;;;;AAOnF,MAAM,mBAAmB,SAAS,OAAO,SAAS,YAAY,SAAS,KAAK,KAAK;;;;;;AAOjF,MAAM,mBAAmB,SAAS;AAChC,KAAI,KAAK,SAAS,yBAAyB,KAAK,MAAM,KAAK,GAAG,SAAS,aACrE,QAAO,KAAK,GAAG;AAGjB,MAAK,KAAK,SAAS,wBAAwB,KAAK,SAAS,8BAA8B,KAAK,IAC1F;MAAI,KAAK,GAAG,SAAS,aAAc,QAAO,KAAK,GAAG;;CAGpD,MAAM,SAAS,KAAK;AACpB,KAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAE,QAAO;AAEvC,KAAI,OAAO,SAAS,qBAClB,QA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SAAS,2DAA2D,MAAM,KAAK;IAChF,CAAC;;;EAKN,MAAM,yBAAyB,SAAS;GACtC,MAAM,QAAQ,iBAAiB;AAC/B,OAAI,CAAC,MAAO;GAEZ,MAAM,WAAW,KAAK;AACtB,OAAI,CAAC,SAAU;AAEf,OAAI,UAAU,SAAS,CACrB,OAAM,aAAa;;;EAKvB,MAAM,uBAAuB,SAAS;AACpC,OAAI,CAAC,oBAAoB,KAAK,CAAE;GAEhC,MAAM,QAAQ,iBAAiB;AAC/B,OAAI,CAAC,MAAO;AAGZ,SAAM,mBAAmB,KAAK,KAAK;;AAGrC,SAAyD;GACvD,oBAAoB,MAAM;AACxB,QAAI,eAAe,KAAK,CAAE,eAAc,KAAK;;GAE/C,4BAA4B;GAC5B,mBAAmB,MAAM;AACvB,QAAI,eAAe,KAAK,CAAE,eAAc,KAAK;;GAE/C,2BAA2B;GAC3B,wBAAwB,MAAM;AAC5B,QAAI,eAAe,KAAK,CAAE,eAAc,KAAK;;GAE/C,gCAAgC;GAChC,gBAAgB,MAAM;AACpB,QAAI,KAAK,SAAS,kBAAmB,uBAAsB,KAAK;;GAElE,cAAc,MAAM;AAClB,QAAI,KAAK,SAAS,gBAAiB,qBAAoB,KAAK;;GAE/D;;CAEJ,CAAC;AAEF,MAAa,mCAAmC;AAEhD,8CAAe;CACb,MAAM,EAAE,MAAM,mCAAmC;CACjD,OAAO,EAAE,mCAAmC,MAAM;CACnD"}
@@ -0,0 +1,16 @@
1
+ import * as oxlint15 from "oxlint";
2
+
3
+ //#region src/oxlint-plugins/no-emoji.d.ts
4
+ declare const noEmojiRule: oxlint15.Rule;
5
+ declare namespace _default {
6
+ namespace meta {
7
+ let name: string;
8
+ }
9
+ let rules: {
10
+ "no-emoji": oxlint15.Rule;
11
+ };
12
+ }
13
+ type ESTNode = oxlint15.ESTree.Node;
14
+ //#endregion
15
+ export { ESTNode, _default as default, noEmojiRule };
16
+ //# sourceMappingURL=no-emoji.d.mts.map
@@ -0,0 +1,89 @@
1
+ import { defineRule } from "oxlint";
2
+
3
+ //#region src/oxlint-plugins/no-emoji.js
4
+ /** @typedef {import("oxlint").ESTree.Node} ESTNode */
5
+ /**
6
+ * Regex pattern to match emojis
7
+ * Covers most common emoji ranges in Unicode
8
+ */
9
+ const EMOJI_REGEX = /[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{1F000}-\u{1F02F}\u{1F0A0}-\u{1F0FF}\u{1F100}-\u{1F64F}\u{1F680}-\u{1F6FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{FE00}-\u{FE0F}\u{203C}\u{2049}\u{20E3}\u{2139}\u{2194}-\u{2199}\u{21A9}-\u{21AA}\u{231A}-\u{231B}\u{2328}\u{23CF}\u{23E9}-\u{23F3}\u{23F8}-\u{23FA}\u{24C2}\u{25AA}-\u{25AB}\u{25B6}\u{25C0}\u{25FB}-\u{25FE}\u{2600}-\u{2604}\u{260E}\u{2611}\u{2614}-\u{2615}\u{2618}\u{261D}\u{2620}\u{2622}-\u{2623}\u{2626}\u{262A}\u{262E}-\u{262F}\u{2638}-\u{263A}\u{2640}\u{2642}\u{2648}-\u{2653}\u{265F}-\u{2660}\u{2663}\u{2665}-\u{2666}\u{2668}\u{267B}\u{267E}-\u{267F}\u{2692}-\u{2697}\u{2699}\u{269B}-\u{269C}\u{26A0}-\u{26A1}\u{26A7}\u{26AA}-\u{26AB}\u{26B0}-\u{26B1}\u{26BD}-\u{26BE}\u{26C4}-\u{26C5}\u{26C8}\u{26CE}\u{26CF}\u{26D1}\u{26D3}-\u{26D4}\u{26E9}-\u{26EA}\u{26F0}-\u{26F5}\u{26F7}-\u{26FA}\u{26FD}\u{2702}\u{2705}\u{2708}-\u{270D}\u{270F}\u{2712}\u{2714}\u{2716}\u{271D}\u{2721}\u{2728}\u{2733}-\u{2734}\u{2744}\u{2747}\u{274C}\u{274E}\u{2753}-\u{2755}\u{2757}\u{2763}-\u{2764}\u{2795}-\u{2797}\u{27A1}\u{27B0}\u{27BF}\u{2934}-\u{2935}\u{2B05}-\u{2B07}\u{2B1B}-\u{2B1C}\u{2B50}\u{2B55}\u{3030}\u{303D}\u{3297}\u{3299}]/gu;
10
+ /**
11
+ * Find emojis in a string
12
+ * @param {string} text
13
+ * @returns {RegExpMatchArray | null}
14
+ */
15
+ const findEmojis = (text) => {
16
+ return text.match(EMOJI_REGEX);
17
+ };
18
+ /**
19
+ * Get a preview of the emoji found
20
+ * @param {string} text
21
+ * @returns {string}
22
+ */
23
+ const getEmojiPreview = (text) => {
24
+ const emojis = findEmojis(text);
25
+ if (!emojis || emojis.length === 0) return "";
26
+ const uniqueEmojis = [...new Set(emojis)];
27
+ const preview = uniqueEmojis.slice(0, 3).join(" ");
28
+ return uniqueEmojis.length > 3 ? `${preview} ...` : preview;
29
+ };
30
+ const rule = defineRule({
31
+ meta: {
32
+ type: "problem",
33
+ docs: {
34
+ description: "Disallow the use of emojis in code. Use icons from a component library instead.",
35
+ recommended: true
36
+ },
37
+ schema: []
38
+ },
39
+ createOnce(context) {
40
+ return {
41
+ StringLiteral(node) {
42
+ if (node.type !== "StringLiteral") return;
43
+ const emojis = findEmojis(node.value);
44
+ if (emojis && emojis.length > 0) {
45
+ const preview = getEmojiPreview(node.value);
46
+ context.report({
47
+ node,
48
+ message: `Emojis are not allowed in code. Found: ${preview}. Use icons from a component library instead.`
49
+ });
50
+ }
51
+ },
52
+ TemplateLiteral(node) {
53
+ if (node.type !== "TemplateLiteral") return;
54
+ for (const quasi of node.quasis) {
55
+ if (quasi.type !== "TemplateElement") continue;
56
+ const text = quasi.value.raw;
57
+ const emojis = findEmojis(text);
58
+ if (emojis && emojis.length > 0) {
59
+ const preview = getEmojiPreview(text);
60
+ context.report({
61
+ node: quasi,
62
+ message: `Emojis are not allowed in code. Found: ${preview}. Use icons from a component library instead.`
63
+ });
64
+ }
65
+ }
66
+ },
67
+ JSXText(node) {
68
+ if (node.type !== "JSXText") return;
69
+ const emojis = findEmojis(node.value);
70
+ if (emojis && emojis.length > 0) {
71
+ const preview = getEmojiPreview(node.value);
72
+ context.report({
73
+ node,
74
+ message: `Emojis are not allowed in code. Found: ${preview}. Use icons from a component library instead.`
75
+ });
76
+ }
77
+ }
78
+ };
79
+ }
80
+ });
81
+ const noEmojiRule = rule;
82
+ var no_emoji_default = {
83
+ meta: { name: "no-emoji" },
84
+ rules: { "no-emoji": rule }
85
+ };
86
+
87
+ //#endregion
88
+ export { no_emoji_default as default, noEmojiRule };
89
+ //# sourceMappingURL=no-emoji.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-emoji.mjs","names":[],"sources":["../../src/oxlint-plugins/no-emoji.js"],"sourcesContent":["import { defineRule } from \"oxlint\";\r\n\r\n/** @typedef {import(\"oxlint\").ESTree.Node} ESTNode */\r\n\r\n/**\r\n * Regex pattern to match emojis\r\n * Covers most common emoji ranges in Unicode\r\n */\r\nconst EMOJI_REGEX =\r\n /[\\u{1F300}-\\u{1F9FF}\\u{2600}-\\u{26FF}\\u{2700}-\\u{27BF}\\u{1F000}-\\u{1F02F}\\u{1F0A0}-\\u{1F0FF}\\u{1F100}-\\u{1F64F}\\u{1F680}-\\u{1F6FF}\\u{1F900}-\\u{1F9FF}\\u{1FA00}-\\u{1FA6F}\\u{1FA70}-\\u{1FAFF}\\u{FE00}-\\u{FE0F}\\u{203C}\\u{2049}\\u{20E3}\\u{2139}\\u{2194}-\\u{2199}\\u{21A9}-\\u{21AA}\\u{231A}-\\u{231B}\\u{2328}\\u{23CF}\\u{23E9}-\\u{23F3}\\u{23F8}-\\u{23FA}\\u{24C2}\\u{25AA}-\\u{25AB}\\u{25B6}\\u{25C0}\\u{25FB}-\\u{25FE}\\u{2600}-\\u{2604}\\u{260E}\\u{2611}\\u{2614}-\\u{2615}\\u{2618}\\u{261D}\\u{2620}\\u{2622}-\\u{2623}\\u{2626}\\u{262A}\\u{262E}-\\u{262F}\\u{2638}-\\u{263A}\\u{2640}\\u{2642}\\u{2648}-\\u{2653}\\u{265F}-\\u{2660}\\u{2663}\\u{2665}-\\u{2666}\\u{2668}\\u{267B}\\u{267E}-\\u{267F}\\u{2692}-\\u{2697}\\u{2699}\\u{269B}-\\u{269C}\\u{26A0}-\\u{26A1}\\u{26A7}\\u{26AA}-\\u{26AB}\\u{26B0}-\\u{26B1}\\u{26BD}-\\u{26BE}\\u{26C4}-\\u{26C5}\\u{26C8}\\u{26CE}\\u{26CF}\\u{26D1}\\u{26D3}-\\u{26D4}\\u{26E9}-\\u{26EA}\\u{26F0}-\\u{26F5}\\u{26F7}-\\u{26FA}\\u{26FD}\\u{2702}\\u{2705}\\u{2708}-\\u{270D}\\u{270F}\\u{2712}\\u{2714}\\u{2716}\\u{271D}\\u{2721}\\u{2728}\\u{2733}-\\u{2734}\\u{2744}\\u{2747}\\u{274C}\\u{274E}\\u{2753}-\\u{2755}\\u{2757}\\u{2763}-\\u{2764}\\u{2795}-\\u{2797}\\u{27A1}\\u{27B0}\\u{27BF}\\u{2934}-\\u{2935}\\u{2B05}-\\u{2B07}\\u{2B1B}-\\u{2B1C}\\u{2B50}\\u{2B55}\\u{3030}\\u{303D}\\u{3297}\\u{3299}]/gu;\r\n\r\n/**\r\n * Find emojis in a string\r\n * @param {string} text\r\n * @returns {RegExpMatchArray | null}\r\n */\r\nconst findEmojis = (text) => {\r\n return text.match(EMOJI_REGEX);\r\n};\r\n\r\n/**\r\n * Get a preview of the emoji found\r\n * @param {string} text\r\n * @returns {string}\r\n */\r\nconst getEmojiPreview = (text) => {\r\n const emojis = findEmojis(text);\r\n if (!emojis || emojis.length === 0) return \"\";\r\n\r\n const uniqueEmojis = [...new Set(emojis)];\r\n const preview = uniqueEmojis.slice(0, 3).join(\" \");\r\n\r\n return uniqueEmojis.length > 3 ? `${preview} ...` : preview;\r\n};\r\n\r\nconst rule = defineRule({\r\n meta: {\r\n type: \"problem\",\r\n docs: {\r\n description: \"Disallow the use of emojis in code. Use icons from a component library instead.\",\r\n recommended: true,\r\n },\r\n schema: [],\r\n },\r\n createOnce(context) {\r\n return /** @type {import(\"oxlint\").VisitorWithHooks} */ ({\r\n /**\r\n * Check string literals\r\n * @param {ESTNode} node\r\n */\r\n StringLiteral(node) {\r\n if (node.type !== \"StringLiteral\") return;\r\n\r\n const emojis = findEmojis(node.value);\r\n if (emojis && emojis.length > 0) {\r\n const preview = getEmojiPreview(node.value);\r\n context.report({\r\n node,\r\n message: `Emojis are not allowed in code. Found: ${preview}. Use icons from a component library instead.`,\r\n });\r\n }\r\n },\r\n\r\n /**\r\n * Check template literals\r\n * @param {ESTNode} node\r\n */\r\n TemplateLiteral(node) {\r\n if (node.type !== \"TemplateLiteral\") return;\r\n\r\n // Check each quasi (template string part)\r\n for (const quasi of node.quasis) {\r\n if (quasi.type !== \"TemplateElement\") continue;\r\n\r\n const text = quasi.value.raw;\r\n const emojis = findEmojis(text);\r\n\r\n if (emojis && emojis.length > 0) {\r\n const preview = getEmojiPreview(text);\r\n context.report({\r\n node: quasi,\r\n message: `Emojis are not allowed in code. Found: ${preview}. Use icons from a component library instead.`,\r\n });\r\n }\r\n }\r\n },\r\n\r\n /**\r\n * Check JSX text\r\n * @param {ESTNode} node\r\n */\r\n JSXText(node) {\r\n if (node.type !== \"JSXText\") return;\r\n\r\n const emojis = findEmojis(node.value);\r\n if (emojis && emojis.length > 0) {\r\n const preview = getEmojiPreview(node.value);\r\n context.report({\r\n node,\r\n message: `Emojis are not allowed in code. Found: ${preview}. Use icons from a component library instead.`,\r\n });\r\n }\r\n },\r\n });\r\n },\r\n});\r\n\r\nexport const noEmojiRule = rule;\r\n\r\nexport default {\r\n meta: { name: \"no-emoji\" },\r\n rules: { \"no-emoji\": rule },\r\n};\r\n"],"mappings":";;;;;;;;AAQA,MAAM,cACJ;;;;;;AAOF,MAAM,cAAc,SAAS;AAC3B,QAAO,KAAK,MAAM,YAAY;;;;;;;AAQhC,MAAM,mBAAmB,SAAS;CAChC,MAAM,SAAS,WAAW,K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AY;CAC1B,OAAO,EAAE,YAAY,MAAM;CAC5B"}
@@ -0,0 +1,16 @@
1
+ import * as oxlint18 from "oxlint";
2
+
3
+ //#region src/oxlint-plugins/no-finally.d.ts
4
+ declare const noFinallyRule: oxlint18.Rule;
5
+ declare namespace _default {
6
+ namespace meta {
7
+ let name: string;
8
+ }
9
+ let rules: {
10
+ "no-finally": oxlint18.Rule;
11
+ };
12
+ }
13
+ type ESTNode = oxlint18.ESTree.Node;
14
+ //#endregion
15
+ export { ESTNode, _default as default, noFinallyRule };
16
+ //# sourceMappingURL=no-finally.d.mts.map
@@ -0,0 +1,32 @@
1
+ import { defineRule } from "oxlint";
2
+
3
+ //#region src/oxlint-plugins/no-finally.js
4
+ /** @typedef {import("oxlint").ESTree.Node} ESTNode */
5
+ const rule = defineRule({
6
+ meta: {
7
+ type: "problem",
8
+ docs: {
9
+ description: "Disallow 'finally' blocks in try/catch/finally statements",
10
+ recommended: true
11
+ },
12
+ schema: []
13
+ },
14
+ createOnce(context) {
15
+ return { TryStatement(node) {
16
+ if (node.type !== "TryStatement") return;
17
+ if (node.finalizer) context.report({
18
+ node: node.finalizer,
19
+ message: "Use of 'finally' blocks is disallowed. Handle cleanup explicitly in try/catch blocks instead."
20
+ });
21
+ } };
22
+ }
23
+ });
24
+ const noFinallyRule = rule;
25
+ var no_finally_default = {
26
+ meta: { name: "no-finally" },
27
+ rules: { "no-finally": rule }
28
+ };
29
+
30
+ //#endregion
31
+ export { no_finally_default as default, noFinallyRule };
32
+ //# sourceMappingURL=no-finally.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-finally.mjs","names":[],"sources":["../../src/oxlint-plugins/no-finally.js"],"sourcesContent":["import { defineRule } from \"oxlint\";\r\n\r\n/** @typedef {import(\"oxlint\").ESTree.Node} ESTNode */\r\n\r\nconst rule = defineRule({\r\n meta: {\r\n type: \"problem\",\r\n docs: {\r\n description: \"Disallow 'finally' blocks in try/catch/finally statements\",\r\n recommended: true,\r\n },\r\n schema: [],\r\n },\r\n createOnce(context) {\r\n return /** @type {import(\"oxlint\").VisitorWithHooks} */ ({\r\n /**\r\n * @param {ESTNode} node\r\n */\r\n TryStatement(node) {\r\n if (node.type !== \"TryStatement\") return;\r\n\r\n if (node.finalizer) {\r\n context.report({\r\n node: node.finalizer,\r\n message: \"Use of 'finally' blocks is disallowed. Handle cleanup explicitly in try/catch blocks instead.\",\r\n });\r\n }\r\n },\r\n });\r\n },\r\n});\r\n\r\nexport const noFinallyRule = rule;\r\n\r\nexport default {\r\n meta: { name: \"no-finally\" },\r\n rules: { \"no-finally\": rule },\r\n};\r\n"],"mappings":";;;;AAIA,MAAM,OAAO,WAAW;CACtB,MAAM;EACJ,MAAM;EACN,MAAM;GACJ,aAAa;GACb,aAAa;GACd;EACD,QAAQ,EAAE;EACX;CACD,WAAW,SAAS;AAClB,SAAyD,EAIvD,aAAa,MAAM;AACjB,OAAI,KAAK,SAAS,eAAgB;AAElC,OAAI,KAAK,UACP,SAAQ,OAAO;IACb,MAAM,KAAK;IACX,SAAS;IACV,CAAC;KAGP;;CAEJ,CAAC;AAEF,MAAa,gBAAgB;AAE7B,yBAAe;CACb,MAAM,EAAE,MAAM,cAAc;CAC5B,OAAO,EAAE,cAAc,MAAM;CAC9B"}
@@ -0,0 +1,44 @@
1
+ import * as oxlint32 from "oxlint";
2
+
3
+ //#region src/oxlint-plugins/no-inline-components.d.ts
4
+ declare function isComponentName(name: unknown): name is string;
5
+ declare function isHookName(name: unknown): name is string;
6
+ declare function getEnclosingFunction(node: ESTNode | null | undefined): FunctionLikeNode | null;
7
+ declare function getFunctionName(node: FunctionLikeNode): string;
8
+ declare const noInlineComponentsRule: oxlint32.Rule;
9
+ declare namespace _default {
10
+ namespace meta {
11
+ let name: string;
12
+ }
13
+ let rules: {
14
+ "no-inline-components": oxlint32.Rule;
15
+ };
16
+ }
17
+ type RuleContext = oxlint32.Context;
18
+ type ESTNode = oxlint32.ESTree.Node;
19
+ type ESTExpression = oxlint32.ESTree.Expression;
20
+ type ESTPattern = oxlint32.ESTree.Pattern;
21
+ type ReturnStatementNode = oxlint32.ESTree.ReturnStatement;
22
+ type VariableDeclaratorNode = oxlint32.ESTree.VariableDeclarator;
23
+ type AssignmentExpressionNode = oxlint32.ESTree.AssignmentExpression;
24
+ type FunctionLikeNode = oxlint32.ESTree.Function | oxlint32.ESTree.ArrowFunctionExpression;
25
+ type RecordedAssignment = {
26
+ node: ESTExpression;
27
+ names: string[];
28
+ };
29
+ type NestedFunctionRecord = {
30
+ node: FunctionLikeNode;
31
+ name: string;
32
+ };
33
+ type FunctionContext = {
34
+ node: FunctionLikeNode;
35
+ parent: FunctionContext | null;
36
+ name: string;
37
+ returnsJsx: boolean;
38
+ jsxBindingNames: Set<string>;
39
+ jsxAssignments: RecordedAssignment[];
40
+ nestedJsxChildren: NestedFunctionRecord[];
41
+ };
42
+ //#endregion
43
+ export { AssignmentExpressionNode, ESTExpression, ESTNode, ESTPattern, FunctionContext, FunctionLikeNode, NestedFunctionRecord, RecordedAssignment, ReturnStatementNode, RuleContext, VariableDeclaratorNode, _default as default, getEnclosingFunction, getFunctionName, isComponentName, isHookName, noInlineComponentsRule };
44
+ //# sourceMappingURL=no-inline-components.d.mts.map