content in fenced code blocks is checked for spelling after a blank comment line
lopopolo opened this issue · comments
Describe the bug
To Reproduce
Steps to reproduce the behaviour:
- A file containing:
// ```ruby
// def is_special_global_punct(ch)
// idx = (ch - 0x20) / 32;
// case idx
// when 0 then (4_227_980_502 >> (ch % 32)) & 1 > 0
// when 1 then (268_435_457 >> (ch % 32)) & 1 > 0
// when 2 then (1_073_741_825 >> (ch % 32)) & 1 > 0
// else
// false
// end
// end
//
// h = {}
// (0..255).each do |ch|
// h[ch.chr] = ch if is_special_global_punct(ch)
// end
// h.keys.map {|k| "b'#{k.inspect[1..-2]}'"}.join(" | ")
// ```
- Run
cargo spellcheck fix
- Observe the following errors:
error: spellcheck(Hunspell)
--> /Users/lopopolo/dev/artichoke/artichoke/spinoso-symbol/src/ident.rs:571
|
571 | [2.6.6] > chars.map(&:ord).map { |ch| bit(ch, 0) }.reduce(0, :|)
| ^^^
(12/316) Apply this suggestion [y,n,q,a,d,j,e,?]?
o rd
orb
org
odd
old
ore
Ford
Lord
word
ford
cord
lord
rd
or
» rod
`ord`
...
error: spellcheck(Hunspell)
--> /Users/lopopolo/dev/artichoke/artichoke/spinoso-symbol/src/ident.rs:573
|
573 | [2.6.6] > chars.map(&:ord).map { |ch| bit(ch, 1) }.reduce(0, :|)
| ^^^
(17/316) Apply this suggestion [y,n,q,a,d,j,e,?]?
o rd
orb
org
odd
old
ore
Ford
Lord
word
ford
cord
lord
rd
or
» rod
`ord`
...
error: spellcheck(Hunspell)
--> /Users/lopopolo/dev/artichoke/artichoke/spinoso-symbol/src/ident.rs:575
|
575 | [2.6.6] > chars.map(&:ord).map { |ch| bit(ch, 2) }.reduce(0, :|)
| ^^^
(22/316) Apply this suggestion [y,n,q,a,d,j,e,?]?
o rd
orb
org
odd
old
ore
Ford
Lord
word
ford
cord
lord
rd
or
» rod
`ord`
...
error: spellcheck(Hunspell)
--> /Users/lopopolo/dev/artichoke/artichoke/spinoso-symbol/src/ident.rs:595
|
595 | h[ch.chr] = ch if is_special_global_punct(ch)
| ^
(29/316) Apply this suggestion [y,n,q,a,d,j,e,?]?
h ch
huh
och
sch
» ch
`h`
...
error: spellcheck(Hunspell)
--> /Users/lopopolo/dev/artichoke/artichoke/spinoso-symbol/src/ident.rs:595
|
595 | h[ch.chr] = ch if is_special_global_punct(ch)
| ^^^
(30/316) Apply this suggestion [y,n,q,a,d,j,e,?]?
ch r
c hr
chm
chg
cur
cor
ctr
car
cir
chi
char
hr
» ch
`chr`
...
error: spellcheck(Hunspell)
--> /Users/lopopolo/dev/artichoke/artichoke/spinoso-symbol/src/ident.rs:597
|
597 | h.keys.map {|k| "b'#{k.inspect[1..-2]}'"}.join(" | ")
| ^^^
(34/316) Apply this suggestion [y,n,q,a,d,j,e,?]?
» mob's
`b'#`
error: spellcheck(Hunspell)
--> /Users/lopopolo/dev/artichoke/artichoke/spinoso-symbol/src/ident.rs:597
|
597 | h.keys.map {|k| "b'#{k.inspect[1..-2]}'"}.join(" | ")
| ^^
(35/316) Apply this suggestion [y,n,q,a,d,j,e,?]?
Bk
Mk
Gk
wk
bk
pk
» ck
`{k`
...
error: spellcheck(Hunspell)
--> /Users/lopopolo/dev/artichoke/artichoke/spinoso-symbol/src/ident.rs:597
|
597 | h.keys.map {|k| "b'#{k.inspect[1..-2]}'"}.join(" | ")
| ^^^^^^^
(36/316) Apply this suggestion [y,n,q,a,d,j,e,?]?
inspect 1
inspects
» inspect
`inspect`
...
This snippet does not lint:
// ```ruby
// def is_special_global_punct(ch)
// idx = (ch - 0x20) / 32;
// case idx
// when 0 then (4_227_980_502 >> (ch % 32)) & 1 > 0
// when 1 then (268_435_457 >> (ch % 32)) & 1 > 0
// when 2 then (1_073_741_825 >> (ch % 32)) & 1 > 0
// else
// false
// end
// end
// h = {}
// (0..255).each do |ch|
// h[ch.chr] = ch if is_special_global_punct(ch)
// end
// h.keys.map {|k| "b'#{k.inspect[1..-2]}'"}.join(" | ")
// ```
Expected behavior
Neither code snippet finds spelling errors.
Please complete the following information:
- System: macOS
- Obtained:
cargo install
- Version:
cargo-spellcheck 0.11.0
Additional context
A shorter example I saw this with was:
// ```c
// MRB_API void mrb_str_modify_keep_ascii(mrb_state *mrb, struct RString *s)
//
// MRB_API void mrb_str_modify(mrb_state *mrb, struct RString *s)
// ```
whereas this does not lint:
// ```c
// MRB_API void mrb_str_modify_keep_ascii(mrb_state *mrb, struct RString *s)
// MRB_API void mrb_str_modify(mrb_state *mrb, struct RString *s)
// ```
I can reproduce this, but only with doc comments (///
rather than //
).
Turns out empty lines are removed too early, and hence clustering does not work for continuous comments and hence creates two (very messed up) clusters.
it actually was ok, the decendants_with_tokens
does remove empty comment lines, so replacing this with decendents
will resolve the issue, but is not as trivial as it sounds 🙃From
impl uses a regex that did not hold
v0.11.1
just hit https://crates.io/crates/cargo-spellcheck which includes #258 which fixes the issue. Thanks for reporting!
yay I can confirm this fixes things in my codebase! thank you for getting a fix out!