Closed samjcombs closed 10 months ago
Welcome @samjcombs! :wave: Thanks for the time and consideration, improving the developer experience is definitely a continuing goal for the project.
I have been looking into how to achieve this but before I dive in completely I was wondering if theres a simple option to turn a rule into a write rule instead of just a warning reporter.
Not currently, see https://github.com/remarkjs/remark-lint/issues/82 There is ongoing discussion on the approach, your thoughts and insights are welcome on the thread.
no-undefined-references no-unused-definitions
I'd be cautious outright removing the reference or definitions as a fix. I see there being (at least) three cases.
[aside]
becomes \[aside\]
)[a-real-reference-typo]
should suggest, "reference is undefined did you mean [a-real-reference]
?")Given that there are multiple scenarios, I'm not sure remark-lint
should take automatic action even if it could.
This feels like something where an integration with https://github.com/remarkjs/vscode-remark would be a better fit, allowing the user to choose from a list of potential fixes.
no-duplicate-definitions
I'm not sure the value of adding a comment would have here. It doesn't fix the error, and it contains the same information an error message would have. So the error message may be fine?
Given your interest in fixes. I'd highly recommend reading through https://github.com/remarkjs/remark-lint/issues/82 and chiming in with ideas. As well as checking out https://github.com/remarkjs/vscode-remark, I could definitely see a tie-in between multiple fix options, which require user feedback, and the language server.
@samjcombs thoughts on the above? Is thing something you'd be interested in working on?
remark-language-server
/ vscode-remark
gives suggestions based on the expected
property of reported messages. Let’s say you have this message, it will show a quick fix suggestion to remove the reference:
const message = new VFileMessage('Undefined reference [foo]', nodeOrPosition, 'remark-lint:no-undefined-references')
message.expected = ['foo']
For removal, suggest an empty string.
const message = new VFileMessage('Duplicate reference [foo]', nodeOrPosition, 'remark-lint:no-duplicate-definitions')
message.expected = ['']
This expected
property is provided by quite a lot of retext
plugins, but not remark-lint
plugins. I definitely see value to add several of those.
This doesn’t provide an option to fix all issues with a single command though.
Closing as is discussed in GH-82.
Adding actual
/expected
fields can be done in separately PRs!
Duplicate of #82
Hi! This was closed. Team: If this was fixed, please add phase/solved
. Otherwise, please add one of the no/*
labels.
Hi! Thanks for taking the time to contribute!
Because we treat issues as our backlog, we close duplicates to focus our work and not have to touch the same chunk of code for the same reason multiple times. This is also why we may mark something as duplicate that isn’t an exact duplicate but is closely related.
Thanks, — bb
Initial checklist
Problem
It would be great if these three rules:
no-undefined-references
no-duplicate-definitions
no-unused-definitions
had a--fix
or--output
option to do the following:no-undefined-references
- remove the brackets around the undefined referenceno-duplicate-definitions
- add a comment to each duplicate so the user can decide which one to keepno-unused-definitions
- remove the definition entirelyI have been looking into how to achieve this but before I dive in completely I was wondering if theres a simple option to turn a rule into a write rule instead of just a warning reporter.
Great work on this repo, very impressive stuff here!
Solution
For
no-undefined-references
Given this input:
Desired output:
For
no-duplicate-definitions
Given this input:
Desired output:
For
no-unused-definitions
Given this input:
Desired output:
Alternatives
I tried piping the output of the cli with these three rules enabled to a script that would parse it and determine where to do file edits, but it got too complicated as lots of work has to be done to make sure that when it starts editing the file, future edits take into account what was already removed and translate positions of everything accordingly. All in all, not a good solution.
Another option I've been toying with is to use these rules to output the AST tree instead of the files, and then parse through that AST and perform the modifications, but I'm not sure how I'd find the violating AST nodes, unless these rules actually add
isAllowed
to the ast nodes themselves.Open to other solutions here and it may be easier to do this on a rule by rule basis.
But an abstract solution to provide a
fix
andfix options
for each rule would be great, so users could say, for nodes that violate this rule, fix it in this way.Thanks much!