Использование с Shopify Polaris
Приложения Shopify, работающие внутри админ-панели Shopify, строят свой интерфейс на веб-компонентах Polaris (<s-button>, <s-text-field>, <s-modal>…). В Vue 3 polaris-vue-elements оборачивает их в типизированные компоненты (SButton, STextField, SModal), и в шаблонах Pug они работают как любые другие компоненты Vue. Этот плагин линтит и исправляет такие шаблоны без дополнительной настройки.
Настройка
npm install polaris-vue-elements
npm install --save-dev pug eslint eslint-plugin-vue vue-eslint-parser eslint-plugin-pug-vue// eslint.config.js
import pluginVue from 'eslint-plugin-vue'
import vuePug from 'eslint-plugin-pug-vue'
export default [
...pluginVue.configs['flat/recommended'],
...vuePug.configs.recommended,
]О скрипте среды выполнения Polaris и опции isCustomElement, которая нужна тегам s-*, читайте в разделе «Начало работы» polaris-vue-elements.
До и после eslint --fix
Шаблон с непоследовательными отступами, кавычками и блоками атрибутов:
div
STextField(v-model="name" label='Name' )
SButton(commandFor="demo-modal",command="--show") Open
s-button(variant="primary" @click="name = ''") Reset
SModal(id="demo-modal" heading="Demo")
SText Hello
template(v-slot:primary-action)
SButton(variant="primary" commandFor="demo-modal" command="--hide") CloseПосле eslint --fix:
div
STextField(v-model="name" label="Name")
SButton(command-for="demo-modal" command="--show") Open
s-button(variant="primary" @click="name = ''") Reset
SModal#demo-modal(heading="Demo")
SText Hello
template(#primary-action)
SButton(variant="primary" command-for="demo-modal" command="--hide") Closevue-pug/indent,vue-pug/attribute-quotes,vue-pug/attribute-commas,vue-pug/no-multi-spacesиvue-pug/attribute-parens-spacingисправили оформление.vue-pug/prefer-shorthandпревратилоid="demo-modal"в#demo-modal;command-forу кнопки по-прежнему открывает модальное окно.- Правила eslint-plugin-vue
vue/v-slot-styleиvue/attribute-hyphenationпереписали слот в#primary-action, аcommandForвcommand-for, что обёртки тоже принимают.
Исправленный шаблон в браузере отображается так же: v-model обновляется, кнопка открывает модальное окно, а кнопка Close попадает в слот primary-action модального окна.
Дополнительные материалы
- Использование шаблонов Pug в документации polaris-vue-elements: как переводить её HTML-примеры в Pug.
- Правила vue/* для Pug: как правила eslint-plugin-vue ведут себя на шаблонах Pug.