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

feat: pass path to config as a cli option --config-path #664

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions cli.js
Expand Up @@ -30,6 +30,7 @@ const cli = meow(`
--stdin Validate/fix code from stdin
--stdin-filename Specify a filename for the --stdin option
--print-config Print the effective ESLint config for the given file
--config-path Path to the config file to use

Examples
$ xo
Expand All @@ -41,6 +42,7 @@ const cli = meow(`
$ xo --plugin=html --extension=html
$ echo 'const x=true' | xo --stdin --fix
$ xo --print-config=index.js
$ xo --config-path=../config/.xo-config.json

Tips
- Add XO to your project with \`npm init xo\`.
Expand Down Expand Up @@ -110,6 +112,9 @@ const cli = meow(`
stdinFilename: {
type: 'string',
},
configPath: {
type: 'string',
},
},
});

Expand Down
10 changes: 8 additions & 2 deletions lib/options-manager.js
Expand Up @@ -107,7 +107,14 @@ const mergeWithFileConfig = async options => {
}

const searchPath = options.filePath || options.cwd;
const {config: xoOptions, filepath: xoConfigPath} = (await configExplorer.search(searchPath)) || {};

let {config: xoOptions , filepath: xoConfigPath} = (await configExplorer.search(searchPath)) || {};
if (options.configPath) {
const searchResultFromConfigPath = (await configExplorer.load(options.configPath)) || {};
xoOptions = searchResultFromConfigPath.config
xoConfigPath = searchResultFromConfigPath.filepath
}

const {config: enginesOptions} = (await pkgConfigExplorer.search(searchPath)) || {};

options = normalizeOptions({
Expand All @@ -117,7 +124,6 @@ const mergeWithFileConfig = async options => {
});
options.extensions = [...DEFAULT_EXTENSION, ...(options.extensions || [])];
options.ignores = getIgnores(options);
options.cwd = xoConfigPath && path.dirname(xoConfigPath) !== options.cwd ? path.resolve(options.cwd, path.dirname(xoConfigPath)) : options.cwd;

// Ensure eslint is ran minimal times across all linted files, once for each unique configuration
// incremental hash of: xo config path + override hash + tsconfig path
Expand Down