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

[feat] Can you please provide sync API with async together? #756

Closed
JounQin opened this issue Apr 24, 2021 · 8 comments
Closed

[feat] Can you please provide sync API with async together? #756

JounQin opened this issue Apr 24, 2021 · 8 comments
Labels

Comments

@JounQin
Copy link

JounQin commented Apr 24, 2021

All APIs changed to be async in #75, but it would be great to still support legacy sync APIs.

I'm trying to integrate this tool to ESLint which does not support async rule for now.

So my proposal is to add lintTextSync, fixTextSync APIs, etc.

Some async rules like textlint-rule-no-dead-link won't work for sync API, that's OK, the user should just disable async rules if they want to use sync API.

If you agree, I'm glad to raise a PR for it.

@azu azu added the Status: Proposal Request for comments label Apr 24, 2021
@azu
Copy link
Member

azu commented Apr 24, 2021

I will not plan that implement sync API.
It will make some inconsistency(Parallel linting, async rule which you suggested) and It will grow maintenance cost.

ESLint will support async API in the future.
eslint/rfcs#42
In another way, sync-rpc may helps you.(I've not tested)

Also, textlint-rule-eslint integrate with ESLint.

@JounQin
Copy link
Author

JounQin commented Apr 24, 2021

ESLint will support async API in the future.

Yes, but it requires a long time to go.

In another way, sync-rpc may helps you.(I've not tested)

Thanks for this suggestion, I'll give it a try.

Also, textlint-rule-eslint integrate with ESLint.

It aims different things as my purpose, it runs ESLint for JavaScript codes just like eslint-plugin-markdown.

But what I'm doing is run textlint for all files as an ESLint plugin.

@JounQin
Copy link
Author

JounQin commented Apr 24, 2021

It will make some inconsistency(Parallel linting, async rule which you suggested) and It will grow maintenance cost.

Many tools support async/sync at the same time, and most of the logic codes could be shared.

unified#process
unified#processSync

cosmiconfig#async
cosmiconfig#sync

@JounQin
Copy link
Author

JounQin commented Apr 24, 2021

@azu I'm doing similar things for markuplint at the same time: markuplint/markuplint#155

We can test async and sync rules at the same time easily like above PR.

@azu
Copy link
Member

azu commented Apr 24, 2021

Comparing cosmiconfig is not fair.
That is the library. textlint is not a library.

unified support async plugin, but it just throws an Error on runSync.

var vfile = require("vfile");
var unified = require("unified");
var f = vfile("alpha");
var n = { type: "bravo" };
var e = { type: "charlie" };
const file = unified().use(plugin).runSync(n, f);
console.log(file);

function plugin() {
    return transformer;
}

async function transformer(tree, file) {
    console.log(tree, file);
    return e;
}

Error: runSync finished async. Use run instead

https://runkit.com/azu/6083a90f2912a2001a3a1fe8

In my experience, 20 - 30% of rules use async API.
Especially, almost 40 - 50% use async API in Japanese rules.
(These rules load a large dictionary like kuromojin)

Sync to async is easy, but the reverse is difficult.
I concern that sync API will be debt and I not want to implement/maintenance Sync API.

Thanks for suggestion.

@JounQin
Copy link
Author

JounQin commented Apr 24, 2021

Error: runSync finished async. Use run instead

Yes, I've mentioned:

Some async rules like textlint-rule-no-dead-link won't work for sync API, that's OK, the user should just disable async rules if they want to use sync API.


I concern that sync API will be debt and I not want to implement/maintenance Sync API.

That's unfortunately if you've decided that.

Or may I raise a PR first to see how difficult would it cost? That's OK if you decide not to merge that even.

@azu
Copy link
Member

azu commented Apr 25, 2021

Or may I raise a PR first to see how difficult would it cost? That's OK if you decide not to merge that even.

Yes!
It is good that discusses on implementation.

@azu
Copy link
Member

azu commented May 8, 2021

Closed by #757 (comment)

@azu azu closed this as completed May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants