eslint-plugin-lube 0.8.0 → 0.8.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
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.1
4
+
5
+ ### Fixed
6
+
7
+ - `svelte-naming-convention` no longer reports or renames an ambient TypeScript declaration (`declare function`, `declare const`, `declare let`, `declare var`, `declare class`, and anything inside `declare global { }` or `declare module "m" { }`) or its usages, since the name belongs to the host that injects it.
8
+ - `svelte-naming-convention` renames every overload signature and the implementation of a function together with its calls, instead of only the calls.
9
+
3
10
  ## 0.8.0
4
11
 
5
12
  ### Breaking
@@ -6,6 +6,7 @@ The strict config turns it on and the recommended config leaves it off, since it
6
6
  - The message names the expected name, `Rename 'camelCase' to 'camel_case'`, or, for a name without a snake_case form such as `NO_SNAKE__CASE`, asks for snake_case, UPPER_SNAKE_CASE or PascalCase.
7
7
  - Usages such as assignments, function bodies, `extends` clauses, JSX and TypeScript expressions are only renamed along with their declaration; `fixSameNames` sets the order.
8
8
  - Usages are matched to declarations by scope, so a global, an import or an exported camelCase function of the same name is left as it is.
9
+ - An ambient TypeScript declaration, `declare function acquireVsCodeApi(): Api`, `declare const`, `declare class`, or anything inside `declare global { }` or `declare module "m" { }`, names a binding the code does not own: it is neither reported nor renamed, and neither are its usages.
9
10
  - A declaration exported with `export { camelCase }` is renamed together with the export specifier, `export { camel_case as camelCase }`.
10
11
  - The JSDoc of a renamed parameter follows it: `@param {T} [camelCase]`, `{camelCase is T}` and `{typeof camelCase}`.
11
12
  - In a `.svelte` file, the store subscriptions of a renamed store are renamed with it, `$camelCase` into `$camel_case`, in the same fix, and so are the usages in the markup: mustache tags, attributes, directives and the expression of `{#if}`, `{#each}`, `{#await}` and `{#key}`. A shorthand attribute is written out, `{camelCase}` into `camelCase={camel_case}`, so the name of the property stays. Names the markup declares, the context of `{#each}`, the value of `{#await}` and a `let:` property, are not reported.
package/package.json CHANGED
@@ -7,11 +7,6 @@
7
7
  "@stylistic/eslint-plugin": "^5.10.0"
8
8
  },
9
9
  "description": "Fixable ESLint rules that format code without Prettier",
10
- "devDependencies": {
11
- "@types/estree": "^1.0.9",
12
- "@typescript/native": "npm:typescript@^7.0.2",
13
- "eslint": "^10.12.0"
14
- },
15
10
  "engines": {
16
11
  "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
17
12
  },
@@ -53,7 +48,7 @@
53
48
  },
54
49
  "type": "module",
55
50
  "types": "types/index.d.ts",
56
- "version": "0.8.0",
51
+ "version": "0.8.1",
57
52
  "scripts": {
58
53
  "dts": "node ../../scripts/tsc_with_clean.js eslint-plugin-lube",
59
54
  "lint": "pnpm -w lint",
@@ -188,7 +188,9 @@ export default {
188
188
  * @returns {void}
189
189
  */
190
190
  function declare(node) {
191
- add(declarations, node)
191
+ if (!is_ambient(node)) {
192
+ add(declarations, node)
193
+ }
192
194
  }
193
195
  /**
194
196
  * @param {import("../../private.js").AstNode & import("estree").Identifier} node
@@ -234,6 +236,22 @@ export default {
234
236
  }
235
237
  return depth > 0
236
238
  }
239
+ /**
240
+ * @param {import("../../private.js").AstNode} node
241
+ * @returns {boolean}
242
+ */
243
+ function is_ambient(node) {
244
+ for (
245
+ let current = /** @type {import("../../private.js").AstNode | undefined} */(node)/**/;
246
+ current;
247
+ current = current.parent
248
+ ) {
249
+ if ("declare" in current && current.declare === true) {
250
+ return true
251
+ }
252
+ }
253
+ return false
254
+ }
237
255
  /**
238
256
  * @param {import("../../private.js").AstNode} node
239
257
  * @returns {boolean}
@@ -916,7 +934,7 @@ export default {
916
934
  plans.set(
917
935
  name,
918
936
  {
919
- atomic: !fix_same_names || variables_by_name.has(target) || nested_targets.has(target) || store_usages.has(name),
937
+ atomic: !fix_same_names || nodes.length > 1 || variables_by_name.has(target) || nested_targets.has(target) || store_usages.has(name),
920
938
  exported: (export_locals.get(name) ?? []).filter(belongs),
921
939
  fixable: !blocked.has(name)
922
940
  && fixable_name_regex.test(name)
@@ -930,21 +948,16 @@ export default {
930
948
  }
931
949
  /**
932
950
  * @param {import("../../private.js").NamingIdentifier} node
933
- * @param {import("../../private.js").NamingIdentifier[]} nodes
934
951
  * @param {import("../../private.js").NamingIdentifier[]} usages_held
935
952
  * @returns {import("../../private.js").RenameEdit[]}
936
953
  */
937
- function declaration_fix(node, nodes, usages_held) {
954
+ function declaration_fix(node, usages_held) {
938
955
  const variable = resolution.get(node)
939
956
  return [
940
957
  ...declaration_edits(node, resolution),
941
- ...nodes.find(
942
- other => resolution.get(other) == variable
943
- ) == node
944
- ? usages_held.filter(
945
- usage => resolution.get(usage) == variable
946
- ).map(rename_edit)
947
- : []
958
+ ...usages_held.filter(
959
+ usage => resolution.get(usage) == variable
960
+ ).map(rename_edit)
948
961
  ]
949
962
  }
950
963
  /** @type {import("../../private.js").RenameEdit[]} */
@@ -990,7 +1003,7 @@ export default {
990
1003
  for (const node of nodes) {
991
1004
  report(
992
1005
  node,
993
- fixable && !used.length ? declaration_fix(node, nodes, usages_held) : null
1006
+ fixable && !used.length ? declaration_fix(node, usages_held) : null
994
1007
  )
995
1008
  }
996
1009
  } else {