diff --git a/cli.js b/cli.js index a12b8d0c..67e804ad 100755 --- a/cli.js +++ b/cli.js @@ -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 @@ -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\`. @@ -110,6 +112,9 @@ const cli = meow(` stdinFilename: { type: 'string', }, + configPath: { + type: 'string', + }, }, }); diff --git a/lib/options-manager.js b/lib/options-manager.js index 8f411509..bf49959f 100644 --- a/lib/options-manager.js +++ b/lib/options-manager.js @@ -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({ @@ -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