|
| 1 | +# eslint-processor-vue-blocks |
| 2 | + |
| 3 | +[![npm version][npm-version-src]][npm-version-href] |
| 4 | +[![npm downloads][npm-downloads-src]][npm-downloads-href] |
| 5 | +[![bundle][bundle-src]][bundle-href] |
| 6 | +[![JSDocs][jsdocs-src]][jsdocs-href] |
| 7 | +[![License][license-src]][license-href] |
| 8 | + |
| 9 | +Create virtual files in ESLint for each Vue SFC block, so that you can lint them individually. |
| 10 | + |
| 11 | +## Install |
| 12 | + |
| 13 | +```bash |
| 14 | +npm i -D eslint-processor-vue-blocks eslint-merge-processors |
| 15 | +``` |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +In ESLint flat config: |
| 20 | + |
| 21 | +```js |
| 22 | +// eslint.config.js |
| 23 | +import pluginVue from 'eslint-plugin-vue' |
| 24 | +import processorVueBlocks from 'eslint-processor-vue-blocks' |
| 25 | +import mergeProcessors from 'eslint-merge-processors' |
| 26 | + |
| 27 | +export default [ |
| 28 | + { |
| 29 | + files: ['*/*.vue'], |
| 30 | + plugins: { |
| 31 | + vue: pluginVue, |
| 32 | + }, |
| 33 | + // `eslint-plugin-vue` will set a default processor for `.vue` files |
| 34 | + // we use `eslint-merge-processors` to extend it |
| 35 | + processor: mergeProcessors([ |
| 36 | + pluginVue.processors['.vue'], |
| 37 | + processorVueBlocks({ |
| 38 | + blocks: { |
| 39 | + styles: true, |
| 40 | + customBlocks: true, |
| 41 | + // Usually it's not recommended to lint <script> and <template> |
| 42 | + // As eslint-plugin-vue already provides the support |
| 43 | + script: false, |
| 44 | + template: false, |
| 45 | + } |
| 46 | + }), |
| 47 | + ]), |
| 48 | + rules: { |
| 49 | + // ... |
| 50 | + } |
| 51 | + }, |
| 52 | + { |
| 53 | + files: ['**/*.css'], |
| 54 | + // ... now you can lint CSS files as will as the <style> blocks in Vue SFCs |
| 55 | + } |
| 56 | +] |
| 57 | +``` |
| 58 | + |
| 59 | +## Sponsors |
| 60 | + |
| 61 | +<p align="center"> |
| 62 | + <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg"> |
| 63 | + <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/> |
| 64 | + </a> |
| 65 | +</p> |
| 66 | + |
| 67 | +## License |
| 68 | + |
| 69 | +[MIT](./LICENSE) License © 2023-PRESENT [Anthony Fu](https://github.com/antfu) |
| 70 | + |
| 71 | + |
| 72 | +<!-- Badges --> |
| 73 | + |
| 74 | +[npm-version-src]: https://img.shields.io/npm/v/eslint-processor-vue-blocks?style=flat&colorA=080f12&colorB=1fa669 |
| 75 | +[npm-version-href]: https://npmjs.com/package/eslint-processor-vue-blocks |
| 76 | +[npm-downloads-src]: https://img.shields.io/npm/dm/eslint-processor-vue-blocks?style=flat&colorA=080f12&colorB=1fa669 |
| 77 | +[npm-downloads-href]: https://npmjs.com/package/eslint-processor-vue-blocks |
| 78 | +[bundle-src]: https://img.shields.io/bundlephobia/minzip/eslint-processor-vue-blocks?style=flat&colorA=080f12&colorB=1fa669&label=minzip |
| 79 | +[bundle-href]: https://bundlephobia.com/result?p=eslint-processor-vue-blocks |
| 80 | +[license-src]: https://img.shields.io/github/license/antfu/eslint-processor-vue-blocks.svg?style=flat&colorA=080f12&colorB=1fa669 |
| 81 | +[license-href]: https://github.com/antfu/eslint-processor-vue-blocks/blob/main/LICENSE |
| 82 | +[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669 |
| 83 | +[jsdocs-href]: https://www.jsdocs.io/package/eslint-processor-vue-blocks |
0 commit comments