--- source: crates/biome_js_analyze/tests/spec_tests.rs expression: invalid.js --- # Input ```jsx const a = 1; a = 2; const b = 2, c = 43; b = 4; ++b; b += 45; b--; function f() { b++; } function f(d) { b++; } const fn = (val) => { val = 0; }; const e = () => { try { foo(); } catch (err) { err = 4; } }; const f = (...rest) => { rest = 4; }; const g = class bar {}; bar = 1; const h = function foo() { foo = 1; }; const { i, j: { l }, } = { i: 1, j: { l: 2 } }; i = 4; l = 4; for (const k in [1, 2]) { k = 4; } const [p, { q }] = [1, { q: 2 }]; p = 3; q = 4; const { r, ...rest } = s; r = 4; /*before*/const/*after*/ a = 0; a = 1; ``` # Diagnostics ``` invalid.js:2:1 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign a because it's a constant 1 │ const a = 1; > 2 │ a = 2; │ ^ 3 │ 4 │ const b = 2, c = 43; i This is where the variable is defined as constant 54 │ r = 4; 55 │ > 56 │ /*before*/const/*after*/ a = 0; │ ^ 57 │ a = 1; 58 │ i Unsafe fix: Replace const with let if you assign it to a new value. 54 54 │ r = 4; 55 55 │ 56 │ - /*before*/const/*after*/·a·=·0; 56 │ + /*before*/let/*after*/·a·=·0; 57 57 │ a = 1; 58 58 │ ``` ``` invalid.js:5:1 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign b because it's a constant 4 │ const b = 2, c = 43; > 5 │ b = 4; │ ^ 6 │ ++b; 7 │ b += 45; i This is where the variable is defined as constant 2 │ a = 2; 3 │ > 4 │ const b = 2, c = 43; │ ^ 5 │ b = 4; 6 │ ++b; i Unsafe fix: Replace const with let if you assign it to a new value. 2 2 │ a = 2; 3 3 │ 4 │ - const·b·=·2,·c·=·43; 4 │ + let·b·=·2,·c·=·43; 5 5 │ b = 4; 6 6 │ ++b; ``` ``` invalid.js:6:3 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign b because it's a constant 4 │ const b = 2, c = 43; 5 │ b = 4; > 6 │ ++b; │ ^ 7 │ b += 45; 8 │ b--; i This is where the variable is defined as constant 2 │ a = 2; 3 │ > 4 │ const b = 2, c = 43; │ ^ 5 │ b = 4; 6 │ ++b; i Unsafe fix: Replace const with let if you assign it to a new value. 2 2 │ a = 2; 3 3 │ 4 │ - const·b·=·2,·c·=·43; 4 │ + let·b·=·2,·c·=·43; 5 5 │ b = 4; 6 6 │ ++b; ``` ``` invalid.js:7:1 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign b because it's a constant 5 │ b = 4; 6 │ ++b; > 7 │ b += 45; │ ^ 8 │ b--; 9 │ function f() { i This is where the variable is defined as constant 2 │ a = 2; 3 │ > 4 │ const b = 2, c = 43; │ ^ 5 │ b = 4; 6 │ ++b; i Unsafe fix: Replace const with let if you assign it to a new value. 2 2 │ a = 2; 3 3 │ 4 │ - const·b·=·2,·c·=·43; 4 │ + let·b·=·2,·c·=·43; 5 5 │ b = 4; 6 6 │ ++b; ``` ``` invalid.js:8:1 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign b because it's a constant 6 │ ++b; 7 │ b += 45; > 8 │ b--; │ ^ 9 │ function f() { 10 │ b++; i This is where the variable is defined as constant 2 │ a = 2; 3 │ > 4 │ const b = 2, c = 43; │ ^ 5 │ b = 4; 6 │ ++b; i Unsafe fix: Replace const with let if you assign it to a new value. 2 2 │ a = 2; 3 3 │ 4 │ - const·b·=·2,·c·=·43; 4 │ + let·b·=·2,·c·=·43; 5 5 │ b = 4; 6 6 │ ++b; ``` ``` invalid.js:10:2 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign b because it's a constant 8 │ b--; 9 │ function f() { > 10 │ b++; │ ^ 11 │ } 12 │ function f(d) { i This is where the variable is defined as constant 2 │ a = 2; 3 │ > 4 │ const b = 2, c = 43; │ ^ 5 │ b = 4; 6 │ ++b; i Unsafe fix: Replace const with let if you assign it to a new value. 2 2 │ a = 2; 3 3 │ 4 │ - const·b·=·2,·c·=·43; 4 │ + let·b·=·2,·c·=·43; 5 5 │ b = 4; 6 6 │ ++b; ``` ``` invalid.js:13:2 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign b because it's a constant 11 │ } 12 │ function f(d) { > 13 │ b++; │ ^ 14 │ } 15 │ const fn = (val) => { i This is where the variable is defined as constant 2 │ a = 2; 3 │ > 4 │ const b = 2, c = 43; │ ^ 5 │ b = 4; 6 │ ++b; i Unsafe fix: Replace const with let if you assign it to a new value. 2 2 │ a = 2; 3 3 │ 4 │ - const·b·=·2,·c·=·43; 4 │ + let·b·=·2,·c·=·43; 5 5 │ b = 4; 6 6 │ ++b; ``` ``` invalid.js:42:1 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign i because it's a constant 40 │ j: { l }, 41 │ } = { i: 1, j: { l: 2 } }; > 42 │ i = 4; │ ^ 43 │ l = 4; 44 │ i This is where the variable is defined as constant 38 │ const { > 39 │ i, │ ^ 40 │ j: { l }, 41 │ } = { i: 1, j: { l: 2 } }; i Unsafe fix: Replace const with let if you assign it to a new value. 36 36 │ }; 37 37 │ 38 │ - const·{ 38 │ + let·{ 39 39 │ i, 40 40 │ j: { l }, ``` ``` invalid.js:43:1 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign l because it's a constant 41 │ } = { i: 1, j: { l: 2 } }; 42 │ i = 4; > 43 │ l = 4; │ ^ 44 │ 45 │ for (const k in [1, 2]) { i This is where the variable is defined as constant 38 │ const { 39 │ i, > 40 │ j: { l }, │ ^ 41 │ } = { i: 1, j: { l: 2 } }; 42 │ i = 4; i Unsafe fix: Replace const with let if you assign it to a new value. 36 36 │ }; 37 37 │ 38 │ - const·{ 38 │ + let·{ 39 39 │ i, 40 40 │ j: { l }, ``` ``` invalid.js:46:2 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign k because it's a constant 45 │ for (const k in [1, 2]) { > 46 │ k = 4; │ ^ 47 │ } 48 │ i This is where the variable is defined as constant 43 │ l = 4; 44 │ > 45 │ for (const k in [1, 2]) { │ ^ 46 │ k = 4; 47 │ } i Unsafe fix: Replace const with let if you assign it to a new value. 43 43 │ l = 4; 44 44 │ 45 │ - for·(const·k·in·[1,·2])·{ 45 │ + for·(let·k·in·[1,·2])·{ 46 46 │ k = 4; 47 47 │ } ``` ``` invalid.js:50:1 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign p because it's a constant 49 │ const [p, { q }] = [1, { q: 2 }]; > 50 │ p = 3; │ ^ 51 │ q = 4; 52 │ i This is where the variable is defined as constant 47 │ } 48 │ > 49 │ const [p, { q }] = [1, { q: 2 }]; │ ^ 50 │ p = 3; 51 │ q = 4; i Unsafe fix: Replace const with let if you assign it to a new value. 47 47 │ } 48 48 │ 49 │ - const·[p,·{·q·}]·=·[1,·{·q:·2·}]; 49 │ + let·[p,·{·q·}]·=·[1,·{·q:·2·}]; 50 50 │ p = 3; 51 51 │ q = 4; ``` ``` invalid.js:51:1 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign q because it's a constant 49 │ const [p, { q }] = [1, { q: 2 }]; 50 │ p = 3; > 51 │ q = 4; │ ^ 52 │ 53 │ const { r, ...rest } = s; i This is where the variable is defined as constant 47 │ } 48 │ > 49 │ const [p, { q }] = [1, { q: 2 }]; │ ^ 50 │ p = 3; 51 │ q = 4; i Unsafe fix: Replace const with let if you assign it to a new value. 47 47 │ } 48 48 │ 49 │ - const·[p,·{·q·}]·=·[1,·{·q:·2·}]; 49 │ + let·[p,·{·q·}]·=·[1,·{·q:·2·}]; 50 50 │ p = 3; 51 51 │ q = 4; ``` ``` invalid.js:54:1 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign r because it's a constant 53 │ const { r, ...rest } = s; > 54 │ r = 4; │ ^ 55 │ 56 │ /*before*/const/*after*/ a = 0; i This is where the variable is defined as constant 51 │ q = 4; 52 │ > 53 │ const { r, ...rest } = s; │ ^ 54 │ r = 4; 55 │ i Unsafe fix: Replace const with let if you assign it to a new value. 51 51 │ q = 4; 52 52 │ 53 │ - const·{·r,·...rest·}·=·s; 53 │ + let·{·r,·...rest·}·=·s; 54 54 │ r = 4; 55 55 │ ``` ``` invalid.js:57:1 lint/correctness/noConstAssign FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Can't assign a because it's a constant 56 │ /*before*/const/*after*/ a = 0; > 57 │ a = 1; │ ^ 58 │ i This is where the variable is defined as constant 54 │ r = 4; 55 │ > 56 │ /*before*/const/*after*/ a = 0; │ ^ 57 │ a = 1; 58 │ i Unsafe fix: Replace const with let if you assign it to a new value. 54 54 │ r = 4; 55 55 │ 56 │ - /*before*/const/*after*/·a·=·0; 56 │ + /*before*/let/*after*/·a·=·0; 57 57 │ a = 1; 58 58 │ ```