2

I have an index.js which exports a few files/modules in a directory:

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

running eslint --fix removes whitespace that results in incorrect syntax:

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

I can't find the relevant rules/formatter/plugin to help with this

The projects .eslintrc:

Note: I also tried with "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"
  ]
}

And from the projects 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",
4

1 回答 1

2

The eslint-friendly way to do imports to specify the {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"

Why? Even-though both forms are equivalent, the second form is a TC39 stage 1 proposed syntax

(Credit to Toru Nagashima on eslint gitter for the heads up)

于 2017-07-16T18:00:33.340 回答