Closed ryo-funaba closed 1 year ago
@azu PR is here
I found a same issue in this repo.
That issue was closed by ESM..?
https://github.com/textlint-rule/textlint-rule-alex/issues/13
https://github.com/get-alex/alex/issues/319
Alex only fix this issue in 10.0.0.
10.0.0 use pure ESM. It disallow to require("alex")
.
textlint does not support Pure ESM rule yet. https://github.com/textlint/textlint/issues/868
Two options:
import("alex")
) in this ruls
import(...)
instead of import x from "..."
1's blocker is interop issue between CJS and ESM.
2 is just using Dynamic Import for alex@10.
Node.js disallow to import ESM from CJS using import x from "mod"
statement .
However, Node.js allow to import ESM from CJS using const x = await import("mod")
.
Probably, following changes will work in Node.js 12+?.
import {RuleHelper} from "textlint-rule-helper";
- import alex from "alex";
const defaultOptions = {
allow: undefined,
deny: undefined,
noBinary: false,
profanitySureness: 0
};
export default function textlintRuleAlex(context, options = {}) {
const {Syntax, RuleError, report, getSource} = context;
const helper = new RuleHelper(context);
const opts = {...defaultOptions, ...options};
/*
{ [1:5-1:14: `boogeyman` may be insensitive, use `boogey` instead]
message: '`boogeyman` may be insensitive, use `boogey` instead',
name: '1:5-1:14',
file: '',
reason: '`boogeyman` may be insensitive, use `boogey` instead',
line: 1,
column: 5,
location: Position { start: [Object], end: [Object] },
fatal: false,
ruleId: 'boogeyman-boogeywoman',
source: 'retext-equality' }
*/
const reportError = (node, result) => {
const ruleError = new RuleError(`[${result.ruleId}] ${result.message}`, {
line: result.line - 1,
column: result.column - 1
});
report(node, ruleError);
};
return {
- [Syntax.Str](node){
+ async [Syntax.Str](node){
+ const alex = await import("alex").then(mod => mod.markdown); // markdown equals to default export https://github.com/get-alex/alex/blob/1b4c1be7991b30502cd56fb1d4769708df6853a5/index.js#L56
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
return;
}
const text = getSource(node);
const messages = alex(text, opts).messages;
messages.forEach((result) => {
reportError(node, result);
});
}
}
}
2 is just workaround until textlint ESM support.
Thank you for your explanation.
ok, I'll wait until textlint ESM support.
Any progress on this?
Can you create a PR?
I created a PR #25 but it has issues. If anyway can help me, it would be great.
【issue】 While using this repository, I received a security notice from Dependabot regarding vulnerable version of trim.
The security notice is here.
【solution】 I think updating alex version to
10.0.0
will solve this issue because latest version of alex depends on latest version of remark-parseThank you.