xojs/xo

Projects in a Turborepo monorepo not using workspace package.json config

Opened this issue · 2 comments

Hello,

I have a very simple XO configuration I'd like to share between all the packages and apps in my Turborepo monorepo:

"xo": {
  "prettier": true,
  "rules": {
    "import/extensions": 0
  }
}

The project README states that I should just need one version of this in the root package.json file:

However, I'm seeing linting errors in each of my packages if I don't have this XO config in every package.json. Have I configured something incorrectly?

I'm seeing the same behavior / having the same problem. Running xo in a sub-package does not seem to "search upwards" and find the parent package.json config.

- package.json         # Includes XO config
- packages/
    - packageName/
        - package.json # Does not include XO config

I believe there are some magic filenames that might work - I'll try those out and report back. I'll watch this issue with interest though, as I'd rather not have yet another root config file.

I've found the discrepancy!

From lines 103 and 104 of lib/options-manager.js:

options.cwd = path.resolve(options.cwd || process.cwd());
const configExplorer = cosmiconfig(MODULE_NAME, {searchPlaces: CONFIG_FILES, loaders: {noExt: defaultLoaders['.json']}, stopDir: options.cwd});

Note that stopDir is set to options.cwd, which defaults to process.cwd().

From the comsiconfig readme:

  • If none of those searches reveal a configuration object, move up one directory level and try again. So the search continues in ./, ../, ../../, ../../../, etc., checking the same places in each directory.
  • Continue searching until arriving at your home directory (or some other directory defined by the cosmiconfig option stopDir).

In short, xo does not search upwards - the search is stopped in the current working directory.

Workaround

  1. Use the --cwd flag to start xo from your monorepo root (overriding options.cwd)
  2. Narrow scope back down by specifying the subfolder you want
{
    "scripts": {
        "lint": "xo --cwd=../.. $(pwd)"
    }
}

There's probably a better way to identify the monorepo root than just hard-coding ../.., but that's all I've got for now.