ESLint Processor for Vue Blocks
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
-
Error: Cannot find module 'eslint-processor-vue-blocks'
cause Attempting to `require()` an ESM-only package in a CommonJS context.fixEnsure your ESLint configuration file (`eslint.config.js`) is treated as an ES Module. This typically means adding `"type": "module"` to your `package.json` or renaming the config file to `.mjs`. -
TypeError: processorVueBlocks is not a function
cause Incorrect import of `processorVueBlocks` or attempt to use it without `import` in an ESM context.fixVerify that you are using `import processorVueBlocks from 'eslint-processor-vue-blocks'` and that your environment supports ES Modules. -
ESLint couldn't find the plugin "vue".
cause `eslint-plugin-vue` is not installed or correctly configured.fixInstall `eslint-plugin-vue` (e.g., `npm i -D eslint-plugin-vue`) and ensure it is included in your ESLint flat config under the `plugins` key.
Warnings
- breaking Version 2.0.0 of `eslint-processor-vue-blocks` requires ESLint v9.0.0 or higher. Older ESLint versions are not supported.
- breaking Since v2.0.0, `eslint-processor-vue-blocks` is an ESM-only package. It no longer provides CommonJS builds.
- gotcha By default, `eslint-plugin-vue` already handles `<script>` and `<template>` blocks. Enabling them in `eslint-processor-vue-blocks` can lead to duplicate linting or unexpected behavior.
- gotcha This package requires `@vue/compiler-sfc` as a peer dependency for parsing Vue SFCs. Without it, the processor cannot function.
Install
-
npm install eslint-processor-vue-blocks -
yarn add eslint-processor-vue-blocks -
pnpm add eslint-processor-vue-blocks
Imports
- processorVueBlocks
const processorVueBlocks = require('eslint-processor-vue-blocks')import processorVueBlocks from 'eslint-processor-vue-blocks'
- mergeProcessors
import mergeProcessors from 'eslint-merge-processors'
import { mergeProcessors } from 'eslint-merge-processors' - ConfigObject
import type { Linter } from 'eslint'
Quickstart
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
}
}
]