Skip to content

feat: add ESLint integration#171

Merged
johnsoncodehk merged 1 commit intomasterfrom
eslint
May 1, 2024
Merged

feat: add ESLint integration#171
johnsoncodehk merged 1 commit intomasterfrom
eslint

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.

1 participant