@esphome/compose-eslint 0.2.0 → 0.3.0
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/dist/index.mjs +54 -2
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -176,6 +176,53 @@ var jsx_children_intents_default = createRule({
|
|
|
176
176
|
}
|
|
177
177
|
});
|
|
178
178
|
|
|
179
|
+
// src/rules/no-nested-functions.ts
|
|
180
|
+
import { ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
|
|
181
|
+
var createRule2 = ESLintUtils2.RuleCreator(
|
|
182
|
+
(name) => `https://github.com/xmlguy74/espcompose/blob/main/docs/rules/${name}.md`
|
|
183
|
+
);
|
|
184
|
+
var no_nested_functions_default = createRule2({
|
|
185
|
+
name: "no-nested-functions",
|
|
186
|
+
meta: {
|
|
187
|
+
type: "problem",
|
|
188
|
+
docs: {
|
|
189
|
+
description: "Disallow function declarations nested inside other functions. Only top-level function declarations are compiled into ESPHome scripts."
|
|
190
|
+
},
|
|
191
|
+
messages: {
|
|
192
|
+
nestedFunction: `Function declaration "{{ name }}" is nested inside another function. Move it to the module's top level so the compiler can transform it into an ESPHome script, or use an inline arrow function in the trigger prop.`
|
|
193
|
+
},
|
|
194
|
+
schema: []
|
|
195
|
+
},
|
|
196
|
+
defaultOptions: [],
|
|
197
|
+
create(context) {
|
|
198
|
+
let functionDepth = 0;
|
|
199
|
+
function enterFunction() {
|
|
200
|
+
functionDepth++;
|
|
201
|
+
}
|
|
202
|
+
function exitFunction() {
|
|
203
|
+
functionDepth--;
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
// Track all function-like boundaries (declarations, expressions, arrows)
|
|
207
|
+
FunctionDeclaration(node) {
|
|
208
|
+
if (functionDepth > 0 && node.id) {
|
|
209
|
+
context.report({
|
|
210
|
+
node,
|
|
211
|
+
messageId: "nestedFunction",
|
|
212
|
+
data: { name: node.id.name }
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
enterFunction();
|
|
216
|
+
},
|
|
217
|
+
"FunctionDeclaration:exit": exitFunction,
|
|
218
|
+
FunctionExpression: enterFunction,
|
|
219
|
+
"FunctionExpression:exit": exitFunction,
|
|
220
|
+
ArrowFunctionExpression: enterFunction,
|
|
221
|
+
"ArrowFunctionExpression:exit": exitFunction
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
179
226
|
// src/index.ts
|
|
180
227
|
var plugin = {
|
|
181
228
|
meta: {
|
|
@@ -184,7 +231,9 @@ var plugin = {
|
|
|
184
231
|
},
|
|
185
232
|
rules: {
|
|
186
233
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
187
|
-
"jsx-children-intents": jsx_children_intents_default
|
|
234
|
+
"jsx-children-intents": jsx_children_intents_default,
|
|
235
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
236
|
+
"no-nested-functions": no_nested_functions_default
|
|
188
237
|
}
|
|
189
238
|
};
|
|
190
239
|
var recommended = [
|
|
@@ -209,7 +258,10 @@ var recommended = [
|
|
|
209
258
|
varsIgnorePattern: "^ESPCompose$"
|
|
210
259
|
}],
|
|
211
260
|
// Enforce valid parent-child component nesting based on declared intents.
|
|
212
|
-
"@esphome/compose-eslint/jsx-children-intents": "error"
|
|
261
|
+
"@esphome/compose-eslint/jsx-children-intents": "error",
|
|
262
|
+
// Prevent nested function declarations — only top-level functions become
|
|
263
|
+
// ESPHome scripts; nested ones are silently ignored by the compiler.
|
|
264
|
+
"@esphome/compose-eslint/no-nested-functions": "error"
|
|
213
265
|
}
|
|
214
266
|
},
|
|
215
267
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esphome/compose-eslint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "ESLint plugin with custom rules for ESPHome Compose projects",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -35,17 +35,17 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@typescript-eslint/utils": "^8.0.0",
|
|
38
|
-
"typescript-eslint": "^8.
|
|
39
|
-
"@esphome/compose": "0.
|
|
38
|
+
"typescript-eslint": "^8.57.2",
|
|
39
|
+
"@esphome/compose": "0.3.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"eslint": ">=9.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@typescript-eslint/rule-tester": "^8.0.0",
|
|
46
|
-
"eslint": "^9.
|
|
46
|
+
"eslint": "^9.39.4",
|
|
47
47
|
"tsup": "^8.0.0",
|
|
48
|
-
"typescript": "^5.
|
|
48
|
+
"typescript": "^5.9.3",
|
|
49
49
|
"vitest": "^2.0.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|