Skip to content

Add fixes property #13

Open
Open
@remcohaszing

Description

Initial checklist

Problem

I have been working on unifiedjs/unified-language-server#13. On top of those changes I have been developing quick fixes based on the expected property of vfile messages. This works, but it’s very limited.

Screencast_2021-12-18_12.38.29.mp4

It now works by replacing the entire reported unist position with a string value from the expected array.

This works fine for retext-sentence-spacing:double-space, because it reports a small range. Although a more descriptive text for the action would be nice. All properties on vfile messages can be used to construct this description.

Currently this is: 'Fix: ' + diagnostic.message

Probably better alternatives would be something like: 'Replace “' + actual + '” with + “' + expected + '”'

However, for remark-lint:unordered-list-marker-style this is going to be harder to do, because the entire node is reported. It would be nice to only use the first character for autofixing.

I’m missing the following data for making a proper quick fix:

  1. A human readable description of the quick fix.
  2. A custom range for the quick fix.

Solution

Add a new property fixes which should contain an array of the following shape:

interface VFileMessageFix {
  description?: string;
  position: import('unist').Position;
  replacement: string;
}

Alternatives

It would be possible to support custom fixer functions instead of or in addition of text replacements.


Report smaller ranges.

remark-lint:unordered-list-marker-style is a good example of a rule which could narrow the reported range to a single character (the actual list marker).

Even then a custom description for the change could be nice.


Reuse the expected field to allow this shape in addition to strings.

Metadata

Assignees

No one assigned

    Labels

    🤞 phase/openPost is being triaged manually

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions