eslint错误地修复"从y"中导出x从" exportx from y"

时间:2017-06-22 06:26:37

标签: eslint eslint-config-airbnb

我有一个index.js,可以在目录中导出一些文件/模块:

export DaysAsTimePeriod from "./DaysAsTimePeriod"
export Money from "./Money"
export NumberOfProducts from "./NumberOfProducts"
export ItemNumber from "./ItemNumber"

运行eslint --fix会删除导致语法错误的空格:

exportDaysAsTimePeriodfrom "./DaysAsTimePeriod"
exportMoneyfrom "./Money"
exportNumberOfProductsfrom "./NumberOfProducts"
exportItemNumberfrom "./ItemNumber"
exportAttachedProducts, {NAME as PRODUCTS_NAME} from "./AttachedProducts"

我无法找到相关的规则/格式化程序/插件来帮助解决此问题

项目.eslintrc

注意:我也试过了"import/prefer-default-export": [0, { "includeExports": false }],

{
  "extends": "airbnb",
  "env": {
    "browser": true,
    "mocha": true,
    "node": true
  },
  "allowInlineConfig": false,
  "globals": {
    "expect": true,
    "shallow": true,
    "sinon": true,
    "mount": true,
    "snapshot": true,
    "__USEMOCKS__": true
  },
  "rules": {
    "array-callback-return": 0,
    "arrow-body-style": 0,
    "camelcase": 0,
    "class-methods-use-this": 0,
    "comma-dangle": [2, "never"],
    "func-names": 0,
    "import/extensions": 0,
    "import/no-extraneous-dependencies": 0,
    "import/no-named-as-default-member": 0,
    "import/prefer-default-export": 0,
    "indent": [2, 2],
    "jsx-a11y/img-has-alt": 0,
    "jsx-a11y/no-static-element-interactions": 0,
    "no-alert": 0,
    "no-console": 0,
    "no-underscore-dangle": 0,
    "object-curly-spacing": [2, "never"],
    "prefer-arrow-callback": 0,
    "quote-props": ["error", "consistent-as-needed"],
    "quotes": [2, "double"],
    "react/jsx-closing-bracket-location": [2, "after-props"],
    "react/forbid-prop-types": [2, { "forbid": ["any"] }],
    "react/jsx-curly-spacing": [2, "never"],
    "react/jsx-filename-extension": 0,
    "react/jsx-no-bind": 0,
    "react/jsx-uses-react": 1,
    "react/no-array-index-key": 0,
    "react/prefer-stateless-function": 0,
    "react/react-in-jsx-scope": 0,
    "semi": [2, "never"],
    "space-before-function-paren": ["error", "never"],
    "vars-on-top": 0
  },
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 6,
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true
    }
  },
  "plugins": [
    "class-property"
  ]
}

来自项目package.json

"eslint": "3.19.0",
"eslint-config-airbnb": "14.1.0",
"eslint-plugin-babel": "4.1.1",
"eslint-plugin-class-property": "1.0.6",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsx-a11y": "4.0.0",
"eslint-plugin-react": "6.10.3",

1 个答案:

答案 0 :(得分:1)

使用eslint友好的方式进行导入以指定{default as <name>}

export {default as DaysAsTimePeriod} from "./DaysAsTimePeriod"
export {default as Money} from "./Money"
export {default as NumberOfProducts} from "./NumberOfProducts"
export {default as ItemNumber} from "./ItemNumber"

为什么?偶数 - 虽然两种形式都是equivalent,但第二种形式是TC39 stage 1 proposed语法

(归功于Toru Nagashima对于抬头的傻瓜)