eslint-plugin-weapp2
v1.2.0
Published
a weapp eslint
Readme
eslint-plugin-weapp2
a weapp eslint
Installation
Install ESLint, this plugin, and the language plugins used by the mini program asset rules:
npm install eslint eslint-plugin-weapp2 @eslint/json @eslint/css --save-dev
# pnpm install eslint eslint-plugin-weapp2 @eslint/json @eslint/css --save-devUsage
For ESLint 10, use the bundled mini program flat config:
const { defineConfig } = require("eslint/config");
const weapp2 = require("eslint-plugin-weapp2");
module.exports = defineConfig([
...weapp2.configs["flat/weapp"],
]);If your config loader cannot synchronously require() @eslint/json or
@eslint/css, pass the language plugins explicitly:
const { defineConfig } = require("eslint/config");
const weapp2 = require("eslint-plugin-weapp2");
module.exports = (async () => {
const json = (await import("@eslint/json")).default;
const css = (await import("@eslint/css")).default;
return defineConfig([
...weapp2.createFlatWeappConfig({ json, css }),
]);
})();flat/weapp enables:
- JS/WXS rules:
weapp2/component,weapp2/import,weapp2/wx-navigate - JSON rules through
@eslint/json:weapp2/component-import - WXSS rules through
@eslint/css:weapp2/wxss-import - WXML rules through the built-in
weapp2/wxmllanguage:weapp2/wxml-import
If you only want the JS/WXS rules, use weapp2.configs["flat/recommended"].
If you're still on ESLint 8, you can keep using .eslintrc:
{
"extends": ["eslint:recommended", "plugin:weapp2/recommended"]
}Rules
💼 Configurations enabled in.
🧊 Set in the flat/recommended configuration.
🌐 Set in the flat/weapp configuration.
✅ Set in the recommended configuration.
🔧 Automatically fixable by the --fix CLI option.
| Name | Description | 💼 | 🔧 | | :------------------------------------------------- | :---------------------------------------------------------------------------------- | :------ | :- | | component | 检查组件的 properties 属性是否规范 | 🧊 🌐 ✅ | 🔧 | | component-import | 基于 app.json 校验小程序组件配置文件中的路径(usingComponents / pages / tabBar 等) | 🌐 | | | import | 基于 app.json 检查小程序的 import/require 与动态跳转是否合法 | 🧊 🌐 ✅ | | | wx-navigate | 基于 app.json 校验 wx.navigateTo / redirectTo / switchTab / reLaunch 等跳转 API 的 url 是否合法 | 🧊 🌐 ✅ | | | wxml-import | 基于 app.json 校验 WXML 中 // 的 src 路径与分包边界 | 🌐 | | | wxss-import | 基于 app.json 校验 WXSS 的 @import 引用路径与分包边界 | 🌐 | |
