Skip to content

यह पेज एक अनुवाद है। यदि यह अंग्रेज़ी पेज से अलग है, तो अंग्रेज़ी पेज ही सही है। English

vue-pug/no-pug-control-flow ​

Pug compile-time constructs (control flow, code, mixins, #{} interpolation, includes) मना करें।

configs.recommended में चालू नहीं। --fix से ठीक नहीं होता।

Rule का विवरण ​

Pug के conditionals, loops, code, mixins और #{} interpolation template के compile होते समय एक बार चलते हैं। Vue उन्हें कभी नहीं देखता, इसलिए वे reactive नहीं हैं, और vue/* rules खुद Pug logic को नहीं देखते। यह rule उन्हें रिपोर्ट करता है ताकि templates इसके बजाय Vue directives और bindings उपयोग करें। हर construct एक category में आता है:

Categoryक्या रिपोर्ट करता है
controlif, else if, else, unless, each, for, while, case, when, default
code- code, = expression, != expression, p= expression
mixinmixin definitions (mixin name) और calls (+name)
interpolationtext में #{…} और !{…}
includeinclude, extends, block, append, prepend, yield, doctype

गलत ​

vue
<template lang="pug">
ul
  each item in items
    li= item
</template>
vue
<template lang="pug">
p Hello #{name}
</template>

सही ​

vue
<template lang="pug">
ul
  li(v-for="item in items" :key="item") {{ item }}
</template>
vue
<template lang="pug">
p(v-if="name") Hello {{ name }}
</template>

Options ​

js
'vue-pug/no-pug-control-flow': ['warn', { allow: [] }]

allow: वे categories जो रिपोर्ट नहीं होतीं, 'control', 'code', 'mixin', 'interpolation', 'include' में से कोई भी (default [])।

[{ "allow": ["interpolation"] }] के साथ सही ​

vue
<template lang="pug">
p Hello #{name}
</template>

[{ "allow": ["interpolation"] }] के साथ गलत ​

vue
<template lang="pug">
p= name
</template>

eslint-plugin-vue-pug से माइग्रेट करना ​

eslint-plugin-vue-pug में इसी id वाला एक rule है, vue-pug/no-pug-control-flow। अंतर:

  • उसकी schema खाली है: वह कोई options नहीं लेता और जितने constructs जानता है सब हमेशा रिपोर्ट करता है। यह rule { allow: [...] } लेता है (ऊपर देखें)। पुराने rule को आपने जो भी options दिए थे उन्हें ESLint अस्वीकार कर देता था, इसलिए बिना options वाली मौजूदा सेटिंग काम करती रहती है।
  • पुराना rule अपने strongly-recommended configs में (warn पर) चालू था। यह rule किसी config में नहीं है: इसे खुद चालू करें।

MIT License के अंतर्गत जारी।