Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: ability to pass path to config file #638

Closed
mrsauravsahu opened this issue Nov 20, 2021 · 9 comments · May be fixed by #664
Closed

feature request: ability to pass path to config file #638

mrsauravsahu opened this issue Nov 20, 2021 · 9 comments · May be fixed by #664

Comments

@mrsauravsahu
Copy link

mrsauravsahu commented Nov 20, 2021

To reuse xo-config across multiple projects in my monorepo, I have to run xo from each of my projects directory (otherwise I get file is not in cwd error)

$ ./node_modules/.bin/xo ../../srv/souvenirs
Error: Path /souvenirs/srv/souvenirs/BUILD is not in cwd /souvenirs/common/lint_xo
    at ensureAbsolutePathForCwd (file:///souvenirs/common/lint_xo/node_modules/globby/gitignore.js:54:9)
    at file:///souvenirs/common/lint_xo/node_modules/globby/gitignore.js:60:95
    at file:///souvenirs/common/lint_xo/node_modules/globby/index.js:142:47
    at Array.filter (<anonymous>)
    at globby (file:///souvenirs/common/lint_xo/node_modules/globby/index.js:142:30)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async globFiles (file:///souvenirs/common/lint_xo/node_modules/xo/index.js:23:16)
    at async Object.lintFiles (file:///souvenirs/common/lint_xo/node_modules/xo/index.js:67:16)
    at async file:///souvenirs/common/lint_xo/node_modules/xo/cli.js:211:18

As mentioned in the docs, the xo config can be put in the package.json, with the xo key. This, again, doesn't work because of the above error, as I will be running xo from the projects' folder and each of them have their own package.json and I want to keep the xo-config centralized.

Is it already possible to pass the path to config as a switch? If not, I'm happy to collaborate and add this feature in!

Thanks
-S

@macarie
Copy link

macarie commented Nov 30, 2021

I (think?) have the same problem.

In a monorepo setup, I have xo as a dev-dependency and its configuration inside /package.json, as mentioned in the readme, then I have /packages/module/package.json containing a lint script ("xo").

Xo doesn't pick up the configuration from /package.json if launched from inside the module's directory, and neither does it if launched from the root directory with pnpm run -r lint.

The workaround I found to be working is having "xo --cwd ../.. packages/module/source" as my lint script in /packages/module/package.json.

I've looked a bit around, and I think the line that causes this issue is this one:

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

I've tried locally, and removing the stopDir property seems to be solving this issue.

I can open a PR, but I'm not sure if this is indeed a bug or a known/wanted behavior.

@8ctopus
Copy link

8ctopus commented Jan 25, 2022

Same problem here. running xo with --cwd does not trigger the error but does not lint either.

@mrsauravsahu
Copy link
Author

I'm having to use eslint for now until I add this feature into xo. Would love to work on this together if anyone's interested.

@AbdallahAbis
Copy link

Any workaround for this?

@mrsauravsahu
Copy link
Author

I've made the basic changes in code and everything seems to be working. I didn't have time to look at the test setup. Will do that now.

#664 created a draft PR.

You can pass the config file path like so.

I'm testing with a playground folder, that's where my code is and config has the .xo-config.json
./node_modules/.bin/xo --config-path config/.xo-config.json --cwd playground

@jwr1
Copy link

jwr1 commented May 12, 2022

The --config-path option is a good idea, but It seems like xo should also be able to automatically look up through the file tree for a config so the path does not need to be specified each time.

@mrsauravsahu
Copy link
Author

It does. But for our use case the config isn’t up the file tree. It’s in a different config folder altogether.

@jwr1
Copy link

jwr1 commented May 12, 2022

It seems like the config resolver is not working for me, I might just open a separate issue.

@fregante
Copy link
Member

fregante commented Aug 6, 2022

This is being tracked in

@fregante fregante marked this as a duplicate of #448 Aug 6, 2022
@fregante fregante closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants