--- source: crates/biome_js_analyze/tests/spec_tests.rs expression: invalid.ts --- # Input ```ts x!; x!.y; x.y!; !x!.y; x!.y?.z; x![y]; x![y]?.z; x.y.z!(); x.y?.z!(); x!!!; x!!.y; x.y!!; x.y.z!!(); x!?.[y].z; x!?.y.z; x!!!?.y.z; x.y.z!?.(); x.y.z!!!?.(); (b! as number) = "test"; (b!! as number) = "test"; x[y.z!]; ``` # Diagnostics ``` invalid.ts:1:1 lint/style/noNonNullAssertion ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. > 1 │ x!; │ ^^ 2 │ x!.y; 3 │ x.y!; ``` ``` invalid.ts:2:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 1 │ x!; > 2 │ x!.y; │ ^^ 3 │ x.y!; 4 │ !x!.y; i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 1 1 │ x!; 2 │ - x!.y; 2 │ + x?.y; 3 3 │ x.y!; 4 4 │ !x!.y; ``` ``` invalid.ts:3:1 lint/style/noNonNullAssertion ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 1 │ x!; 2 │ x!.y; > 3 │ x.y!; │ ^^^^ 4 │ !x!.y; 5 │ x!.y?.z; ``` ``` invalid.ts:4:2 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 2 │ x!.y; 3 │ x.y!; > 4 │ !x!.y; │ ^^ 5 │ x!.y?.z; 6 │ x![y]; i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 2 2 │ x!.y; 3 3 │ x.y!; 4 │ - !x!.y; 4 │ + !x?.y; 5 5 │ x!.y?.z; 6 6 │ x![y]; ``` ``` invalid.ts:5:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 3 │ x.y!; 4 │ !x!.y; > 5 │ x!.y?.z; │ ^^ 6 │ x![y]; 7 │ x![y]?.z; i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 3 3 │ x.y!; 4 4 │ !x!.y; 5 │ - x!.y?.z; 5 │ + x?.y?.z; 6 6 │ x![y]; 7 7 │ x![y]?.z; ``` ``` invalid.ts:6:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 4 │ !x!.y; 5 │ x!.y?.z; > 6 │ x![y]; │ ^^ 7 │ x![y]?.z; 8 │ x.y.z!(); i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 4 4 │ !x!.y; 5 5 │ x!.y?.z; 6 │ - x![y]; 6 │ + x?.[y]; 7 7 │ x![y]?.z; 8 8 │ x.y.z!(); ``` ``` invalid.ts:7:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 5 │ x!.y?.z; 6 │ x![y]; > 7 │ x![y]?.z; │ ^^ 8 │ x.y.z!(); 9 │ x.y?.z!(); i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 5 5 │ x!.y?.z; 6 6 │ x![y]; 7 │ - x![y]?.z; 7 │ + x?.[y]?.z; 8 8 │ x.y.z!(); 9 9 │ x.y?.z!(); ``` ``` invalid.ts:8:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 6 │ x![y]; 7 │ x![y]?.z; > 8 │ x.y.z!(); │ ^^^^^^ 9 │ x.y?.z!(); 10 │ x!!!; i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 6 6 │ x![y]; 7 7 │ x![y]?.z; 8 │ - x.y.z!(); 8 │ + x.y.z?.(); 9 9 │ x.y?.z!(); 10 10 │ x!!!; ``` ``` invalid.ts:9:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 7 │ x![y]?.z; 8 │ x.y.z!(); > 9 │ x.y?.z!(); │ ^^^^^^^ 10 │ x!!!; 11 │ x!!.y; i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 7 7 │ x![y]?.z; 8 8 │ x.y.z!(); 9 │ - x.y?.z!(); 9 │ + x.y?.z?.(); 10 10 │ x!!!; 11 11 │ x!!.y; ``` ``` invalid.ts:10:1 lint/style/noNonNullAssertion ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 8 │ x.y.z!(); 9 │ x.y?.z!(); > 10 │ x!!!; │ ^^^^ 11 │ x!!.y; 12 │ x.y!!; ``` ``` invalid.ts:11:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 9 │ x.y?.z!(); 10 │ x!!!; > 11 │ x!!.y; │ ^^^ 12 │ x.y!!; 13 │ x.y.z!!(); i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 9 9 │ x.y?.z!(); 10 10 │ x!!!; 11 │ - x!!.y; 11 │ + x?.y; 12 12 │ x.y!!; 13 13 │ x.y.z!!(); ``` ``` invalid.ts:12:1 lint/style/noNonNullAssertion ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 10 │ x!!!; 11 │ x!!.y; > 12 │ x.y!!; │ ^^^^^ 13 │ x.y.z!!(); 14 │ x!?.[y].z; ``` ``` invalid.ts:13:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 11 │ x!!.y; 12 │ x.y!!; > 13 │ x.y.z!!(); │ ^^^^^^^ 14 │ x!?.[y].z; 15 │ x!?.y.z; i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 11 11 │ x!!.y; 12 12 │ x.y!!; 13 │ - x.y.z!!(); 13 │ + x.y.z?.(); 14 14 │ x!?.[y].z; 15 15 │ x!?.y.z; ``` ``` invalid.ts:14:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 12 │ x.y!!; 13 │ x.y.z!!(); > 14 │ x!?.[y].z; │ ^^ 15 │ x!?.y.z; 16 │ x!!!?.y.z; i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 14 │ x!?.[y].z; │ - ``` ``` invalid.ts:15:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 13 │ x.y.z!!(); 14 │ x!?.[y].z; > 15 │ x!?.y.z; │ ^^ 16 │ x!!!?.y.z; 17 │ x.y.z!?.(); i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 15 │ x!?.y.z; │ - ``` ``` invalid.ts:16:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 14 │ x!?.[y].z; 15 │ x!?.y.z; > 16 │ x!!!?.y.z; │ ^^^^ 17 │ x.y.z!?.(); 18 │ x.y.z!!!?.(); i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 16 │ x!!!?.y.z; │ --- ``` ``` invalid.ts:17:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 15 │ x!?.y.z; 16 │ x!!!?.y.z; > 17 │ x.y.z!?.(); │ ^^^^^^ 18 │ x.y.z!!!?.(); 19 │ (b! as number) = "test"; i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 17 │ x.y.z!?.(); │ - ``` ``` invalid.ts:18:1 lint/style/noNonNullAssertion FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 16 │ x!!!?.y.z; 17 │ x.y.z!?.(); > 18 │ x.y.z!!!?.(); │ ^^^^^^^^ 19 │ (b! as number) = "test"; 20 │ (b!! as number) = "test"; i Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator 18 │ x.y.z!!!?.(); │ --- ``` ``` invalid.ts:19:2 lint/style/noNonNullAssertion ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 17 │ x.y.z!?.(); 18 │ x.y.z!!!?.(); > 19 │ (b! as number) = "test"; │ ^^ 20 │ (b!! as number) = "test"; 21 │ x[y.z!]; ``` ``` invalid.ts:20:2 lint/style/noNonNullAssertion ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 18 │ x.y.z!!!?.(); 19 │ (b! as number) = "test"; > 20 │ (b!! as number) = "test"; │ ^^^ 21 │ x[y.z!]; 22 │ ``` ``` invalid.ts:21:3 lint/style/noNonNullAssertion ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Forbidden non-null assertion. 19 │ (b! as number) = "test"; 20 │ (b!! as number) = "test"; > 21 │ x[y.z!]; │ ^^^^ 22 │ ```