Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest API #1122

Open
1 of 4 tasks
azu opened this issue Mar 24, 2023 · 1 comment
Open
1 of 4 tasks

Suggest API #1122

azu opened this issue Mar 24, 2023 · 1 comment
Labels
Status: Proposal Request for comments

Comments

@azu
Copy link
Member

azu commented Mar 24, 2023

Purpose

We want to support suggestion on editor like VSCode.
--fix is useful but it provide only a single suggestion.
Also, User can not excludes some fix that is not want to fix.

Some rules want to provide multiple suggestions.
This proposal will near to current fix property.

LLM (Large Language Model) checking is becoming more and more practical.
On the other hand, machine learning-based is not an automatic modification like Lint, but is more appropriate for users to select modifications. This is because it is a matter of probability.

This requires user-oriented interactivity.

Proposal

  • Add suggest property to RuleError
    • suggest should have an array of object that has id and fix and message property
  • The suggest property will be into TextlintMessage
  • textlint cli may does not provide fixing function the suggest at first
const reporter = (context) => {
    const { Syntax, RuleError, fixer, report, getSource } = context;
    return {
        [Syntax.Str](node) {
            const text = getSource(node);
            // "You fix this"
            //      ^^^
            const matchRegexp = /\bfix\b/;
            if (!matchRegexp.test(text)) {
                return;
            }
            // found "fixable" error
            const index = text.search(matchRegexp);
            const length = "fix".length;
            report(
                node,
                new RuleError("Replaced", {
                    index,
                    suggest: [
                        {
                            id: "pattern1",
                            message: "pattern 1",
                            fix: fixer.replaceTextRange([index, index + length], "fixed 1")
                        },
                        {
                            id: "pattern2",
                            message: "pattern 2",
                            fix: fixer.replaceTextRange([index, index + length], "fixed 2")
                        }
                    ]
                })
            );
        }
    };
};
export default {
    linter: reporter,
    fixer: reporter
};

TODO:

  • Message Format
  • Suggest API is required?
    • new RuleSuggest(message, { suggest: [ ... ] }) or new RuleError(message, { serverity: "info" })
    • Current RuleError will be an error
  • How to handle this by textlint CLI?

Similar Works:

@azu
Copy link
Member Author

azu commented Mar 29, 2023

An editor like vscode-textlint can use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Proposal Request for comments
Projects
None yet
Development

No branches or pull requests

1 participant