@dloizides/frontend-devtools 1.0.2 → 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.
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,54 @@ 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 imports = sourceCode.ast.body.filter((node) => node.type === "ImportDeclaration");
1181
+ if (imports.length > 0) {
1182
+ return fixer.insertTextAfter(imports[imports.length - 1], `
1183
+ ${importStatement}`);
1184
+ }
1185
+ return fixer.insertTextBeforeRange([0, 0], `${importStatement}
1186
+ `);
1187
+ }
1140
1188
  var noNullCheckRule = {
1141
1189
  meta: {
1142
1190
  type: "suggestion",
@@ -1172,6 +1220,17 @@ var noNullCheckRule = {
1172
1220
  },
1173
1221
  create(context) {
1174
1222
  const sourceCode = context.sourceCode || context.getSourceCode();
1223
+ const options = context.options[0] || {};
1224
+ const utilImportPath = options.utilImportPath ?? DEFAULT_UTIL_IMPORT_PATH;
1225
+ const guardBinding = findGuardBinding(sourceCode.ast);
1226
+ const declaresGuardItself = guardBinding === BindingKind.Local;
1227
+ const guardIsImported = guardBinding === BindingKind.Imported;
1228
+ function buildFix(fixer, node, replacementText) {
1229
+ if (declaresGuardItself) return null;
1230
+ const rewrite = fixer.replaceText(node, replacementText);
1231
+ if (guardIsImported) return rewrite;
1232
+ return [rewrite, buildGuardImportFix(fixer, sourceCode, utilImportPath)];
1233
+ }
1175
1234
  function isNullLiteral(node) {
1176
1235
  return node && node.type === "Literal" && node.value === null;
1177
1236
  }
@@ -1208,7 +1267,7 @@ var noNullCheckRule = {
1208
1267
  messageId,
1209
1268
  data: isSimple ? { identifier: valueText } : {},
1210
1269
  fix(fixer) {
1211
- return fixer.replaceText(node, `isValueDefined(${valueText})`);
1270
+ return buildFix(fixer, node, `isValueDefined(${valueText})`);
1212
1271
  }
1213
1272
  });
1214
1273
  } else {
@@ -1218,7 +1277,7 @@ var noNullCheckRule = {
1218
1277
  messageId,
1219
1278
  data: isSimple ? { identifier: valueText } : {},
1220
1279
  fix(fixer) {
1221
- return fixer.replaceText(node, `!isValueDefined(${valueText})`);
1280
+ return buildFix(fixer, node, `!isValueDefined(${valueText})`);
1222
1281
  }
1223
1282
  });
1224
1283
  }
@@ -1691,7 +1750,7 @@ var require_stable_hook_args_default = {
1691
1750
  // src/rules/smart-max-lines.js
1692
1751
  var COMPONENT_MAX_DEFAULT = 200;
1693
1752
  var FUNCTION_MAX_DEFAULT = 50;
1694
- var FUNCTION_WARN_DEFAULT = 30;
1753
+ var FUNCTION_WARN_DEFAULT = void 0;
1695
1754
  function isJSX2(node) {
1696
1755
  if (!node) {
1697
1756
  return false;
@@ -1859,7 +1918,7 @@ var smartMaxLinesRule = {
1859
1918
  functionWarn: {
1860
1919
  type: "integer",
1861
1920
  minimum: 1,
1862
- description: "Warning threshold for regular functions"
1921
+ 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
1922
  },
1864
1923
  skipBlankLines: {
1865
1924
  type: "boolean",
@@ -1876,7 +1935,7 @@ var smartMaxLinesRule = {
1876
1935
  messages: {
1877
1936
  componentTooLong: "React component has too many lines ({{count}}). Maximum allowed is {{max}}.",
1878
1937
  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."
1938
+ functionWarning: "Function has {{count}} lines, over the configured stricter limit of {{warn}}. Consider refactoring."
1880
1939
  }
1881
1940
  },
1882
1941
  create(context) {
@@ -1911,7 +1970,7 @@ var smartMaxLinesRule = {
1911
1970
  max: String(functionMax)
1912
1971
  }
1913
1972
  });
1914
- } else if (lineCount > functionWarn) {
1973
+ } else if (functionWarn !== void 0 && lineCount > functionWarn) {
1915
1974
  context.report({
1916
1975
  node,
1917
1976
  messageId: "functionWarning",