标识符"aa_bb"不符合驼峰命名法

5

在这里输入图片描述

我尝试在.eslintrc中添加规则,但它不起作用。

请帮忙。

我从API获取'aa_bb'。我按照文档和其他方式添加了规则。

仍然无法正常工作。我的同学告诉我删除eslint,他认为那是多余的。

哦,我不能再提供更多细节......

{
    "parser": "babel-eslint",
    "extends": "airbnb",
    "plugins": ["compat"],
    "env": {
        "browser": true,
        "node": true,
        "es6": true,
        "mocha": true,
        "jest": true,
        "jasmine": true
    },
    "rules": {
        "generator-star-spacing": [0],
        "consistent-return": [0],
        "react/forbid-prop-types": [0],
        "react/jsx-filename-extension": [1, { "extensions": [".js"] }],
        "global-require": [1],
        "import/prefer-default-export": [0],
        "react/jsx-no-bind": [0],
        "react/prop-types": [0],
        "react/prefer-stateless-function": [0],
        "react/jsx-wrap-multilines": ["error", {
            "declaration": "parens-new-line",
            "assignment": "parens-new-line",
            "return": "parens-new-line",
            "arrow": "parens-new-line",
            "condition": "parens-new-line",
            "logical": "parens-new-line",
            "prop": "ignore"
        }],
        "no-else-return": [0],
        "no-script-url": 0,
        "no-restricted-syntax": [0],
        "import/no-extraneous-dependencies": [0],
        "no-use-before-define": [0],
        "jsx-a11y/no-static-element-interactions": [0],
        "jsx-a11y/no-noninteractive-element-interactions": [0],
        "jsx-a11y/click-events-have-key-events": [0],
        "jsx-a11y/anchor-is-valid": [0],
        "no-nested-ternary": [0],
        "arrow-body-style": [0],
        "import/extensions": [0],
        "no-bitwise": [0],
        "no-cond-assign": [0],
        "import/no-unresolved": [0],
        "camelcase": [
          "error", {
            "properties": "never"
          }
        ],
        "comma-dangle": ["error", {
            "arrays": "always-multiline",
            "objects": "always-multiline",
            "imports": "always-multiline",
            "exports": "always-multiline",
            "functions": "ignore"
        }],
        "object-curly-newline": [0],
        "function-paren-newline": [0],
        "no-restricted-globals": [0],
        "require-yield": [1],
        "compat/compat": "error",
      // "linebreak-style": ["error", "windows"]
    },
    "parserOptions": {
        "ecmaFeatures": {
            "experimentalObjectRestSpread": true
        }
    },
    "settings": {
        "polyfills": ["fetch", "promises"]
    }
}


1
你能否在使用 // eslint-disable-line 的地方禁用内联吗? - Mad-D
4个回答

5

这是你完整的.eslintrc文件,还是只是一段片段?如果是前者,则需要在.eslintrc文件的开头和结尾加上花括号。因此,请尝试:

{
    "rules": {
        "camelcase": ["error", {"properties": "never"}]
    }
}

如果只是一个代码片段,你使用的 ESLint 版本是什么?我记得在早期的 1.x 版本中,"error" 被用来代替表示级别的数字:
{
    "rules": {
        "camelcase": [2, {"properties": "never"}]
    }
}

这只是一小段代码。我在网上找了一些方法(包括你的答案),但还是没有用。。我现在更新了问题。 - window
1
当我将第一个片段添加到eslintrc文件中时,它对我起作用了。谢谢。 - Rick

4

camelCase是一种命名约定,其中复合词中的每个单词都大写,但第一个单词除外。软件开发人员在编写源代码时经常使用camelCase。

在编程中,由于元素名称不能包含空格,因此camelCase非常有用。camelCase命名约定使复合名称更易读。例如,myOneMethod比myonemethod更容易阅读。

add_bb for addFor

3

这个更新使得你现在可以灵活地允许某些标识符(包括正则表达式)不使用驼峰命名法:

{
    "rules": {
        "camelcase": ["error", {"allow": ["aa_bb"]}]
    }
}

请参考:https://eslint.org/docs/rules/camelcase#allow

0
如果修改您的eslint配置不是一个选项,您可以简单地解构然后重命名该属性。
const { first_name: firstName } = data;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接