ESLint Processor for Vue Blocks

2.0.0 · active · verified Sun Apr 19

eslint-processor-vue-blocks enables ESLint to process individual blocks within Vue Single File Components (SFCs) by creating virtual files for each block (e.g., `<style>`, `<custom-block>`). This allows for more granular linting, applying different ESLint configurations and rules to specific parts of a Vue component. The current stable version is 2.0.0, which introduced breaking changes by requiring ESLint v9+ and becoming an ESM-only package. The package is maintained by Antfu and sees updates driven by ecosystem changes like new ESLint versions or Vue SFC parsing improvements. Its key differentiator is providing a flexible way to extend `eslint-plugin-vue`'s default processing, enabling linting of styles or custom blocks independently, which `eslint-plugin-vue` typically delegates or ignores.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure `eslint-processor-vue-blocks` with ESLint flat config to lint Vue SFC `<style>` and custom blocks alongside `eslint-plugin-vue`.

import { mergeProcessors } from 'eslint-merge-processors'
import pluginVue from 'eslint-plugin-vue'
import processorVueBlocks from 'eslint-processor-vue-blocks'

export default [
  {
    files: ['**/*.vue'],
    plugins: {
      vue: pluginVue,
    },
    processor: mergeProcessors([
      pluginVue.processors['.vue'],
      processorVueBlocks({
        blocks: {
          styles: true,
          customBlocks: true,
          // Usually it's not recommended to lint <script> and <template>
          // As eslint-plugin-vue already provides the support
          script: false,
          template: false,
        }
      }),
    ]),
    rules: {
      // Your Vue-specific rules for script and template
      'vue/no-unused-vars': 'error',
      'vue/multi-word-component-names': 'off'
    }
  },
  {
    files: ['**/*.css', '**/*.vue/*.css'], // Lint CSS files and <style> blocks
    rules: {
      'selector-list-comma-newline-after': 'always',
      // ... your CSS rules
    }
  },
  {
    files: ['**/*.md', '**/*.vue/*.md'], // Example for custom blocks, e.g., <docs lang="md"> 
    rules: {
      'prettier/prettier': 'error' // Assuming you have eslint-plugin-prettier configured
    }
  }
]

view raw JSON →