antfu / eslint-config

Anthony's ESLint config preset
https://eslint-config.antfu.me/
MIT License
3.81k stars 426 forks source link

请问可以新增 globals key 吗?小程序开发会全局注入 uni、wx 等变量 #513

Closed sunpm closed 3 months ago

sunpm commented 3 months ago

Clear and concise description of the problem

小程序编译后会全局注入 uni、wx 等变量,可以保证它们一定存在。 但是开发过程中没有注入,导致 eslint 检测报错。 原来 .eslintrc.js中 可以配置 globals,配置到 eslint.config.js 出现异常:Error: Key "globals": This appears to be in eslintrc format rather than flat config format.

Suggested solution

可否在 eslint config 中增加 globals 配置属性

Alternative

No response

Additional context

No response

Validations

Simon-He95 commented 3 months ago

不是可以类型里面声明一个全局的变量吗,就像window

sunpm commented 3 months ago

不是可以类型里面声明一个全局的变量吗,就像window

是的,如果使用tsconfig不会有这个问题,但是用的是js…

antfu commented 3 months ago

你可以自己配置。我不用小程序,没有兴趣支持

Azir-11 commented 2 months ago

给后来者提供一点帮助,可以这样配置以支持全局key:

const antfu = require('@antfu/eslint-config').default
const { FlatCompat } = require('@eslint/eslintrc')

const compat = new FlatCompat()

module.exports = antfu({
// your config
}, 
...compat.config({
  globals: {
    wx: 'readonly', // 微信小程序
    uni: 'readonly', // uniapp
  },
}))

FlatCompat 的配置看你的项目是ES的还是Common的,我这个给的是common的,ES的直接把require换成import就好了