Skip to content

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.

2 participants