MozillaFoundation / mofo-style

JavaScript Style Guide
15 stars 6 forks source link

Add eslint-config-mofo-style shareable config? #51

Open pdehaan opened 7 years ago

pdehaan commented 7 years ago

Currently you have to do something like this to use the config:

extends: "./node_modules/mofo-style/.eslintrc.yaml"

If this module was published as eslint-config-mofo-style on npm, you could simplify this to:

extends: mofo-style

Ref: http://eslint.org/docs/developer-guide/shareable-configs

You could possibly even use this module as a dependency for eslint-config-mofo-style and export the .eslintrc.yaml file.

pdehaan commented 7 years ago

Actually, I tried a bit of hacking locally to get this work in my _/nodemodules/ directory...

I think the general steps (if this is worth pursuing) would be:

  1. Rename mofo-style's .eslintrc.yaml file to .eslintrc.js (then convert to a JavaScript style module.exports = {}; — see converted code below).
  2. Change mofo-style's package.json main field to the new .eslintrc.js file.
  3. Create an eslint-config-mofo-style module and set a dependency of mofo-style.
  4. Set the eslint-config-mofo-style's package.json main field to index.js.
  5. Create an index.js file in eslint-config-mofo-style with the following:

    module.exports = require(`mofo-style`);

/**
 * This is a baseline set of rules intended for usage in any ES6-based project.
 * Be sure to add your project's specific environment(s) as needed via external configuration.
 *   See: http://eslint.org/docs/user-guide/configuring#specifying-environments
 */

module.exports = {
  // http://eslint.org/docs/developer-guide/shareable-configs
  "rules": {
    // Possible Errors
    "valid-jsdoc": "warn",

    // Best Practices
    "curly": "error",
    "dot-notation": "error",
    "eqeqeq": "error",
    "guard-for-in": "error",
    "no-div-regex": "error",
    "no-eval": "error",
    "no-extend-native": "error",
    "no-floating-decimal": "error",
    "no-implied-eval": "error",
    "no-labels": "error",
    "no-lone-blocks": "error",
    "no-loop-func": "error",
    "no-multi-spaces": "error",
    "no-native-reassign": "error",
    "no-new-wrappers": "error",
    "no-new": "error",
    "no-redeclare": "error",
    "no-return-assign": "error",
    "no-self-compare": "error",
    "radix": "error",
    "wrap-iife": ["error", "inside"],
    "yoda": ["error", "never"],

    // Strict Mode
    "strict": ["error", "global"],

    // Variables
    "no-shadow": "error",
    "no-use-before-define": "error",

    // Stylistic Issues
    "block-spacing": ["error", "always"],
    "brace-style": ["error", "1tbs", {"allowSingleLine": true}],
    "camelcase": ["error", {"properties": "always"}],
    "comma-style": ["error", "last"],
    "consistent-this": ["error", "self"],
    "eol-last": "error",
    "indent": ["error", 2, {"VariableDeclarator": {"var": 2, "let": 2, "const": 3}}],
    "linebreak-style": ["error", "unix"],
    "newline-after-var": "error",
    "no-lonely-if": "error",
    "no-trailing-spaces": "error",
    "no-unneeded-ternary": "error",
    "quotes": ["error", "backtick"],
    "semi": ["error", "always"],
    "spaced-comment": ["error", "always"],
    "wrap-regex": "error",

    // ES6
    "prefer-arrow-callback": "warn",

    // Overrides to `eslint:recommended` rule set
    "no-console": "off"
  },

  "extends": [
    "eslint:recommended"
  ],

  "ecmaFeatures": {
    "arrowFunctions": true,
    "blockBindings": true,
    "defaultParams": true,
    "destructuring": true,
    "forOf": true,
    "spread": true,
    "templateStrings": true
  }
};