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

feat: add ESLint integration #171

Merged
merged 1 commit into from May 1, 2024
Merged

feat: add ESLint integration #171

merged 1 commit into from May 1, 2024

Conversation

johnsoncodehk
Copy link
Member

@johnsoncodehk johnsoncodehk commented May 1, 2024

Added @volar/eslint package to export createProcessor method. Processor is the interface for ESLint to handle virtual code conversion. Downstream tools should build a complete ESLint plugin by themselves.

Usage

Here we take Vue as an example.

  • eslint-plugin-vue.js
const { createProcessor } = require('@volar/eslint');
const { createParsedCommandLine, createVueLanguagePlugin } = require('@vue/language-core');
const ts = require('typescript');

module.exports.create = create;

function create(tsconfig) {
    const commonLine = createParsedCommandLine(ts, ts.sys, tsconfig);
    const languagePlugin = createVueLanguagePlugin(
        ts,
        filename => filename,
        ts.sys.useCaseSensitiveFileNames,
        () => '',
        () => commonLine.fileNames,
        commonLine.options,
        commonLine.vueOptions,
    );
    return {
        processors: {
            vue: createProcessor([languagePlugin], ts.sys.useCaseSensitiveFileNames),
        },
    };
}
  • eslint.config.js
const eslint = require('@eslint/js');
const tseslint = require('typescript-eslint');

module.exports = [
    eslint.configs.recommended,
    ...tseslint.configs.recommended,
    {
        plugins: {
            vue: require('./eslint-plugin-vue').create(__dirname + '/tsconfig.json')
        }
    },
    {
        files: ["**/*.vue"],
        processor: "vue/vue"
    },
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant