@dloizides/frontend-devtools 2.1.1 → 2.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/CHANGELOG.md +185 -170
- package/README.md +9 -0
- package/dist/eslint/index.d.mts +4 -1
- package/dist/eslint/index.d.ts +4 -1
- package/dist/eslint/index.js +161 -25
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +160 -26
- package/dist/eslint/index.mjs.map +1 -1
- package/dist/lighthouse/index.d.mts +41 -0
- package/dist/lighthouse/index.d.ts +41 -0
- package/dist/lighthouse/index.js +39 -0
- package/dist/lighthouse/index.js.map +1 -0
- package/dist/lighthouse/index.mjs +34 -0
- package/dist/lighthouse/index.mjs.map +1 -0
- package/package.json +12 -2
package/dist/eslint/index.js
CHANGED
|
@@ -965,6 +965,132 @@ var enum_file_isolation_default = {
|
|
|
965
965
|
}
|
|
966
966
|
};
|
|
967
967
|
|
|
968
|
+
// src/rules/explicit-initial-focus.js
|
|
969
|
+
var DEFAULT_MIN_CONTROLS = 2;
|
|
970
|
+
var DEFAULT_DIALOG_PATTERN = "(Dialog|Modal)$";
|
|
971
|
+
var MENU_DEFAULT_IDENTIFIER = "MENU_DEFAULT_ATTR";
|
|
972
|
+
var MENU_DEFAULT_TEXT = "data-menu-default";
|
|
973
|
+
var MENU_DEFAULT_DATASET_KEY = "menuDefault";
|
|
974
|
+
var FOCUS_METHOD = "focus";
|
|
975
|
+
var FOCUS_PROP_NAMES = /* @__PURE__ */ new Set(["autoFocus", "initialFocus", "initialFocusRef", MENU_DEFAULT_TEXT]);
|
|
976
|
+
var FOCUS_OPTION_KEYS = /* @__PURE__ */ new Set(["initialFocus", "initialFocusRef", "autoFocus"]);
|
|
977
|
+
var DIALOG_ROLE_PROPS = /* @__PURE__ */ new Set(["role", "accessibilityRole"]);
|
|
978
|
+
var BUTTON_TAG = /<button\b/gi;
|
|
979
|
+
function propertyName(member) {
|
|
980
|
+
if (!member.computed && member.property.type === "Identifier") return member.property.name;
|
|
981
|
+
const prop = member.property;
|
|
982
|
+
return prop.type === "Literal" && typeof prop.value === "string" ? prop.value : void 0;
|
|
983
|
+
}
|
|
984
|
+
function keyName(key) {
|
|
985
|
+
if (key.type === "Identifier") return key.name;
|
|
986
|
+
return key.type === "Literal" && typeof key.value === "string" ? key.value : void 0;
|
|
987
|
+
}
|
|
988
|
+
function jsxName(name) {
|
|
989
|
+
if (name.type === "JSXIdentifier") return name.name;
|
|
990
|
+
if (name.type === "JSXMemberExpression") return name.property.name;
|
|
991
|
+
if (name.type === "JSXNamespacedName") return `${name.namespace.name}:${name.name.name}`;
|
|
992
|
+
return void 0;
|
|
993
|
+
}
|
|
994
|
+
function attributeText(attr) {
|
|
995
|
+
const value = attr.value;
|
|
996
|
+
if (!value) return void 0;
|
|
997
|
+
if (value.type === "Literal" && typeof value.value === "string") return value.value;
|
|
998
|
+
const inner = value.type === "JSXExpressionContainer" ? value.expression : void 0;
|
|
999
|
+
return inner && inner.type === "Literal" && typeof inner.value === "string" ? inner.value : void 0;
|
|
1000
|
+
}
|
|
1001
|
+
function isDialogRole(attr) {
|
|
1002
|
+
if (attr.type !== "JSXAttribute" || !DIALOG_ROLE_PROPS.has(jsxName(attr.name) ?? "")) return false;
|
|
1003
|
+
return attributeText(attr) === "dialog";
|
|
1004
|
+
}
|
|
1005
|
+
function readOptions(context) {
|
|
1006
|
+
const options = context.options[0] ?? {};
|
|
1007
|
+
return {
|
|
1008
|
+
minControls: options.minControls ?? DEFAULT_MIN_CONTROLS,
|
|
1009
|
+
dialogPattern: new RegExp(options.dialogPattern ?? DEFAULT_DIALOG_PATTERN),
|
|
1010
|
+
selfFocusing: new Set(options.selfFocusing ?? [])
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
var rule = {
|
|
1014
|
+
meta: {
|
|
1015
|
+
type: "problem",
|
|
1016
|
+
docs: {
|
|
1017
|
+
description: "FOCUS-1: a game menu or a dialog names the control focused on open (data-menu-default, autoFocus, initialFocus or a ref focus), never the first element by default."
|
|
1018
|
+
},
|
|
1019
|
+
schema: [
|
|
1020
|
+
{
|
|
1021
|
+
type: "object",
|
|
1022
|
+
properties: {
|
|
1023
|
+
minControls: { type: "integer", minimum: 1 },
|
|
1024
|
+
dialogPattern: { type: "string" },
|
|
1025
|
+
selfFocusing: { type: "array", items: { type: "string" } }
|
|
1026
|
+
},
|
|
1027
|
+
additionalProperties: false
|
|
1028
|
+
}
|
|
1029
|
+
],
|
|
1030
|
+
messages: {
|
|
1031
|
+
missingMenuDefault: "This file builds a menu of {{count}} buttons but names no initial focus. Mark the primary next step with MENU_DEFAULT_ATTR (data-menu-default) or pass initialFocus; never a destructive action.",
|
|
1032
|
+
missingDialogFocus: "'{{name}}' opens a dialog but the file names no initial focus. Give the primary next step autoFocus, an initialFocus prop or a ref focus on mount; never a destructive action."
|
|
1033
|
+
}
|
|
1034
|
+
},
|
|
1035
|
+
create(context) {
|
|
1036
|
+
const options = readOptions(context);
|
|
1037
|
+
let named = false;
|
|
1038
|
+
let controlCount = 0;
|
|
1039
|
+
let firstControl;
|
|
1040
|
+
const dialogs = [];
|
|
1041
|
+
const countControls = (node, text) => {
|
|
1042
|
+
const found = (text.match(BUTTON_TAG) ?? []).length;
|
|
1043
|
+
if (found === 0) return;
|
|
1044
|
+
controlCount += found;
|
|
1045
|
+
firstControl ?? (firstControl = node);
|
|
1046
|
+
};
|
|
1047
|
+
const scanText = (node, text) => {
|
|
1048
|
+
if (text.includes(MENU_DEFAULT_TEXT)) named = true;
|
|
1049
|
+
countControls(node, text);
|
|
1050
|
+
};
|
|
1051
|
+
return {
|
|
1052
|
+
Identifier(node) {
|
|
1053
|
+
if (node.name === MENU_DEFAULT_IDENTIFIER) named = true;
|
|
1054
|
+
},
|
|
1055
|
+
Literal(node) {
|
|
1056
|
+
if (typeof node.value === "string" && node.parent.type !== "JSXAttribute") scanText(node, node.value);
|
|
1057
|
+
},
|
|
1058
|
+
TemplateElement(node) {
|
|
1059
|
+
scanText(node, node.value.cooked ?? node.value.raw);
|
|
1060
|
+
},
|
|
1061
|
+
MemberExpression(node) {
|
|
1062
|
+
if (propertyName(node) === MENU_DEFAULT_DATASET_KEY) named = true;
|
|
1063
|
+
},
|
|
1064
|
+
Property(node) {
|
|
1065
|
+
if (FOCUS_OPTION_KEYS.has(keyName(node.key) ?? "")) named = true;
|
|
1066
|
+
},
|
|
1067
|
+
CallExpression(node) {
|
|
1068
|
+
if (node.callee.type !== "MemberExpression") return;
|
|
1069
|
+
const name = propertyName(node.callee);
|
|
1070
|
+
if (name === FOCUS_METHOD) named = true;
|
|
1071
|
+
const tag = node.arguments[0];
|
|
1072
|
+
const isButton = name === "createElement" && tag && tag.type === "Literal" && String(tag.value).toLowerCase() === "button";
|
|
1073
|
+
if (isButton) countControls(node, "<button");
|
|
1074
|
+
},
|
|
1075
|
+
JSXAttribute(node) {
|
|
1076
|
+
if (FOCUS_PROP_NAMES.has(jsxName(node.name) ?? "")) named = true;
|
|
1077
|
+
},
|
|
1078
|
+
JSXOpeningElement(node) {
|
|
1079
|
+
const name = jsxName(node.name) ?? "";
|
|
1080
|
+
if (options.selfFocusing.has(name)) return;
|
|
1081
|
+
const isDialog = options.dialogPattern.test(name) || node.attributes.some(isDialogRole);
|
|
1082
|
+
if (isDialog) dialogs.push({ node, name });
|
|
1083
|
+
},
|
|
1084
|
+
"Program:exit"() {
|
|
1085
|
+
if (named) return;
|
|
1086
|
+
if (controlCount >= options.minControls) context.report({ node: firstControl, messageId: "missingMenuDefault", data: { count: String(controlCount) } });
|
|
1087
|
+
dialogs.forEach(({ node, name }) => context.report({ node, messageId: "missingDialogFocus", data: { name } }));
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
var explicit_initial_focus_default = { rules: { "explicit-initial-focus": rule } };
|
|
1093
|
+
|
|
968
1094
|
// src/rules/game-menu-focusable.js
|
|
969
1095
|
var POINTER_EVENTS = /* @__PURE__ */ new Set(["click", "pointerdown", "pointerup"]);
|
|
970
1096
|
var NON_FOCUSABLE_TAGS = /* @__PURE__ */ new Set(["div", "span", "li", "img"]);
|
|
@@ -999,14 +1125,14 @@ function stringValue(node) {
|
|
|
999
1125
|
if (target.type === "TemplateLiteral" && target.expressions.length === 0) return target.quasis[0].value.cooked;
|
|
1000
1126
|
return void 0;
|
|
1001
1127
|
}
|
|
1002
|
-
function
|
|
1128
|
+
function propertyName2(member) {
|
|
1003
1129
|
if (member.computed) return stringValue(member.property);
|
|
1004
1130
|
return member.property.type === "Identifier" ? member.property.name : void 0;
|
|
1005
1131
|
}
|
|
1006
1132
|
function createdTag(init) {
|
|
1007
1133
|
const call = unwrap(init);
|
|
1008
1134
|
if (!call || call.type !== "CallExpression") return void 0;
|
|
1009
|
-
if (call.callee.type !== "MemberExpression" ||
|
|
1135
|
+
if (call.callee.type !== "MemberExpression" || propertyName2(call.callee) !== "createElement") return void 0;
|
|
1010
1136
|
const tag = stringValue(call.arguments[0]);
|
|
1011
1137
|
return tag === void 0 ? void 0 : tag.toLowerCase();
|
|
1012
1138
|
}
|
|
@@ -1018,7 +1144,7 @@ function nonFocusableTag(variable) {
|
|
|
1018
1144
|
function setsFocusAttribute(reference) {
|
|
1019
1145
|
const member = reference.identifier.parent;
|
|
1020
1146
|
if (!member || member.type !== "MemberExpression" || member.object !== reference.identifier) return false;
|
|
1021
|
-
const name =
|
|
1147
|
+
const name = propertyName2(member);
|
|
1022
1148
|
const outer = member.parent;
|
|
1023
1149
|
if (FOCUS_PROPERTIES.has(name ?? "")) return outer.type === "AssignmentExpression" && outer.left === member;
|
|
1024
1150
|
if (name !== "setAttribute" || outer.type !== "CallExpression" || outer.callee !== member) return false;
|
|
@@ -1047,7 +1173,7 @@ function stopPropagationCalls(fn) {
|
|
|
1047
1173
|
const visit = (node) => {
|
|
1048
1174
|
if (!node || typeof node.type !== "string") return;
|
|
1049
1175
|
if (node !== fn && node.type.includes("Function")) return;
|
|
1050
|
-
const isStop = node.type === "CallExpression" && node.callee.type === "MemberExpression" &&
|
|
1176
|
+
const isStop = node.type === "CallExpression" && node.callee.type === "MemberExpression" && propertyName2(node.callee) === "stopPropagation";
|
|
1051
1177
|
if (isStop) found.push(node);
|
|
1052
1178
|
for (const key of Object.keys(node)) {
|
|
1053
1179
|
if (key === "parent") continue;
|
|
@@ -1059,7 +1185,7 @@ function stopPropagationCalls(fn) {
|
|
|
1059
1185
|
visit(fn.body);
|
|
1060
1186
|
return found;
|
|
1061
1187
|
}
|
|
1062
|
-
var
|
|
1188
|
+
var rule2 = {
|
|
1063
1189
|
meta: {
|
|
1064
1190
|
type: "problem",
|
|
1065
1191
|
docs: {
|
|
@@ -1084,28 +1210,28 @@ var rule = {
|
|
|
1084
1210
|
};
|
|
1085
1211
|
return {
|
|
1086
1212
|
CallExpression(node) {
|
|
1087
|
-
if (node.callee.type !== "MemberExpression" ||
|
|
1213
|
+
if (node.callee.type !== "MemberExpression" || propertyName2(node.callee) !== "addEventListener") return;
|
|
1088
1214
|
const event = stringValue(node.arguments[0]);
|
|
1089
1215
|
if (event === KEYDOWN) reportKeydown(node, node.arguments[1]);
|
|
1090
1216
|
else if (POINTER_EVENTS.has(event ?? "")) reportPointerOnly(node, node.callee.object, event);
|
|
1091
1217
|
},
|
|
1092
1218
|
AssignmentExpression(node) {
|
|
1093
1219
|
if (node.left.type !== "MemberExpression") return;
|
|
1094
|
-
const name =
|
|
1220
|
+
const name = propertyName2(node.left);
|
|
1095
1221
|
if (name === "onclick") reportPointerOnly(node, node.left.object, "onclick");
|
|
1096
1222
|
else if (name === "onkeydown") reportKeydown(node, node.right);
|
|
1097
1223
|
}
|
|
1098
1224
|
};
|
|
1099
1225
|
}
|
|
1100
1226
|
};
|
|
1101
|
-
var game_menu_focusable_default = { rules: { "game-menu-focusable":
|
|
1227
|
+
var game_menu_focusable_default = { rules: { "game-menu-focusable": rule2 } };
|
|
1102
1228
|
|
|
1103
1229
|
// src/rules/i18n-interpolation.js
|
|
1104
1230
|
var DOUBLE_BRACE_REGEX = /\{\{(\w+)\}\}/g;
|
|
1105
1231
|
var SINGLE_BRACE_REGEX = /(?<!\{)\{(\w+)\}(?!\})/g;
|
|
1106
1232
|
var ALLOWED_NAMES = /* @__PURE__ */ new Set(["p1", "p2", "p3"]);
|
|
1107
1233
|
var MAX_POSITIONAL_PARAMS = 3;
|
|
1108
|
-
var
|
|
1234
|
+
var rule3 = {
|
|
1109
1235
|
meta: {
|
|
1110
1236
|
type: "problem",
|
|
1111
1237
|
docs: {
|
|
@@ -1224,7 +1350,7 @@ var rule2 = {
|
|
|
1224
1350
|
};
|
|
1225
1351
|
var i18n_interpolation_default = {
|
|
1226
1352
|
rules: {
|
|
1227
|
-
"i18n-interpolation":
|
|
1353
|
+
"i18n-interpolation": rule3
|
|
1228
1354
|
}
|
|
1229
1355
|
};
|
|
1230
1356
|
|
|
@@ -1246,7 +1372,7 @@ var I18NEXT_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
1246
1372
|
"formatParams",
|
|
1247
1373
|
"missingInterpolationHandler"
|
|
1248
1374
|
]);
|
|
1249
|
-
var
|
|
1375
|
+
var rule4 = {
|
|
1250
1376
|
meta: {
|
|
1251
1377
|
type: "problem",
|
|
1252
1378
|
docs: {
|
|
@@ -1271,14 +1397,14 @@ var rule3 = {
|
|
|
1271
1397
|
const properties = optionsArg.properties;
|
|
1272
1398
|
for (const prop of properties) {
|
|
1273
1399
|
if (prop.type === "SpreadElement") continue;
|
|
1274
|
-
const
|
|
1275
|
-
if (
|
|
1276
|
-
if (I18NEXT_CONFIG_KEYS.has(
|
|
1277
|
-
if (!ALLOWED_PARAM_NAMES.has(
|
|
1400
|
+
const keyName2 = prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "Literal" ? String(prop.key.value) : null;
|
|
1401
|
+
if (keyName2 === null) continue;
|
|
1402
|
+
if (I18NEXT_CONFIG_KEYS.has(keyName2)) continue;
|
|
1403
|
+
if (!ALLOWED_PARAM_NAMES.has(keyName2))
|
|
1278
1404
|
context.report({
|
|
1279
1405
|
node: prop,
|
|
1280
1406
|
messageId: "nonStandardParam",
|
|
1281
|
-
data: { paramName:
|
|
1407
|
+
data: { paramName: keyName2 }
|
|
1282
1408
|
});
|
|
1283
1409
|
}
|
|
1284
1410
|
}
|
|
@@ -1287,7 +1413,7 @@ var rule3 = {
|
|
|
1287
1413
|
};
|
|
1288
1414
|
var i18n_param_names_default = {
|
|
1289
1415
|
rules: {
|
|
1290
|
-
"i18n-param-names":
|
|
1416
|
+
"i18n-param-names": rule4
|
|
1291
1417
|
}
|
|
1292
1418
|
};
|
|
1293
1419
|
|
|
@@ -2343,7 +2469,7 @@ function isQueryKeyProperty(node) {
|
|
|
2343
2469
|
if (node.key.type === "Identifier") return node.key.name === QUERY_KEY;
|
|
2344
2470
|
return node.key.type === "Literal" && node.key.value === QUERY_KEY;
|
|
2345
2471
|
}
|
|
2346
|
-
var
|
|
2472
|
+
var rule5 = {
|
|
2347
2473
|
meta: {
|
|
2348
2474
|
type: "suggestion",
|
|
2349
2475
|
docs: {
|
|
@@ -2374,7 +2500,7 @@ var rule4 = {
|
|
|
2374
2500
|
};
|
|
2375
2501
|
}
|
|
2376
2502
|
};
|
|
2377
|
-
var query_key_factory_default = { rules: { "query-key-factory":
|
|
2503
|
+
var query_key_factory_default = { rules: { "query-key-factory": rule5 } };
|
|
2378
2504
|
|
|
2379
2505
|
// src/rules/require-stable-hook-args.js
|
|
2380
2506
|
var STABLE_INIT_CALLS = /* @__PURE__ */ new Set([
|
|
@@ -3045,6 +3171,7 @@ var ruleModules = [
|
|
|
3045
3171
|
enforce_route_preload_default,
|
|
3046
3172
|
enforce_test_colocation_default,
|
|
3047
3173
|
enum_file_isolation_default,
|
|
3174
|
+
explicit_initial_focus_default,
|
|
3048
3175
|
game_menu_focusable_default,
|
|
3049
3176
|
i18n_interpolation_default,
|
|
3050
3177
|
i18n_param_names_default,
|
|
@@ -3068,11 +3195,11 @@ var ruleModules = [
|
|
|
3068
3195
|
function mergeRules(modules) {
|
|
3069
3196
|
const merged = {};
|
|
3070
3197
|
for (const mod of modules) {
|
|
3071
|
-
for (const [name,
|
|
3198
|
+
for (const [name, rule6] of Object.entries(mod.rules)) {
|
|
3072
3199
|
if (merged[name] !== void 0) {
|
|
3073
3200
|
throw new Error(`Duplicate ESLint rule name: "${name}"`);
|
|
3074
3201
|
}
|
|
3075
|
-
merged[name] =
|
|
3202
|
+
merged[name] = rule6;
|
|
3076
3203
|
}
|
|
3077
3204
|
}
|
|
3078
3205
|
return merged;
|
|
@@ -3088,15 +3215,15 @@ var ruleNames = Object.keys(plugin.rules).sort();
|
|
|
3088
3215
|
var legacyPlugins = buildLegacyPlugins();
|
|
3089
3216
|
function buildLegacyPlugins() {
|
|
3090
3217
|
const out = {};
|
|
3091
|
-
for (const [name,
|
|
3092
|
-
out[name] = oneRulePlugin(name,
|
|
3218
|
+
for (const [name, rule6] of Object.entries(rules)) {
|
|
3219
|
+
out[name] = oneRulePlugin(name, rule6);
|
|
3093
3220
|
}
|
|
3094
3221
|
return out;
|
|
3095
3222
|
}
|
|
3096
|
-
function oneRulePlugin(name,
|
|
3223
|
+
function oneRulePlugin(name, rule6) {
|
|
3097
3224
|
return {
|
|
3098
3225
|
meta: { name, version: "1.0.0" },
|
|
3099
|
-
rules: { [name]:
|
|
3226
|
+
rules: { [name]: rule6 }
|
|
3100
3227
|
};
|
|
3101
3228
|
}
|
|
3102
3229
|
var OFF_LEVELS = ["off", 0];
|
|
@@ -3188,15 +3315,24 @@ var recommendedConfig = {
|
|
|
3188
3315
|
plugins: commentsConfig.plugins,
|
|
3189
3316
|
rules: { ...commentsConfig.rules, ...rowActionsConfig.rules, ...apiConfig.rules }
|
|
3190
3317
|
};
|
|
3318
|
+
var FOCUS_RULE_NAMES = ["explicit-initial-focus"];
|
|
3319
|
+
var focusConfig = {
|
|
3320
|
+
plugins: commentsConfig.plugins,
|
|
3321
|
+
rules: {
|
|
3322
|
+
"@dloizides/explicit-initial-focus": "error"
|
|
3323
|
+
}
|
|
3324
|
+
};
|
|
3191
3325
|
|
|
3192
3326
|
exports.API_RULE_NAMES = API_RULE_NAMES;
|
|
3193
3327
|
exports.COMMENT_RULE_NAMES = COMMENT_RULE_NAMES;
|
|
3328
|
+
exports.FOCUS_RULE_NAMES = FOCUS_RULE_NAMES;
|
|
3194
3329
|
exports.GAME_RULE_NAMES = GAME_RULE_NAMES;
|
|
3195
3330
|
exports.HOUSE_PATTERN_RULE_NAMES = HOUSE_PATTERN_RULE_NAMES;
|
|
3196
3331
|
exports.REUSE_RULE_NAMES = REUSE_RULE_NAMES;
|
|
3197
3332
|
exports.ROW_ACTION_RULE_NAMES = ROW_ACTION_RULE_NAMES;
|
|
3198
3333
|
exports.apiConfig = apiConfig;
|
|
3199
3334
|
exports.commentsConfig = commentsConfig;
|
|
3335
|
+
exports.focusConfig = focusConfig;
|
|
3200
3336
|
exports.gameConfig = gameConfig;
|
|
3201
3337
|
exports.legacyPlugins = legacyPlugins;
|
|
3202
3338
|
exports.patternPacksConfig = patternPacksConfig;
|