Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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-dev

Usage

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/wxml language: 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 引用路径与分包边界 🌐

About

一个微信小程序的eslint插件,进行最基础的语法检查和一些小程序开发的时候比较坑的写法检查。

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages