@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 CHANGED
@@ -5,6 +5,46 @@ All notable changes to `@dloizides/frontend-devtools` are documented here.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.1.0] - 2026-07-13
9
+
10
+ Both changes come out of the ES-04 (agora-web) build, which surfaced two ways the
11
+ rule pack misbehaved against a freshly scaffolded app.
12
+
13
+ ### Fixed
14
+
15
+ - **`no-null-check`: the autofixer no longer corrupts files.** It rewrote
16
+ `x === undefined` → `!isValueDefined(x)` *without importing `isValueDefined`*,
17
+ so `eslint --fix` emitted source referencing an undeclared global. Running
18
+ `lint:fix` on agora-web rewrote ~20 files and produced 67 `no-unsafe-call` /
19
+ `strict-boolean-expressions` errors. A fixer that produces broken code is worse
20
+ than no fixer — `lint:fix` is the first thing anyone runs.
21
+
22
+ The fixer now inserts `import { isValueDefined } from '@dloizides/utils';` (the
23
+ path is configurable via the pre-existing but previously **unused**
24
+ `utilImportPath` option) when the file has no binding for the guard, and skips
25
+ the autofix entirely in the module that defines or re-exports it. Proven with
26
+ `Linter.verifyAndFix` multipass tests — the actual `--fix` code path.
27
+
28
+ ⚠️ The package's own test suite had *codified* the bug: it asserted the
29
+ import-less output was correct. Those expectations were wrong and are updated.
30
+
31
+ ### Changed
32
+
33
+ - **`smart-max-lines`: `functionWarn` is now opt-in (default: off).** ESLint has
34
+ no per-report severity, so a `functionWarn` report is emitted at the severity
35
+ the *rule* is configured with. Every app configured the rule as `'error'` and
36
+ passed `functionWarn: 30` — which made the real, enforced limit **30 lines**
37
+ while the docs promised **50**. The rule lied about its own threshold.
38
+
39
+ Out of the box the only enforced thresholds are now `componentMax` (200) and
40
+ `functionMax` (50) — exactly what the documentation has always promised.
41
+ `functionWarn` remains available as an explicit *stricter second threshold*,
42
+ and its schema/message now say plainly that it reports at the rule's severity
43
+ rather than as a warning.
44
+
45
+ Migration: drop `functionWarn: 30` from your ESLint config. This only relaxes
46
+ linting (30 → 50), so it cannot introduce new failures.
47
+
8
48
  ## [1.0.0] - 2026-06-14
9
49
 
10
50
  ### Added
package/README.md CHANGED
@@ -57,6 +57,46 @@ export default [
57
57
  ];
58
58
  ```
59
59
 
60
+ ### Two rules worth knowing the exact semantics of
61
+
62
+ #### `smart-max-lines` — `functionWarn` is NOT a warning tier
63
+
64
+ ESLint has **no per-report severity**: every `context.report()` a rule makes is
65
+ emitted at the severity the *rule* is configured with. A rule cannot warn on one
66
+ line and error on another.
67
+
68
+ So `['error', { functionWarn: 30 }]` does **not** give you "warn at 30, error at
69
+ 50" — it gives you a hard **error at 30**, silently overriding the documented
70
+ 50-line limit. That mismatch is why `functionWarn` is now **opt-in and off by
71
+ default** (since 1.1.0). Out of the box the only threshold is `functionMax`:
72
+
73
+ | Function kind | Enforced limit |
74
+ | --- | --- |
75
+ | React component (returns JSX) | `componentMax`, default **200** |
76
+ | Regular function | `functionMax`, default **50** |
77
+
78
+ Set `functionWarn` only if you deliberately want a *second, stricter* hard
79
+ threshold — it reports at the rule's own severity, not at `'warn'`.
80
+
81
+ #### `no-null-check` — the autofix brings its own import
82
+
83
+ The fix rewrites `x === undefined` → `!isValueDefined(x)`. That is only valid
84
+ source if `isValueDefined` is in scope, so the fixer **adds the import** when the
85
+ file lacks it:
86
+
87
+ ```js
88
+ 'no-null-check/no-null-check': ['error', { utilImportPath: '@dloizides/utils' }],
89
+ ```
90
+
91
+ `utilImportPath` (default `@dloizides/utils`) is the module the import is added
92
+ from. The fixer never touches the module that *defines* or *re-exports* the guard
93
+ — it would otherwise self-import.
94
+
95
+ > Before 1.1.0 the fixer emitted the call with no import, so `eslint --fix`
96
+ > produced files referencing an undeclared global. Running `lint:fix` on a fresh
97
+ > app corrupted ~20 files at once. If you are on ≤1.0.3, upgrade before running
98
+ > `lint:fix`.
99
+
60
100
  Delete the local `eslint-plugins/*.mjs` files and their imports; the rule names,
61
101
  options, and severities stay exactly as they were.
62
102
 
@@ -1137,6 +1137,59 @@ var no_generated_models_barrel_value_import_default = {
1137
1137
  };
1138
1138
 
1139
1139
  // src/rules/no-null-check.js
1140
+ var DEFAULT_UTIL_IMPORT_PATH = "@dloizides/utils";
1141
+ var GUARD_NAME = "isValueDefined";
1142
+ var BindingKind = {
1143
+ /** Not bound — the fixer must add an import. */
1144
+ None: "none",
1145
+ /** Already imported — the fixer may rewrite freely. */
1146
+ Imported: "imported",
1147
+ /** Declared/exported *by this file* — never autofix (it would self-import). */
1148
+ Local: "local"
1149
+ };
1150
+ function findGuardBinding(ast) {
1151
+ for (const statement of ast.body) {
1152
+ if (statement.type === "ImportDeclaration") {
1153
+ for (const specifier of statement.specifiers) {
1154
+ if (specifier.local && specifier.local.name === GUARD_NAME) return BindingKind.Imported;
1155
+ }
1156
+ continue;
1157
+ }
1158
+ if (statement.type === "ExportNamedDeclaration") {
1159
+ for (const specifier of statement.specifiers || []) {
1160
+ if (specifier.exported && specifier.exported.name === GUARD_NAME) return BindingKind.Local;
1161
+ }
1162
+ }
1163
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
1164
+ if (!declaration) continue;
1165
+ if (declaration.type === "FunctionDeclaration" && declaration.id?.name === GUARD_NAME) {
1166
+ return BindingKind.Local;
1167
+ }
1168
+ if (declaration.type === "VariableDeclaration") {
1169
+ for (const declarator of declaration.declarations) {
1170
+ if (declarator.id?.type === "Identifier" && declarator.id.name === GUARD_NAME) {
1171
+ return BindingKind.Local;
1172
+ }
1173
+ }
1174
+ }
1175
+ }
1176
+ return BindingKind.None;
1177
+ }
1178
+ function buildGuardImportFix(fixer, sourceCode, utilImportPath) {
1179
+ const importStatement = `import { ${GUARD_NAME} } from '${utilImportPath}';`;
1180
+ const body = sourceCode.ast.body;
1181
+ const imports = body.filter((node) => node.type === "ImportDeclaration");
1182
+ if (imports.length > 0) {
1183
+ return fixer.insertTextAfter(imports[imports.length - 1], `
1184
+ ${importStatement}`);
1185
+ }
1186
+ if (body.length > 0) {
1187
+ return fixer.insertTextBefore(body[0], `${importStatement}
1188
+ `);
1189
+ }
1190
+ return fixer.insertTextBeforeRange([0, 0], `${importStatement}
1191
+ `);
1192
+ }
1140
1193
  var noNullCheckRule = {
1141
1194
  meta: {
1142
1195
  type: "suggestion",
@@ -1172,6 +1225,17 @@ var noNullCheckRule = {
1172
1225
  },
1173
1226
  create(context) {
1174
1227
  const sourceCode = context.sourceCode || context.getSourceCode();
1228
+ const options = context.options[0] || {};
1229
+ const utilImportPath = options.utilImportPath ?? DEFAULT_UTIL_IMPORT_PATH;
1230
+ const guardBinding = findGuardBinding(sourceCode.ast);
1231
+ const declaresGuardItself = guardBinding === BindingKind.Local;
1232
+ const guardIsImported = guardBinding === BindingKind.Imported;
1233
+ function buildFix(fixer, node, replacementText) {
1234
+ if (declaresGuardItself) return null;
1235
+ const rewrite = fixer.replaceText(node, replacementText);
1236
+ if (guardIsImported) return rewrite;
1237
+ return [rewrite, buildGuardImportFix(fixer, sourceCode, utilImportPath)];
1238
+ }
1175
1239
  function isNullLiteral(node) {
1176
1240
  return node && node.type === "Literal" && node.value === null;
1177
1241
  }
@@ -1208,7 +1272,7 @@ var noNullCheckRule = {
1208
1272
  messageId,
1209
1273
  data: isSimple ? { identifier: valueText } : {},
1210
1274
  fix(fixer) {
1211
- return fixer.replaceText(node, `isValueDefined(${valueText})`);
1275
+ return buildFix(fixer, node, `isValueDefined(${valueText})`);
1212
1276
  }
1213
1277
  });
1214
1278
  } else {
@@ -1218,7 +1282,7 @@ var noNullCheckRule = {
1218
1282
  messageId,
1219
1283
  data: isSimple ? { identifier: valueText } : {},
1220
1284
  fix(fixer) {
1221
- return fixer.replaceText(node, `!isValueDefined(${valueText})`);
1285
+ return buildFix(fixer, node, `!isValueDefined(${valueText})`);
1222
1286
  }
1223
1287
  });
1224
1288
  }
@@ -1691,7 +1755,7 @@ var require_stable_hook_args_default = {
1691
1755
  // src/rules/smart-max-lines.js
1692
1756
  var COMPONENT_MAX_DEFAULT = 200;
1693
1757
  var FUNCTION_MAX_DEFAULT = 50;
1694
- var FUNCTION_WARN_DEFAULT = 30;
1758
+ var FUNCTION_WARN_DEFAULT = void 0;
1695
1759
  function isJSX2(node) {
1696
1760
  if (!node) {
1697
1761
  return false;
@@ -1859,7 +1923,7 @@ var smartMaxLinesRule = {
1859
1923
  functionWarn: {
1860
1924
  type: "integer",
1861
1925
  minimum: 1,
1862
- description: "Warning threshold for regular functions"
1926
+ 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.'
1863
1927
  },
1864
1928
  skipBlankLines: {
1865
1929
  type: "boolean",
@@ -1876,7 +1940,7 @@ var smartMaxLinesRule = {
1876
1940
  messages: {
1877
1941
  componentTooLong: "React component has too many lines ({{count}}). Maximum allowed is {{max}}.",
1878
1942
  functionTooLong: "Function has too many lines ({{count}}). Maximum allowed is {{max}}.",
1879
- functionWarning: "Function has {{count}} lines which exceeds recommended limit of {{warn}}. Consider refactoring."
1943
+ functionWarning: "Function has {{count}} lines, over the configured stricter limit of {{warn}}. Consider refactoring."
1880
1944
  }
1881
1945
  },
1882
1946
  create(context) {
@@ -1911,7 +1975,7 @@ var smartMaxLinesRule = {
1911
1975
  max: String(functionMax)
1912
1976
  }
1913
1977
  });
1914
- } else if (lineCount > functionWarn) {
1978
+ } else if (functionWarn !== void 0 && lineCount > functionWarn) {
1915
1979
  context.report({
1916
1980
  node,
1917
1981
  messageId: "functionWarning",