npetruzzelli / eslint-config-prettier-standard

An ESLint shareable config for projects using 'Prettier' and 'JavaScript Standard Style' as ESLint rules.
BSD 3-Clause "New" or "Revised" License
39 stars 3 forks source link

Overridding specific rules #7

Closed amitkot closed 5 years ago

amitkot commented 5 years ago

I want to use the prettier + standard eslint config but override a specific rule (tabWidth).

I tried specifying the prettier/prettier rule in .eslintrc this way:

{
    "extends": ["prettier-standard"],
    "plugins": ["prettier"],
    "rules": {
        "prettier/prettier": ["error", { "tabWidth": 4 }],
    }
}

But it seems that by doing this I override more than the tab width and also get the "semi": true rule.

Is there a way to get prettier-standard with only specific rules overridden?

npetruzzelli commented 5 years ago

I have no control over this as mentioned here: https://github.com/npetruzzelli/eslint-config-prettier-standard/blob/0f41fe2e6b94e148379f1b3fb3673636f984c85b/README.markdown#extending-prettier

Though if you are looking to extend what this module uses, there is a work around available to you. by reading what I use and then extending it like any other JavaScript object.

const baseConfig = require("eslint-config-prettier-standard/lib/base");
const basePrettierConfig = baseConfig.rules["prettier/prettier"][1];

module.exports = {
  // ... other config
  "extends": [
    "prettier-standard"
  ],

  // plugins: ["prettier"], // Not needed since `prettier-standard` already references it as a plugin.

  rules: {
    "prettier/prettier": [
      "error",
      Object.assign(
        {},
        basePrettierConfig,
        {
          tabWidth: 4
        }
      )
    ]
  }
  // ... other config
}

This works for simple scenarios but it doesn't account for other configs which may try to configure prettier. You don't get to extend it across multiple configs like you can do with individual rules.

npetruzzelli commented 5 years ago

You may also want to be aware of the following: https://github.com/prettier/eslint-plugin-prettier/blob/3e9aa399ee3c0394a397f6ed3f8ec7c5e1597991/README.md#options

At some point in the future I should see if I can support this in both ESLint's and Prettier's config files. If I remember correctly, Prettier may not have had an RC file when I first made this shareable config. I don't know when I will have time to look into it.

npetruzzelli commented 5 years ago

version 3.0.0 has been released, which will hopefully make it easier to extend Prettier configuration options.

The following references may be helpful: