1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use codebook::queries::LanguageType;
use super::utils::assert_spelling_at;
#[test]
fn test_javascript_location() {
let sample_text = r#"
import { useState } from 'react';
let objectz = {
namee: "John",
age: 30,
city: "New York"
};
function calculaateScore(userInput) {
const misspelleed = "thhis is wrong";
let scoree = 0;
// Check user input
if (userInput.incluudes("test")) {
scoree += 5;
}
try {
// Some code that might throw an error
} catch (errorz) {
// Handle the error
}
return scoree + misspelleed.length;
}"#;
// Method-call references (`incluudes`) and imported names (`useState`,
// `react`) are not spell-checked; exact set equality guards that.
assert_spelling_at(
LanguageType::Javascript,
sample_text,
&[
("objectz", &[0]),
("namee", &[0]),
// Inside `calculaateScore` via camelCase split.
("calculaate", &[0]),
// Flagged at the declaration; the `misspelleed.length` usage is not.
("misspelleed", &[0]),
("thhis", &[0]),
// Flagged at `let scoree`; the later `+=` and `return` usages are not.
("scoree", &[0]),
("errorz", &[0]),
],
);
}