0

eslint allows formats other than json, including .js if it exports as module. Unfortunately, the keys required by eslint include dashes like prefer-const below. Quoting is required. This appears to work.

But: Is there a workaround that allows the .js preferences to not require quotes? Prettier, for example, allows camel case for .prettierrc.js. That does not appear to work for eslint.

module.exports = {
  env: {
    browser: true,
    es6:     true
  },
  extends:  "standard",
  parserOptions: {
    sourceType: "module"
  },
  rules: {
    curly: [ 0 ],
    "prefer-const": [ 2 ]
  }
}
backspaces
  • 3,802
  • 6
  • 34
  • 58

1 Answers1

2

If it matters to you, I would go on and write a function to convert the key names from camel case to dash style.

I was able to come up with a proof-of-concept in a few lines, so that shouldn't be too much work.

function fromCamelCase(rules) {
  return Object.entries(rules).reduce(
    (obj, [key, value]) =>
      (obj[key.replace(/[A-Z]/, ch => `-${ch.toLowerCase()}`)] = value, obj),
    { }
  );
}

module.exports = {
  env: {
    browser: true,
    es6:     true
  },
  extends:  "standard",
  parserOptions: {
    sourceType: "module"
  },
  rules: fromCamelCase({
    curly: [ 0 ],
    preferConst: [ 2 ]
  })
}

If I'm reading the source code correctly, eslint doesn't allow aliasing rule names, so creating a custom plugin is not an option.

GOTO 0
  • 42,323
  • 22
  • 125
  • 158
  • 1
    Good info, thanks. I'm OK with quotes as long as it works! My bet is that prettier is leading the way and others will lead us to a JS object where currently JSON is the only choice. – backspaces May 06 '18 at 18:21