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

Plugin should have Processor property #4

Open
JohannesRudolph opened this issue Feb 15, 2022 · 2 comments
Open

Plugin should have Processor property #4

JohannesRudolph opened this issue Feb 15, 2022 · 2 comments
Labels
Status: PR Welcome Type: Bug Something isn't working

Comments

@JohannesRudolph
Copy link

I was trying to get this working for testing, but looks like the textstat plugin is no longer compatible with the latest textlint api?

Here's the error I'm getting when I try run one of the only public examples I could find at https://github.com/asciidwango/js-primer/blob/master/tools/textstat.js

Error: Plugin should have Processor property.
module.exports = {
  Processor: class Processor{ ... }
}

    at new TextlintPluginDescriptor (/Users/jrudolph/dev/tmp/js-primer/node_modules/@textlint/kernel/lib/descriptor/TextlintPluginDescriptor.js:32:19)
    at /Users/jrudolph/dev/tmp/js-primer/node_modules/@textstat/kernel/lib/src/TextstatKernel.js:26:16
    at Array.map (<anonymous>)
    at Object.exports.createParser (/Users/jrudolph/dev/tmp/js-primer/node_modules/@textstat/kernel/lib/src/TextstatKernel.js:25:45)
    at TextstatKernel.report (/Users/jrudolph/dev/tmp/js-primer/node_modules/@textstat/kernel/lib/src/TextstatKernel.js:64:34)
    at /Users/jrudolph/dev/tmp/js-primer/node_modules/textstat/lib/src/textstat.js:74:41
    at Array.map (<anonymous>)
    at Object.<anonymous> (/Users/jrudolph/dev/tmp/js-primer/node_modules/textstat/lib/src/textstat.js:72:41)
    at step (/Users/jrudolph/dev/tmp/js-primer/node_modules/textstat/lib/src/textstat.js:32:23)
    at Object.next (/Users/jrudolph/dev/tmp/js-primer/node_modules/textstat/lib/src/textstat.js:13:53)

What would it take to fix those?

@JohannesRudolph
Copy link
Author

I did a bit of digging on this. Seems it has nothing to do with the textlint's module API but something funky in the way my node wants to load the thing or how an upstream change in textlint-plugin-markdown which I've read has switched to typescript...

Anyhow, I could workaround this by fixing the plugin: require() load for textlint-markdown to unwrap the .default module wrapper.

export async function report(options: ReportOptions) {
    const fileList = await globby(options.globPatterns);
    const textstat = new TextstatKernel();
    const promises = fileList.map((filePath: string) => {
        const text = fs.readFileSync(filePath, "utf-8");
        return textstat.report(text, {
            filePath: filePath,
            ext: path.extname(filePath),
            rules: createTextstatPresetToTextlintPreset(createPreset()),
            plugins: [
                {
                    pluginId: "markdown",
                    plugin: require("@textlint/textlint-plugin-markdown").default
                }
            ],
            sharedDeps: {
                filePathList: fileList,
                locale: options.locale
            }
        });
    });
    return Promise.all(promises);
}

@azu azu added the Type: Bug Something isn't working label Feb 16, 2022
@azu
Copy link
Member

azu commented Feb 16, 2022

Yes. Probably this is interop issue.
https://www.npmjs.com/package/@textlint/module-interop will cover it.

- plugin: require(https://github.com/textlint/textlint).default
+ plugin: moduleInterop(require("@textlint/textlint-plugin-markdown"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: PR Welcome Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants