xojs/xo

Add option to explicitly tell xo to use a config file

Opened this issue · 5 comments

In my current project, my xo config file isn't in any of the parent directories of the linted files, but instead in a separate directory. However, I still want to be able to use my custom config, without having to move it to one of the parent directories or publish it to npm.

In my opinion, a decent solution to the issue would be to add a --config option to xo, which (when specified) would tell xo to use the configuration at the given path (e.g. xo --config ../.xo-config.json).

I'd appreciate your feedback, and if you agree this should be a part of xo, let me know and I'll be happy to implement this.

(Note that this could resolve #250 as well.)

pvdlg commented

Would having a minimal config at the root of your repo that extends you global works?
For example in your the package.json:

{
  "xo": {
    "extends": ["../path/to/global/config"]
  }
}

@pvdlg Apologies for the delay in my response, I forgot to reply to you.

That would work, however I'd say that it would be best to allow people to configure this either in package.json or via a flag.

I had made the changes for this. Just need to do the final testing, but I'm short on time.

https://github.com/mrsauravsahu/xo/tree/feat/config-path-option

I was able to kind of have a work around for my current project by using a cjs config file:

const config = require('../../.xo-config.cjs')
module.exports = {
  ...config
}

Somehow the "parent folder import" for monorepo setups also did not work for me. Not sure if it's related to me using .cjs config files instead of putting it into the package.json but at least this way I only have to really manage one .xo-config.cjs file and all the others can extend it if necessary and fall back to my defaults for the project.