如何使用antful的eslint

99 阅读1分钟

问题

  1. 在使用中发现这个eslint在某些电脑出现 unrs-resolver
Error:Failed to load native binding

这个问题在我的电脑上怎么都解决不了,方案如下

先集成这个
https://github.com/un-ts/napi-postinstall
我试了还是不行,但是重新安装依赖之后,重新打开vscode就可以了

在配置规则需要用到的资源

https://eslint.style/rules/default/arrow-parens

https://github.com/antfu/eslint-config   antful的官网

运行:

pnpm dlx @antfu/eslint-config@latest
import antfu from "@antfu/eslint-config";

export default antfu(
  {
    ignores: ["snapshot*", "**/snapshot*/**", "dist", "**/dist/**", "lib", "**/lib/**", "es", "**/es/**", "esm", "**/esm/**", "node_modules", "**/node_modules/**", "src/_common", "src/_common/**", "static", "**/static/**", "cypress", "**/cypress/**", "script/test/cypress", "script/test/cypress/**", "_site", "**/_site/**", "temp*", "**/temp*/**", "static/", "**/static/**/", "!.prettierrc.js", "!**/.prettierrc.js/**"],
    formatters: {
      css: true, // 格式化 CSS 和 <style> 块
      html: true, // 格式化 HTML 文件
      markdown: "prettier" // 格式化 Markdown 文件
    },
    unocss: true,
    vue: true,
    stylistic: {
      indent: 2, // 4, or 'tab'
      quotes: "double", // or 'double'
      semi: true,
      jsx: true

    },
    rules: {
      "style/semi": ["error", "always"], // 强制在语句末尾使用分号
      "style/comma-dangle": ["error", "never"], // 禁止末尾逗号
      "style/arrow-parens": ["error", "always"]

    }
  }

);

解释下stylistic 和 rule下面的 style: 他们两个是一样的,看这段参考

image.png

你可以直接写stylistic 去配置规则,也可以在rule中配置规则,但是semi应该有一个前缀,就是用style 代替stylistic

总结

1 配置的时候,值的类型有字符串"off",数组["",""],第一个参数是错误级别,第二个参数有对象,字符串。

技巧

1.template和script的顺序

"vue/block-order": [  //配置 template和script的顺序,找了好久!
        "error",
        {
          order: ["template", "script", "style"]
        }
      ],
      
      

2.no console 这个也找了好久

  "no-console": ["error", { allow: ["warn", "error"] }],