Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ tree-sitter-python = "<0.26.0"
tree-sitter-r = "1.1.0"
tree-sitter-ruby = "0.23.1"
tree-sitter-rust = "<0.25.0"
tree-sitter-svelte-ng = "1.0.2"
tree-sitter-swift = "<0.8.0"
tree-sitter-toml-ng = "<0.8.0"
tree-sitter-typescript = "0.23.2"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ Codebook is in active development. As better dictionaries are added, words that
| Python | ✅ |
| Ruby | ✅ |
| Rust | ✅ |
| Svelte | ⚠️ |
| Swift | ⚠️ |
| TOML | ✅ |
| TypeScript | ✅ |
Expand Down
1 change: 1 addition & 0 deletions crates/codebook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ tree-sitter-rust.workspace = true
tree-sitter-swift.workspace = true
tree-sitter-toml-ng.workspace = true
tree-sitter-typescript.workspace = true
tree-sitter-svelte-ng.workspace = true
tree-sitter-vhdl.workspace = true
codebook-tree-sitter-typst.workspace = true
tree-sitter-yaml.workspace = true
Expand Down
4 changes: 4 additions & 0 deletions crates/codebook/src/dictionaries/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ static TEXT_DICTIONARIES: LazyLock<Vec<TextRepo>> = LazyLock::new(|| {
"csharp",
"https://raw.githubusercontent.com/streetsidesoftware/cspell-dicts/refs/heads/main/dictionaries/csharp/csharp.txt",
),
TextRepo::new(
"svelte",
"https://raw.githubusercontent.com/streetsidesoftware/cspell-dicts/refs/heads/main/dictionaries/svelte/src/svelte.txt",
),
]
});

Expand Down
9 changes: 9 additions & 0 deletions crates/codebook/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum LanguageType {
R,
Ruby,
Rust,
Svelte,
Swift,
TOML,
Text,
Expand Down Expand Up @@ -177,6 +178,13 @@ pub static LANGUAGE_SETTINGS: &[LanguageSetting] = &[
query: include_str!("queries/go.scm"),
extensions: &["go"],
},
LanguageSetting {
type_: LanguageType::Svelte,
ids: &["svelte"],
dictionary_ids: &["svelte"],
query: include_str!("queries/svelte.scm"),
extensions: &["svelte"],
},
LanguageSetting {
type_: LanguageType::Swift,
ids: &["swift"],
Expand Down Expand Up @@ -319,6 +327,7 @@ impl LanguageSetting {
LanguageType::R => Some(tree_sitter_r::LANGUAGE.into()),
LanguageType::Ruby => Some(tree_sitter_ruby::LANGUAGE.into()),
LanguageType::Rust => Some(tree_sitter_rust::LANGUAGE.into()),
LanguageType::Svelte => Some(tree_sitter_svelte_ng::LANGUAGE.into()),
LanguageType::Swift => Some(tree_sitter_swift::LANGUAGE.into()),
LanguageType::TOML => Some(tree_sitter_toml_ng::LANGUAGE.into()),
LanguageType::Text => None,
Expand Down
17 changes: 17 additions & 0 deletions crates/codebook/src/queries/svelte.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; HTML comments
(comment) @comment

; Visible text nodes between HTML tags
(text) @string

; Quoted attribute values — e.g. alt="descriptoin", title="Wellcome"
(quoted_attribute_value) @string

; JavaScript / TypeScript inside <script> and <script lang="ts"> blocks.
; Captured as text so string literals and identifiers are spell-checked.
(script_element
(raw_text) @string)

; CSS / SCSS inside <style> and <style lang="scss"> blocks.
(style_element
(raw_text) @string)
71 changes: 71 additions & 0 deletions crates/codebook/tests/test_svelte.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use codebook::queries::LanguageType;

mod utils;

#[test]
fn test_svelte_html() {
utils::init_logging();
let sample_text = r#"
<main>
<h1>Welcom to my app</h1>
<p>Enjoye your stay, pleaze report bugs.</p>
</main>"#;

let processor = utils::get_processor();
let misspelled = processor
.spell_check(sample_text, Some(LanguageType::Svelte), None)
.to_vec();
println!("Misspelled: {misspelled:#?}");

assert_eq!(misspelled.len(), 3);
assert!(misspelled.iter().any(|w| w.word == "Welcom"));
assert!(misspelled.iter().any(|w| w.word == "Enjoye"));
assert!(misspelled.iter().any(|w| w.word == "pleaze"));
}

#[test]
fn test_svelte_script() {
utils::init_logging();
let sample_text = r#"
<script>
const mesage = "Helo Wrold";
let naeme = 'Welcom back';
</script>"#;

let processor = utils::get_processor();
let misspelled = processor
.spell_check(sample_text, Some(LanguageType::Svelte), None)
.to_vec();
println!("Misspelled: {misspelled:#?}");

assert_eq!(misspelled.len(), 5);
assert!(misspelled.iter().any(|w| w.word == "mesage"));
assert!(misspelled.iter().any(|w| w.word == "Helo"));
assert!(misspelled.iter().any(|w| w.word == "Wrold"));
assert!(misspelled.iter().any(|w| w.word == "naeme"));
assert!(misspelled.iter().any(|w| w.word == "Welcom"));
}

#[test]
fn test_svelte_style() {
utils::init_logging();
let sample_text = r#"
<style>
.card {
backgrond-color: #fff;
font-wieght: bold;
bordre: 1px solid #ccc;
}
</style>"#;

let processor = utils::get_processor();
let misspelled = processor
.spell_check(sample_text, Some(LanguageType::Svelte), None)
.to_vec();
println!("Misspelled: {misspelled:#?}");

assert_eq!(misspelled.len(), 3);
assert!(misspelled.iter().any(|w| w.word == "backgrond"));
assert!(misspelled.iter().any(|w| w.word == "wieght"));
assert!(misspelled.iter().any(|w| w.word == "bordre"));
}
Loading