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

Supports rules that are written as ECMAScript Modules #868

Closed
2 tasks done
Tracked by #902
azu opened this issue May 25, 2022 · 5 comments · Fixed by #965
Closed
2 tasks done
Tracked by #902

Supports rules that are written as ECMAScript Modules #868

azu opened this issue May 25, 2022 · 5 comments · Fixed by #965
Labels
Status: Proposal Request for comments

Comments

@azu
Copy link
Member

azu commented May 25, 2022

Currently, textlint can not load a rule that is ECMAScript Modules(ESM).

It means that textlint-module-loader.ts use Dynamic Import instead of require to load a rule module.

This issue aim to support to load a rule that is written by ESM.
It is not that rewrite textlint to ESM.

  • Current: require() in CJS can not load ESM, It only load CJS
  • Next(This issue): import() in CJS can load ESM and CJS

TODO

@azu

This comment was marked as outdated.

@azu
Copy link
Member Author

azu commented Sep 10, 2022

  1. Refactor Config
  2. use dynamic import for loading rule/plugin

@azu azu mentioned this issue Sep 19, 2022
4 tasks
@azu
Copy link
Member Author

azu commented Dec 25, 2022

Change to Async:

flowchart LR
   A[Load Config File] --> B[Load Modules]
Loading

@azu
Copy link
Member Author

azu commented Dec 25, 2022

We will introduce new API like createTextlint for supporting Async APIs.
v13 continue to support current TextLintEngine and TextFixEngine for backward compatible.

New createTextlint support ESM rules/plugins.
In other hands, TextLintEngine and TextFixEngine can not support ESM rules/plugins.

https://github.com/textlint/textlint/blob/60cea514f7eaefbff4411087d16a51daf68f12a4/packages/textlint/src/index.ts

API Description Behavior Target Platform Current Status Next Status
cli Command LIne Interface Async Node.js ✅ (Use createTextlint internally)
textlint TextLintCore alias Async Node.js/CommonJS ❌ Deprecated ❌ Deprecated
TextLintCore Old API. It is Procedural API. Lint Only Single File. Recommended to use @texltint/kernel module instead of It. Async Node.js/CommonJS ❌ Deprecated ❌ Deprecated
TextLintEngine Lint Engine API. It load .textlintrc automaticaly ◉ Loading is Sync
◉ Linting is Async
Node.js/CommonJS ✅ Recommended ❌ Deprecated
TextFixEngine Fix Engine API. It load .textlintrc automaticaly ◉ Loading is Sync
◉ Fixing is Async
Node.js/CommonJS ✅ Recommended ❌ Deprecated
createLinter Combine TextLintEngine and TextFixEngine. Support Async APIs. ◉ Loading is Async
◉ Linting/Fixing is Async
Node.js/CommonJS and ESM None ✅ Recommended

@azu azu changed the title Supports rules that are ECMAScript Modules Supports rules that are written as ECMAScript Modules Dec 25, 2022
@azu
Copy link
Member Author

azu commented Dec 26, 2022

We have two config

  • .textlintrc config file
  • CLI options - It override textlintrc

It is just idea that we can implement these as separated loader and merge these.

image

type Loader = (_:unknown) => Promise<Config>;
const config = mergeConfig({
 await configFileLoader(),
 await cliLoader()
});

createTextlint({
  config
});

// OR
createTextlint({
  loaders: [configFileLoader(), cliLoader()]
});

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
1 participant