# [Deprecated] wxml/no-wx-for-with-wx-if

# Backgroud

WARNING

Please use wxml/no-wx-for-with-wx-else (opens new window) instead.

You can't use wx:for with wx:if | wx:elif | wx:else at same tag, it will cause wechat miniprogram compile error like follow 👇

error

Releative official community discussion

# Motivation

Force developer using wx:for without wx:if|wx:elif|wx:else, that's wrong wxml grammer, so we need avoid the compile error.

<!-- ✓ GOOD --> <view wx:for="{{list}}"> {{item.name}}</view> <!-- use <block /> to wrap loop list is official recommended --> <block wx:if="{{showList}}"> <view wx:for="{{list}}"> {{item.name}}</view> </block> <!-- ✗ BAD --> <view wx:if="{{showList}}" wx:for="{{list}}"> {{item.name}}</view> <view wx:elif="{{showOtherList}}" wx:for="{{otherList}}"> {{item.name}}</view> <view wx:else wx:for="{{lastList}}"> {{item.name}}</view>
Now loading...

💡 tips

You can edit code via online editor, it's online REPL, try to fix eslint problem !

# Config

No special options, normal config is ok

{ "wxml/no-wx-for-with-wx-if": "error" }

# History

Version Changes
v0.5.0 Deprecated

# Version

This rule was introduced in eslint-plugin-wxml v0.4.0

# Implementation