xojs/xo

Parent Folder Config File Ignored?

chrisspiegl opened this issue · 7 comments

Hello, I have been trying to get a parent folder / monorepo structure up and running with all kinds of ways. Tried following the instructions on the readme.md file and all.

However, I have not been able to do it. Next to that the xo-linter extension for VS Code also seems to not be able to find my config files.

I tried renaming them, converting them to JSON, etc. I even tried if the package.json structure would work. No luck with any of those options for both (cli and vs code extension).

Is there a trick that I don't know about?

Here is my .xo-config.cjs file which I am using and when I run my xo in the folder where the config file actually is, it also works.

Config File:
module.exports = {
	extensions: ['js', 'vue'],
	ignores: [
		'./dist', './ios',
	],
	rules: {
		semi: ['error', 'never'],
		indent: ['error', 2, {
			SwitchCase: 1,
		}],
		quotes: ['error', 'single', {
			allowTemplateLiterals: true,
		}],
		curly: ['error', 'multi-line'],
		'object-curly-spacing': ['error', 'always'],
		'arrow-parens': ['error', 'always'],
		'capitalized-comments': 'off',
		'import/extensions': [
			'error',
			'never',
			{
				json: 'always',
				vue: 'always',
				css: 'always',
				scss: 'always',
			},
		],
		'node/file-extension-in-import': [
			'error',
			'never',
			{
				tryExtensions: ['.js', '.json'],
				'.json': 'always',
				'.vue': 'always',
				'.css': 'always',
				'.scss': 'always',
			},
		],
		'import/no-unassigned-import': [
			'error',
			{
				allow: ['**/*.css', '**/*.scss'],
			},
		],
		// 'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0 }],
		// 'padding-line-between-statements': ['error', { blankLine: 'any', prev: '*', next: '*' }],
		// 'no-unused-vars': ['warn', { caughtErrors: 'none', varsIgnorePattern: '^error$', args: 'none' }],
		// 'require-await': 'error',
		// 'no-return-await': 'off',
		'unicorn/filename-case': [
			'error',
			{
				cases: {
					camelCase: true,
					pascalCase: true,
				},
				ignore: ['\\d*-[\\w\\d]*.js'],
			},
		],
		// 'unicorn/prefer-optional-catch-binding': 'off',
		// 'unicorn/no-process-exit': 'off',
	},
};

Duplicate of #475?

Could be related. But also maybe different. Since I am talking about the config files and not config inside package.json

https://github.com/spence-s/ts-monorepo - this works for me. WIth this example I use overrides in the root for the configuration for each app/project in the monorepo. -- Alternatively, you can put an xo config in each package/app. Always run xo from the root for either scenario.

Anyway - it's really hard to tell what you are asking here. Loads of ppl, including me, use xo with monorepos and its pretty flexible.

As far as finding things goes in the extension: You need to have xo as a dep in your package.json and it needs to be accessible in a local node_modules folder (yarn berry may break this, so use yarn classic, npm, or pnpm). Tried to make this clear in the extension documentation but may need to be more explicit about not supporting yarn pnp.

Hi @spence-s, thanks for your reply.

I think I might be trying to do something different. I thought I could run xo in the sub directories instead of only from the root of the project / monorepo.

Since I am working on specific parts, I thought I could run xo just on that part to get more targeted formatting prompts and so on. With this, I thought that it would be good if xo would search for parent directories for config files.

But it sounds like that is not something that's working at this time?
The other issues/PRs which are talking about a config file parameter as well as a global config file may be some other way for me to look into once they are added.

ahh i see - in your package/app folder use xo "./path/to/folder/from/root" --cwd "../../path/to/root"

So lets say you have a monorepo with the folder packages/lint-only-me and you want to lint only the lint-only-me folder.

navigate to the folder or in a package script, youd write xo "./packages/lint-only-me" --cwd "../.."

This is wonky but this would be the current work around for what you want. Basically you are tricking xo into thinking you running it from the root folder.

I think the extension should work already for what you want?? If not, please file a bug here https://github.com/xojs/vscode-linter-xo/issues

Oh wow, @spence-s, that sounds like it could be a real life safer for me to have less config files.
Yes, a bit of a workaround, but at least it would do the trick like I imagined it.

I have tried the extension but have not been able to get it to work with the config file in my project root. I will investigate in the coming weeks a bit more since I really like XO and want to use it more.

I also tried looking into XO with VUE.js but the extension I found (https://github.com/ChocPanda/eslint-config-xo-vue) seems not to be maintained any more. Though this is going off topic 🙈.

Thank you for your help with the workaround ❤.

Closing in favor of