elsint报错Delete `␍`eslintprettier/prettier

一,原因

这篇博客写得很清楚:解决VSCode Delete `␍`eslint(prettier/prettier)错误_vscode 删除cr-CSDN博客
还有这篇文章,解决办法很详细:滑动验证页面

二,解决办法

根目录下新建.prettierrc.js文件

module.exports = {
  trailingComma: "all", // 设置是否末尾添加逗号的字段
  arrowParens: "avoid", //箭头函数参数括号,avoid 能省略括号的时候就省略
  useEditorConfig: false,
  endOfLine: "auto", //避免报错delete (cr)的错
  bracketSameLine: true,
  jsxSingleQuote: true,
  singleQuote: false, // 格式化以单引号为主
  semi: true, // 格式化不加分号
  printWidth: 300,
};

根目录下.eslintrc.js文件(可以不配置)

module.exports = {
  env: {
    browser: true,
    es6: true,
    node: true,
  },
  extends: [
    "plugin:vue/essential",
    "airbnb-base",
    "plugin:prettier/recommended", //这样写,让pettier的规则,放在eslint规则扩展中,于是会经由eslint报错
  ],
  globals: {
    Atomics: "readonly",
    SharedArrayBuffer: "readonly",
  },
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: "module",
  },
  plugins: ["vue"],
  rules: {
    quotes: [2, "double"], //警告,必须双引号
    "no-compare-neg-zero": 2, //禁止与 -0 进行比较
    "no-cond-assign": [2, "except-parens"], //禁止条件语句中出现赋值操作符
    "no-console": 0, //允许出现console
    "no-constant-condition": 2, //禁止在条件中使用常量表达式
    "no-control-regex": 2, //禁止在正则表达式中使用控制字符
    "no-debugger": 0, //可以使用debugger
    "no-dupe-args": 2, //禁止 function 定义中出现重名参数
    "no-dupe-keys": 2, //禁止对象字面量中出现重复的 key
    "no-duplicate-case": 2, //禁止出现重复的 case 标签
    "no-empty": 2, //禁止出现空语句块
    "no-empty-character-class": 2, //禁止在正则表达式中使用空字符集
    "no-ex-assign": 2, //禁止对 catch 子句的参数重新赋值
    "no-extra-boolean-cast": 2, //禁止不必要的布尔转换
    "no-extra-parens": ["error", "functions"], //禁止不必要的括号
    "no-extra-semi": 2, //禁止不必要的分号
    "no-func-assign": 2, //禁止对 function 声明重新赋值
    "no-inner-declarations": 0, //禁止在嵌套的块中出现变量声明或 function 声明
    "no-invalid-regexp": 2, //禁止 RegExp 构造函数中存在无效的正则表达式字符串
    "no-irregular-whitespace": 2, //禁止不规则的空白
    "no-obj-calls": 2, //禁止把全局对象作为函数调用
    "no-prototype-builtins": 2, //禁止直接调用 Object.prototypes 的内置属性
    "no-regex-spaces": 2, //禁止正则表达式字面量中出现多个空格
    "no-sparse-arrays": 2, //禁用稀疏数组
    "no-template-curly-in-string": 0, //禁止在常规字符串中出现模板字面量占位符语法
    "no-unexpected-multiline": 2, //禁止出现令人困惑的多行表达式
    "no-unreachable": 2, //禁止在 return、throw、continue 和 break 语句之后出现不可达代码
    "no-unsafe-finally": 2, //禁止在 finally 语句块中出现控制流语句
    "no-unsafe-negation": 2, //禁止对关系运算符的左操作数使用否定操作符
    "use-isnan": 2, //要求使用 isNaN() 检查 NaN
    "valid-jsdoc": "off", //
    "valid-typeof": 2, //强制 typeof 表达式与有效的字符串进行比较

    curly: 2, //强制所有控制语句使用一致的括号风格
    "consistent-return": [
      2,
      {
        treatUndefinedAsUnspecified: true,
      },
    ],
    "default-case": 2,
    eqeqeq: "off",
    "guard-for-in": 0,
    "no-case-declarations": 0,
    "no-empty-pattern": 2,
    "no-fallthrough": 2,
    "no-global-assign": [
      2,
      {
        exceptions: [],
      },
    ],
    "no-octal": 2,
    "no-redeclare": 2,
    "no-self-assign": 2,
    "no-unused-labels": 2,
    "no-useless-escape": 2,

    strict: 2,

    "no-delete-var": 2,
    "no-undefined": 0,
    "no-undef": 2,
    "no-use-before-define": 2,

    "array-bracket-spacing": [2, "never"],
    "block-spacing": [2, "always"],
    "brace-style": [2, "1tbs"],
    "comma-dangle": ["error", "never"],
    "comma-spacing": [
      2,
      {
        before: false,
        after: true,
      },
    ],
    "comma-style": [2, "last"],
    "computed-property-spacing": ["error", "never"],
    "eol-last": [2, "always"],
    "func-call-spacing": ["error", "never"],
    indent: [
      "error",
      2,
      {
        SwitchCase: 1,
      },
    ],
    "jsx-quotes": ["error", "prefer-double"],
    "key-spacing": [
      "error",
      {
        beforeColon: false,
        afterColon: true,
      },
    ],
    "new-cap": [
      "error",
      {
        newIsCap: true,
        capIsNewExceptionPattern: "(Type[a-zA-Z0-9]+|Deco[a-zA-Z0-9]+)+",
      },
    ],
    "new-parens": "error",
    "no-mixed-spaces-and-tabs": 2,
    "no-multi-assign": "error",
    "no-multiple-empty-lines": "error",

    semi: [
      2,
      "always",
      {
        omitLastInOneLineBlock: true,
      },
    ],

    "constructor-super": 2,
    "no-class-assign": 0,
    "no-const-assign": 2,
    "no-this-before-super": 2,
    "no-var": 2,
    "no-dupe-class-members": 2,
    "no-new-symbol": 2,
    "require-yield": 2,
    "prefer-const": 0,
  },
};

  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
eslint-prettier/prettier是一个用于代码格式化的工具,用于统一代码风格,提高代码可读性和维护性。它可以帮助我们在开发过程中自动格式化代码,避免因为代码风格不一致而引起的问题。 然而,有时候我们可能需要删除eslint-prettier/prettier插件。有几种情况可能导致这样的需求: 1. 个人喜好:有些开发者可能对某些代码风格的约束没有强烈的需求,或者更喜欢其他的代码风格工具,所以他们可能会选择删除eslint-prettier/prettier。 2. 与其他工具冲突:有时候,eslint-prettier/prettier与其他代码检测工具或代码编辑器插件存在冲突,导致运行时出现问题,这时候删除eslint-prettier/prettier可能是一个解决办法。 3. 项目需求:对于一些特定的项目,可能需要通过其他方式进行代码格式化,或者引入其他代码风格规范,这时候就需要删除eslint-prettier/prettier。 要删除eslint-prettier/prettier,可以按照以下步骤进行: 1. 先找到项目中的`.eslintrc`或`.eslintrc.js`配置文件,打开查看。 2. 在该配置文件中,找到`plugins`和`extends`字段,里面可能包含了`prettier`相关的配置信息。 3. 删除`plugins`和`extends`字段中与`eslint-prettier/prettier`有关的配置项。 4. 如果有其他与eslint-prettier/prettier相关的配置字段,也一并删除。 5. 保存并关闭配置文件。 完成以上步骤后,eslint-prettier/prettier就被成功删除了。但需要注意的是,删除eslint-prettier/prettier可能导致代码格式不一致,建议在删除之前备份代码或者提前进行其他代码格式化操作,以确保代码风格的一致性。 总之,删除eslint-prettier/prettier的需求可能因个人喜好、工具冲突或者项目需要而产生。通过删除相关配置项,可以成功移除该插件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值