Using with Shopify Polaris
Shopify apps that run inside the Shopify admin build their UI with Polaris web components (<s-button>, <s-text-field>, <s-modal>…). In Vue 3, polaris-vue-elements wraps them as typed components (SButton, STextField, SModal), and those work in Pug templates like any other Vue component. This plugin lints and fixes them with no extra configuration.
Setup
sh
npm install polaris-vue-elements
npm install --save-dev pug eslint eslint-plugin-vue vue-eslint-parser eslint-plugin-pug-vuejs
// 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,
]For the Polaris runtime script and the isCustomElement option that s-* tags need, follow polaris-vue-elements' Getting started.
Before and after eslint --fix
A template with inconsistent indentation, quotes and attribute blocks:
pug
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") CloseAfter eslint --fix:
pug
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-spacesandvue-pug/attribute-parens-spacingfixed the layout.vue-pug/prefer-shorthandturnedid="demo-modal"into#demo-modal; the button'scommand-forstill opens the modal.- eslint-plugin-vue's
vue/v-slot-styleandvue/attribute-hyphenationrewrote the slot to#primary-actionandcommandFortocommand-for, which the wrappers accept as well.
The fixed template renders the same in the browser: v-model updates, the button opens the modal, and the Close button lands in the modal's primary-action slot.
Further reading
- Using Pug templates in the polaris-vue-elements docs: translating its HTML examples to Pug.
- vue/* rules on Pug: how eslint-plugin-vue rules behave on Pug templates.