drahnr / cargo-spellcheck

Checks all your documentation for spelling and grammar mistakes with hunspell and a nlprule based checker for grammar
Apache License 2.0
326 stars 33 forks source link

fenced code blocks in comments are not ignored if they contain an unpaired backtick #256

Closed lopopolo closed 2 years ago

lopopolo commented 2 years ago

Describe the bug

If a comment contains a fenced code block (one that starts with three backticks), that code block is usually ignored.

When the code block contains a single unpaired backtick, the block is spellchecked.

To Reproduce

Steps to reproduce the behaviour:

  1. A file containing:
    // From `spec/core/symbol/inspect_spec.rb`:
    //
    // ```ruby
    // symbols = {
    //   fred:         ":fred",
    //   :fred?     => ":fred?",
    //   :fred!     => ":fred!",
    //   :$ruby     => ":$ruby",
    //   :@ruby     => ":@ruby",
    //   :@@ruby    => ":@@ruby",
    //   :"$ruby!"  => ":\"$ruby!\"",
    //   :"$ruby?"  => ":\"$ruby?\"",
    //   :"@ruby!"  => ":\"@ruby!\"",
    //   :"@ruby?"  => ":\"@ruby?\"",
    //   :"@@ruby!" => ":\"@@ruby!\"",
    //   :"@@ruby?" => ":\"@@ruby?\"",
    //
    //   :$-w       => ":$-w",
    //   :"$-ww"    => ":\"$-ww\"",
    //   :"$+"      => ":$+",
    //   :"$~"      => ":$~",
    //   :"$:"      => ":$:",
    //   :"$?"      => ":$?",
    //   :"$<"      => ":$<",
    //   :"$_"      => ":$_",
    //   :"$/"      => ":$/",
    //   :"$'"      => ":$'",
    //   :"$\""     => ":$\"",
    //   :"$$"      => ":$$",
    //   :"$."      => ":$.",
    //   :"$,"      => ":$,",
    //   :"$`"      => ":$`",
    //   :"$!"      => ":$!",
    //   :"$;"      => ":$;",
    //   :"$\\"     => ":$\\",
    //   :"$="      => ":$=",
    //   :"$*"      => ":$*",
    //   :"$>"      => ":$>",
    //   :"$&"      => ":$&",
    //   :"$@"      => ":$@",
    //   :"$1234"   => ":$1234",
    //
    //   :-@        => ":-@",
    //   :+@        => ":+@",
    //   :%         => ":%",
    //   :&         => ":&",
    //   :*         => ":*",
    //   :**        => ":**",
    //   :"/"       => ":/",     # lhs quoted for emacs happiness
    //   :<         => ":<",
    //   :<=        => ":<=",
    //   :<=>       => ":<=>",
    //   :==        => ":==",
    //   :===       => ":===",
    //   :=~        => ":=~",
    //   :>         => ":>",
    //   :>=        => ":>=",
    //   :>>        => ":>>",
    //   :[]        => ":[]",
    //   :[]=       => ":[]=",
    //   :"\<\<"    => ":\<\<",
    //   :^         => ":^",
    //   :"`"       => ":`",     # for emacs, and justice!
    //   :~         => ":~",
    //   :|         => ":|",
    //
    //   :"!"       => [":\"!\"",  ":!" ],
    //   :"!="      => [":\"!=\"", ":!="],
    //   :"!~"      => [":\"!~\"", ":!~"],
    //   :"\$"      => ":\"$\"", # for justice!
    //   :"&&"      => ":\"&&\"",
    //   :"'"       => ":\"\'\"",
    //   :","       => ":\",\"",
    //   :"."       => ":\".\"",
    //   :".."      => ":\"..\"",
    //   :"..."     => ":\"...\"",
    //   :":"       => ":\":\"",
    //   :"::"      => ":\"::\"",
    //   :";"       => ":\";\"",
    //   :"="       => ":\"=\"",
    //   :"=>"      => ":\"=>\"",
    //   :"\?"      => ":\"?\"", # rawr!
    //   :"@"       => ":\"@\"",
    //   :"||"      => ":\"||\"",
    //   :"|||"     => ":\"|||\"",
    //   :"++"      => ":\"++\"",
    //
    //   :"\""      => ":\"\\\"\"",
    //   :"\"\""    => ":\"\\\"\\\"\"",
    //
    //   :"9"       => ":\"9\"",
    //   :"foo bar" => ":\"foo bar\"",
    //   :"*foo"    => ":\"*foo\"",
    //   :"foo "    => ":\"foo \"",
    //   :" foo"    => ":\" foo\"",
    //   :" "       => ":\" \"",
    // }
    // ```
  2. Run cargo spellcheck edit
  3. Observe these spelling errors:

    error: spellcheck(Hunspell)
      --> /Users/lopopolo/dev/artichoke/artichoke/spinoso-symbol/src/inspect.rs:796
       |
    796 |    :"/"       => ":/",     # lhs quoted for emacs happiness
       |                              ^^^
    
    (122/284) Apply this suggestion [y,n,q,a,d,j,e,?]?
    
     laths
     lbs
     ohs
    » ls
     `lhs`
     ...
    error: spellcheck(Hunspell)
      --> /Users/lopopolo/dev/artichoke/artichoke/spinoso-symbol/src/inspect.rs:796
       |
    796 |    :"/"       => ":/",     # lhs quoted for emacs happiness
       |                                             ^^^^^
    
    (123/284) Apply this suggestion [y,n,q,a,d,j,e,?]?
    
     emaciates
     e macs
     maces
     macs
    » Emacs
     `emacs`
     ...
    error: spellcheck(Hunspell)
      --> /Users/lopopolo/dev/artichoke/artichoke/spinoso-symbol/src/inspect.rs:810
       |
    810 |    :"`"       => ":`",     # for emacs, and justice!
       |                                  ^^^^^
    
    (194/284) Apply this suggestion [y,n,q,a,d,j,e,?]?
    
     emaciates
     e macs
     maces
     macs
    » Emacs
     `emacs`
     ...
    error: spellcheck(Hunspell)
      --> /Users/lopopolo/dev/artichoke/artichoke/spinoso-symbol/src/inspect.rs:829
       |
    829 |    :"\?"      => ":\"?\"", # rawr!
       |                              ^^^^
    
    (249/284) Apply this suggestion [y,n,q,a,d,j,e,?]?
    
     raw r
     rawer
    » raw
     `rawr`
     ...

Expected behavior

Screenshots

Please complete the following information:

Additional context

lopopolo commented 2 years ago

Now that I've also filed https://github.com/drahnr/cargo-spellcheck/issues/257, I'm not sure if these two issues are the same because the sample snippet includes empty lines in the fenced code block comment.

drahnr commented 2 years ago

Hey @lopopolo , thanks for reporting this and #257 , I very much appreciate it!

Indeed, this seems to be duplicate of #257 .