使用 coffeescript eslintrc 配置 eslint

Configure eslint with coffeescript eslintrc

我正在尝试使用具有以下代码的 coffeescript 文件配置 eslint。但是到目前为止配置没有被正确读取。

# .eslintrc.js
require('coffeescript/register')
require('./.eslintrc.coffee')
# .eslintrc.coffee
config =
  root: true
  env:
    node: true
  extends: [
    'plugin:prettier/recommended'
    'plugin:vue/recommended'
    '@vue/standard'
  ]
  parserOptions:
    parser: 'babel-eslint'
  rules:
    'prettier/prettier': 'error'
    'no-console': if process.env.NODE_ENV == 'production' then 'error' else 'off'
    'no-debugger': if process.env.NODE_ENV == 'production' then 'error' else 'off'

module.exports = config

不幸的是,这是结果。

$ ./node_modules/.bin/eslint --print-config test.js
{
  "env": {},
  "globals": {},
  "parser": null,
  "parserOptions": {},
  "plugins": [],
  "rules": {},
  "settings": {}
}

我尝试过但未成功的其他事情是:

# .eslintrc.js
require('coffeescript/register')
module.exports = require('./.eslintrc.coffee')
# .eslintrc.coffee
config =
  root: true
  env:
    node: true
  extends: [
    'plugin:prettier/recommended'
    'plugin:vue/recommended'
    '@vue/standard'
  ]
  parserOptions:
    parser: 'babel-eslint'
  rules:
    'prettier/prettier': 'error'
    'no-console': if process.env.NODE_ENV == 'production' then 'error' else 'off'
    'no-debugger': if process.env.NODE_ENV == 'production' then 'error' else 'off'

我正在发布一个答案,因为我在任何地方都找不到它:

# .eslintrc.js
require('coffeescript/register')
module.exports = require('./.eslintrc.coffee')
# .eslintrc.coffee
module.exports =
  root: true
  env:
    node: true
  extends: [
    'plugin:prettier/recommended'
    'plugin:vue/recommended'
    '@vue/standard'
  ]
  parserOptions:
    parser: 'babel-eslint'
  rules:
    'prettier/prettier': 'error'
    'no-console': if process.env.NODE_ENV == 'production' then 'error' else 'off'
    'no-debugger': if process.env.NODE_ENV == 'production' then 'error' else 'off'

没错,需要双module.exports

我对其他语言的了解太深了,不知道为什么...

$ ./node_modules/.bin/eslint --print-config test.js
{
  "env": {
    "node": true,
    "es6": true,
    "browser": true
  },
  "globals": {
    "document": false,
    "navigator": false,
    "window": false
  },
  "parser": "/home/worthlessjavascriptcomma/test/node_modules/vue-eslint-parser/index.js",
  "parserOptions": {
    "parser": "babel-eslint",
    "ecmaVersion": 2018,
    "ecmaFeatures": {
      "jsx": true
    },
    "sourceType": "module"
  },
  "plugins": [
    "prettier",
    "vue",
    "standard",
    "promise",
    "node",
    "import"
  ],
  ...

有人有其他选择吗?