@dloizides/frontend-devtools 1.0.3 → 1.1.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.
- package/CHANGELOG.md +40 -0
- package/README.md +40 -0
- package/dist/eslint/index.js +70 -6
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +70 -6
- package/dist/eslint/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/eslint/index.mjs
CHANGED
|
@@ -1130,6 +1130,59 @@ var no_generated_models_barrel_value_import_default = {
|
|
|
1130
1130
|
};
|
|
1131
1131
|
|
|
1132
1132
|
// src/rules/no-null-check.js
|
|
1133
|
+
var DEFAULT_UTIL_IMPORT_PATH = "@dloizides/utils";
|
|
1134
|
+
var GUARD_NAME = "isValueDefined";
|
|
1135
|
+
var BindingKind = {
|
|
1136
|
+
/** Not bound — the fixer must add an import. */
|
|
1137
|
+
None: "none",
|
|
1138
|
+
/** Already imported — the fixer may rewrite freely. */
|
|
1139
|
+
Imported: "imported",
|
|
1140
|
+
/** Declared/exported *by this file* — never autofix (it would self-import). */
|
|
1141
|
+
Local: "local"
|
|
1142
|
+
};
|
|
1143
|
+
function findGuardBinding(ast) {
|
|
1144
|
+
for (const statement of ast.body) {
|
|
1145
|
+
if (statement.type === "ImportDeclaration") {
|
|
1146
|
+
for (const specifier of statement.specifiers) {
|
|
1147
|
+
if (specifier.local && specifier.local.name === GUARD_NAME) return BindingKind.Imported;
|
|
1148
|
+
}
|
|
1149
|
+
continue;
|
|
1150
|
+
}
|
|
1151
|
+
if (statement.type === "ExportNamedDeclaration") {
|
|
1152
|
+
for (const specifier of statement.specifiers || []) {
|
|
1153
|
+
if (specifier.exported && specifier.exported.name === GUARD_NAME) return BindingKind.Local;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
1157
|
+
if (!declaration) continue;
|
|
1158
|
+
if (declaration.type === "FunctionDeclaration" && declaration.id?.name === GUARD_NAME) {
|
|
1159
|
+
return BindingKind.Local;
|
|
1160
|
+
}
|
|
1161
|
+
if (declaration.type === "VariableDeclaration") {
|
|
1162
|
+
for (const declarator of declaration.declarations) {
|
|
1163
|
+
if (declarator.id?.type === "Identifier" && declarator.id.name === GUARD_NAME) {
|
|
1164
|
+
return BindingKind.Local;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
return BindingKind.None;
|
|
1170
|
+
}
|
|
1171
|
+
function buildGuardImportFix(fixer, sourceCode, utilImportPath) {
|
|
1172
|
+
const importStatement = `import { ${GUARD_NAME} } from '${utilImportPath}';`;
|
|
1173
|
+
const body = sourceCode.ast.body;
|
|
1174
|
+
const imports = body.filter((node) => node.type === "ImportDeclaration");
|
|
1175
|
+
if (imports.length > 0) {
|
|
1176
|
+
return fixer.insertTextAfter(imports[imports.length - 1], `
|
|
1177
|
+
${importStatement}`);
|
|
1178
|
+
}
|
|
1179
|
+
if (body.length > 0) {
|
|
1180
|
+
return fixer.insertTextBefore(body[0], `${importStatement}
|
|
1181
|
+
`);
|
|
1182
|
+
}
|
|
1183
|
+
return fixer.insertTextBeforeRange([0, 0], `${importStatement}
|
|
1184
|
+
`);
|
|
1185
|
+
}
|
|
1133
1186
|
var noNullCheckRule = {
|
|
1134
1187
|
meta: {
|
|
1135
1188
|
type: "suggestion",
|
|
@@ -1165,6 +1218,17 @@ var noNullCheckRule = {
|
|
|
1165
1218
|
},
|
|
1166
1219
|
create(context) {
|
|
1167
1220
|
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
1221
|
+
const options = context.options[0] || {};
|
|
1222
|
+
const utilImportPath = options.utilImportPath ?? DEFAULT_UTIL_IMPORT_PATH;
|
|
1223
|
+
const guardBinding = findGuardBinding(sourceCode.ast);
|
|
1224
|
+
const declaresGuardItself = guardBinding === BindingKind.Local;
|
|
1225
|
+
const guardIsImported = guardBinding === BindingKind.Imported;
|
|
1226
|
+
function buildFix(fixer, node, replacementText) {
|
|
1227
|
+
if (declaresGuardItself) return null;
|
|
1228
|
+
const rewrite = fixer.replaceText(node, replacementText);
|
|
1229
|
+
if (guardIsImported) return rewrite;
|
|
1230
|
+
return [rewrite, buildGuardImportFix(fixer, sourceCode, utilImportPath)];
|
|
1231
|
+
}
|
|
1168
1232
|
function isNullLiteral(node) {
|
|
1169
1233
|
return node && node.type === "Literal" && node.value === null;
|
|
1170
1234
|
}
|
|
@@ -1201,7 +1265,7 @@ var noNullCheckRule = {
|
|
|
1201
1265
|
messageId,
|
|
1202
1266
|
data: isSimple ? { identifier: valueText } : {},
|
|
1203
1267
|
fix(fixer) {
|
|
1204
|
-
return fixer
|
|
1268
|
+
return buildFix(fixer, node, `isValueDefined(${valueText})`);
|
|
1205
1269
|
}
|
|
1206
1270
|
});
|
|
1207
1271
|
} else {
|
|
@@ -1211,7 +1275,7 @@ var noNullCheckRule = {
|
|
|
1211
1275
|
messageId,
|
|
1212
1276
|
data: isSimple ? { identifier: valueText } : {},
|
|
1213
1277
|
fix(fixer) {
|
|
1214
|
-
return fixer
|
|
1278
|
+
return buildFix(fixer, node, `!isValueDefined(${valueText})`);
|
|
1215
1279
|
}
|
|
1216
1280
|
});
|
|
1217
1281
|
}
|
|
@@ -1684,7 +1748,7 @@ var require_stable_hook_args_default = {
|
|
|
1684
1748
|
// src/rules/smart-max-lines.js
|
|
1685
1749
|
var COMPONENT_MAX_DEFAULT = 200;
|
|
1686
1750
|
var FUNCTION_MAX_DEFAULT = 50;
|
|
1687
|
-
var FUNCTION_WARN_DEFAULT =
|
|
1751
|
+
var FUNCTION_WARN_DEFAULT = void 0;
|
|
1688
1752
|
function isJSX2(node) {
|
|
1689
1753
|
if (!node) {
|
|
1690
1754
|
return false;
|
|
@@ -1852,7 +1916,7 @@ var smartMaxLinesRule = {
|
|
|
1852
1916
|
functionWarn: {
|
|
1853
1917
|
type: "integer",
|
|
1854
1918
|
minimum: 1,
|
|
1855
|
-
description:
|
|
1919
|
+
description: 'Optional SECOND, stricter threshold for regular functions. Disabled by default. Reports at the severity the rule is configured with (ESLint has no per-report severity) \u2014 it is NOT a "warning" tier.'
|
|
1856
1920
|
},
|
|
1857
1921
|
skipBlankLines: {
|
|
1858
1922
|
type: "boolean",
|
|
@@ -1869,7 +1933,7 @@ var smartMaxLinesRule = {
|
|
|
1869
1933
|
messages: {
|
|
1870
1934
|
componentTooLong: "React component has too many lines ({{count}}). Maximum allowed is {{max}}.",
|
|
1871
1935
|
functionTooLong: "Function has too many lines ({{count}}). Maximum allowed is {{max}}.",
|
|
1872
|
-
functionWarning: "Function has {{count}} lines
|
|
1936
|
+
functionWarning: "Function has {{count}} lines, over the configured stricter limit of {{warn}}. Consider refactoring."
|
|
1873
1937
|
}
|
|
1874
1938
|
},
|
|
1875
1939
|
create(context) {
|
|
@@ -1904,7 +1968,7 @@ var smartMaxLinesRule = {
|
|
|
1904
1968
|
max: String(functionMax)
|
|
1905
1969
|
}
|
|
1906
1970
|
});
|
|
1907
|
-
} else if (lineCount > functionWarn) {
|
|
1971
|
+
} else if (functionWarn !== void 0 && lineCount > functionWarn) {
|
|
1908
1972
|
context.report({
|
|
1909
1973
|
node,
|
|
1910
1974
|
messageId: "functionWarning",
|