caderek / gramma

command-line grammar checker
https://caderek.github.io/gramma/
ISC License
252 stars 18 forks source link

Gramma incorrectly handles inline code spans in markdown #50

Open JohnForster opened 3 months ago

JohnForster commented 3 months ago

Describe the bug When using inline codespans in markdown mode, eg:

"Navigate to `/path/to/file` in your directory"

Gramma incorrectly identifies a double space, ie. the one before and the one after the code span.

A similar error occurs with commas, eg:

"Does Go have arithmetic operators like `++`, `+=`, `*=` or `--`?"

It appears that Gramma is stripping the codespan from the string before analysis, without accounting for the fact that something else was there. See the sentence field in the result below.

To Reproduce Minimal reproduction (NodeJS)

const gramma = require("gramma");

const options = {
  language: "en-GB",
  dictionary: ["npm", "gramma"],
  markdown: true,
};

const string = "Delete the `loginResult` variable.";

gramma.check(string, options).then((results) => console.log(results.matches));

Expected behavior No errors should be found in this text.

Actual behaviour

[
  {
    message: 'It seems like there are too many consecutive spaces here.',
    shortMessage: '',
    replacements: [ [Object] ],
    offset: 10,
    length: 15,
    context: {
      text: 'Delete the `loginResult` variable.',
      offset: 10,
      length: 15
    },
    sentence: 'Delete the  variable.',
    type: { typeName: 'Other' },
    rule: {
      id: 'CONSECUTIVE_SPACES',
      subId: '1',
      sourceFile: 'grammar.xml',
      description: 'Two consecutive spaces',
      issueType: 'typographical',
      category: [Object],
      isPremium: false,
      confidence: 0.47
    },
    ignoreForIncompleteSentence: true,
    contextForSureMatch: -1,
    word: ' `loginResult` '
  }
]

Desktop (please complete the following information):