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

Update alex version #17

Closed
ryo-funaba opened this issue Sep 10, 2022 · 7 comments · Fixed by #25
Closed

Update alex version #17

ryo-funaba opened this issue Sep 10, 2022 · 7 comments · Fixed by #25
Labels
help wanted Extra attention is needed

Comments

@ryo-funaba
Copy link

【issue】
While using this repository, I received a security notice from Dependabot regarding vulnerable version of trim.

The security notice is here.

スクリーンショット 2022-09-10 16 33 45

【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-parse

Thank you.

@ryo-funaba
Copy link
Author

ryo-funaba commented Sep 10, 2022

@azu
PR is here

@ryo-funaba
Copy link
Author

ryo-funaba commented Sep 10, 2022

I found a same issue in this repo.

That issue was closed by ESM..?

#13

@azu
Copy link
Member

azu commented Sep 10, 2022

get-alex/alex#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.
textlint/textlint#868

Two options:

  1. Fix textlint to support Pure ESM
  2. Use Dynamic Import(import("alex")) in this ruls
    • use 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.

@ryo-funaba
Copy link
Author

Thank you for your explanation.

ok, I'll wait until textlint ESM support.

@azu azu added the help wanted Extra attention is needed label Sep 10, 2022
@tyler36
Copy link
Contributor

tyler36 commented Nov 7, 2023

Any progress on this?

@azu
Copy link
Member

azu commented Nov 7, 2023

Can you create a PR?

@tyler36
Copy link
Contributor

tyler36 commented Nov 7, 2023

I created a PR #25 but it has issues.
If anyway can help me, it would be great.

@azu azu closed this as completed in #25 Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants