eslint-plugin-prefer-let 3.0.1 → 4.0.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,14 @@
1
1
  # eslint-plugin-prefer-let
2
2
 
3
+ ## \[4.0.1]
4
+
5
+ - [`ee2ef1b`](https://github.com/thefrontside/javascript/commit/ee2ef1be18087421c2870eb2845b3235e1e10d58) allow var in TypeScript ambient declarations
6
+ - [`02b89a4`](https://github.com/thefrontside/javascript/commit/02b89a41ecc9711cea3ef6131f9a2bde842ec4fe) Support the `using` declaration from explicit resource management
7
+
8
+ ## \[4.0.0]
9
+
10
+ - [`e597fa9`](https://github.com/thefrontside/javascript/commit/e597fa93ce94f81d08d259895003a489ccc0021e) Support ESLint v9
11
+
3
12
  ## 3.0.1
4
13
 
5
14
  ### Patch Changes
package/README.md CHANGED
@@ -8,7 +8,7 @@ long-standing conventions set forth by both formal symbolic logic and
8
8
  the practice of functional programming.
9
9
 
10
10
  Usage of the `const` keyword to bind an _intermediate_ value of a
11
- computation places emphasis on the compiler and and its role in
11
+ computation places emphasis on the compiler and its role in
12
12
  ensuring that a _reference_ never changes. By contrast using `let` in
13
13
  the same situation reads, in plain English, the programmer's intent to
14
14
  declare a name value binding.
@@ -28,22 +28,40 @@ module.exports = {
28
28
  // Helpers
29
29
  //----------------------------------------------------------------------
30
30
 
31
+ function getScope(node) {
32
+ let sourceCode = context.sourceCode ?? context.getSourceCode();
33
+ return sourceCode.getScope
34
+ ? sourceCode.getScope(node)
35
+ : context.getScope();
36
+ }
37
+
31
38
  function isGlobalScope(node) {
32
- return context.getScope().type === 'global';
39
+ return getScope(node).type === 'global';
33
40
  }
34
41
 
35
42
  function isModuleScope(node) {
36
- return context.getScope().type === 'module';
43
+ return getScope(node).type === 'module';
37
44
  }
38
45
 
39
46
  function isProgramScope(node) {
40
- return context.getScope().block.type === 'Program';
47
+ return getScope(node).block.type === 'Program';
41
48
  }
42
49
 
43
50
  function isTopLevelScope(node) {
44
51
  return isGlobalScope(node) || isModuleScope(node) || isProgramScope(node);
45
52
  }
46
53
 
54
+ function isInAmbientContext(node) {
55
+ let current = node.parent;
56
+ while (current) {
57
+ if (current.type === 'TSModuleDeclaration' && current.declare === true) {
58
+ return true;
59
+ }
60
+ current = current.parent;
61
+ }
62
+ return false;
63
+ }
64
+
47
65
  //----------------------------------------------------------------------
48
66
  // Public
49
67
  //----------------------------------------------------------------------
@@ -51,11 +69,14 @@ module.exports = {
51
69
  return {
52
70
  VariableDeclaration(node) {
53
71
  if (node.kind === 'var') {
72
+ if (isInAmbientContext(node)) {
73
+ return;
74
+ }
54
75
  context.report({
55
76
  message: 'prefer `let` over `var` to declare value bindings',
56
77
  node
57
78
  });
58
- } else if (node.kind !== 'let' && !isTopLevelScope(node)) {
79
+ } else if (node.kind === 'const' && !isTopLevelScope(node)) {
59
80
  let constToken = sourceCode.getFirstToken(node);
60
81
 
61
82
  context.report({
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "eslint-plugin-prefer-let",
3
- "version": "3.0.1",
3
+ "version": "4.0.1",
4
4
  "description": "Rule to prefer using `let` to bind names to values",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/thefrontside/javascript.git",
8
+ "directory": "packages/eslint-plugin-prefer-let"
9
+ },
5
10
  "keywords": [
6
11
  "eslint",
7
12
  "eslintplugin",
@@ -15,12 +20,13 @@
15
20
  "requireindex": "~1.2.0"
16
21
  },
17
22
  "devDependencies": {
18
- "eslint": "^8.0.1",
23
+ "@typescript-eslint/parser": "^8.0.0",
24
+ "eslint": "^9.3.0",
25
+ "globals": "^15.3.0",
19
26
  "mocha": "^9.1.3"
20
27
  },
21
28
  "engines": {
22
29
  "node": ">=0.10.0"
23
30
  },
24
- "license": "ISC",
25
- "repository": "thefrontside/javascript"
31
+ "license": "ISC"
26
32
  }