@dloizides/frontend-devtools 1.0.3 → 1.1.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.
@@ -1130,6 +1130,54 @@ 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 imports = sourceCode.ast.body.filter((node) => node.type === "ImportDeclaration");
1174
+ if (imports.length > 0) {
1175
+ return fixer.insertTextAfter(imports[imports.length - 1], `
1176
+ ${importStatement}`);
1177
+ }
1178
+ return fixer.insertTextBeforeRange([0, 0], `${importStatement}
1179
+ `);
1180
+ }
1133
1181
  var noNullCheckRule = {
1134
1182
  meta: {
1135
1183
  type: "suggestion",
@@ -1165,6 +1213,17 @@ var noNullCheckRule = {
1165
1213
  },
1166
1214
  create(context) {
1167
1215
  const sourceCode = context.sourceCode || context.getSourceCode();
1216
+ const options = context.options[0] || {};
1217
+ const utilImportPath = options.utilImportPath ?? DEFAULT_UTIL_IMPORT_PATH;
1218
+ const guardBinding = findGuardBinding(sourceCode.ast);
1219
+ const declaresGuardItself = guardBinding === BindingKind.Local;
1220
+ const guardIsImported = guardBinding === BindingKind.Imported;
1221
+ function buildFix(fixer, node, replacementText) {
1222
+ if (declaresGuardItself) return null;
1223
+ const rewrite = fixer.replaceText(node, replacementText);
1224
+ if (guardIsImported) return rewrite;
1225
+ return [rewrite, buildGuardImportFix(fixer, sourceCode, utilImportPath)];
1226
+ }
1168
1227
  function isNullLiteral(node) {
1169
1228
  return node && node.type === "Literal" && node.value === null;
1170
1229
  }
@@ -1201,7 +1260,7 @@ var noNullCheckRule = {
1201
1260
  messageId,
1202
1261
  data: isSimple ? { identifier: valueText } : {},
1203
1262
  fix(fixer) {
1204
- return fixer.replaceText(node, `isValueDefined(${valueText})`);
1263
+ return buildFix(fixer, node, `isValueDefined(${valueText})`);
1205
1264
  }
1206
1265
  });
1207
1266
  } else {
@@ -1211,7 +1270,7 @@ var noNullCheckRule = {
1211
1270
  messageId,
1212
1271
  data: isSimple ? { identifier: valueText } : {},
1213
1272
  fix(fixer) {
1214
- return fixer.replaceText(node, `!isValueDefined(${valueText})`);
1273
+ return buildFix(fixer, node, `!isValueDefined(${valueText})`);
1215
1274
  }
1216
1275
  });
1217
1276
  }
@@ -1684,7 +1743,7 @@ var require_stable_hook_args_default = {
1684
1743
  // src/rules/smart-max-lines.js
1685
1744
  var COMPONENT_MAX_DEFAULT = 200;
1686
1745
  var FUNCTION_MAX_DEFAULT = 50;
1687
- var FUNCTION_WARN_DEFAULT = 30;
1746
+ var FUNCTION_WARN_DEFAULT = void 0;
1688
1747
  function isJSX2(node) {
1689
1748
  if (!node) {
1690
1749
  return false;
@@ -1852,7 +1911,7 @@ var smartMaxLinesRule = {
1852
1911
  functionWarn: {
1853
1912
  type: "integer",
1854
1913
  minimum: 1,
1855
- description: "Warning threshold for regular functions"
1914
+ 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
1915
  },
1857
1916
  skipBlankLines: {
1858
1917
  type: "boolean",
@@ -1869,7 +1928,7 @@ var smartMaxLinesRule = {
1869
1928
  messages: {
1870
1929
  componentTooLong: "React component has too many lines ({{count}}). Maximum allowed is {{max}}.",
1871
1930
  functionTooLong: "Function has too many lines ({{count}}). Maximum allowed is {{max}}.",
1872
- functionWarning: "Function has {{count}} lines which exceeds recommended limit of {{warn}}. Consider refactoring."
1931
+ functionWarning: "Function has {{count}} lines, over the configured stricter limit of {{warn}}. Consider refactoring."
1873
1932
  }
1874
1933
  },
1875
1934
  create(context) {
@@ -1904,7 +1963,7 @@ var smartMaxLinesRule = {
1904
1963
  max: String(functionMax)
1905
1964
  }
1906
1965
  });
1907
- } else if (lineCount > functionWarn) {
1966
+ } else if (functionWarn !== void 0 && lineCount > functionWarn) {
1908
1967
  context.report({
1909
1968
  node,
1910
1969
  messageId: "functionWarning",