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

New: making Plugin's Processor API chainable #1

Closed
wants to merge 5 commits into from

Conversation

mysticatea
Copy link
Member

@mysticatea mysticatea commented Nov 10, 2018

The first RFC 🎉

Summary

This proposal makes the processors being possible to combinate by that those preprocess can return the pair of code and filename. If the returned filename requires another processor, ESLint applies the processor recursively.

interface Processor {
    readonly supportsAutofix?: boolean
    preprocess(code: string, filePath: string): string[] //→ ({ code: string, filePath: string } | string)[]
    postprocess(messages: Problem[][], filePath: string): Problem[]
}

interface Plugin {
    processors?: {
        [ext: string]: Processor
    }
    // ... omit others ...
}

Related Issues


This feature will be implemented in `Linter#verify` method that is applying pre/post processes currently. Below is the implementation of [**verify**](https://github.com/eslint/eslint/blob/5da378ac922d732ca1765f08edee0face1b1b924/lib/linter.js#L1046) I imaged.

(I'm sorry, I couldn't describe it in English.)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry for not a hight-level description...

@mysticatea
Copy link
Member Author

I updated this PR.

@mysticatea mysticatea added enhancement New feature or request and removed triage labels Nov 20, 2018
@mysticatea
Copy link
Member Author

Considering the following settings:

// .eslintrc.js
module.exports = {
    overrides: [
        {
            files: "*.md",
            plugins: ["markdown"],
            settings: {
                markdown: {
                    targetBlocks: ["js", "ts", "html", "vue"]
                }
            }
        },
        {
            files: "*.ts",
            parser: "typescript-eslint-parser", 
        },
        {
            files: "*.html",
            plugins: ["html"],
        },
        {
            files: "*.vue",
            plugins: ["vue"],
            parser: "vue-eslint-parser", 
        },
    ]
}

I expect the extracted blocks from *.md to use other overriden settings. For example, ESLint uses typescript-eslint-parser for ts blocks. However, in the current plan, CLIEngine makes configuration then Linter handles processors. So, the processors cannot change the configuration. :(

Fortunately, we don't have to find .eslintrc files again if the filename that preprocessors returned cannot change the directory which the file belongs. Probably we can move the logic that resolves overrides setting, from CLIEngine to Linter. Though, it may be a breaking change.

@mysticatea
Copy link
Member Author

Merged to #3.

@mysticatea mysticatea closed this Nov 21, 2018
@mysticatea mysticatea deleted the plugin-processor-chaining branch November 21, 2018 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant