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

fix: --inspect-config only for flat config and respect -c #18306

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: --inspect-config only for flat config and respect -c
  • Loading branch information
nzakas committed Apr 9, 2024
commit 786cc1c254ed48642ac0e205d8e98f0c0741da4f
12 changes: 0 additions & 12 deletions bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,6 @@ ${getErrorMessage(error)}`;
return;
}

// Call the config inspector if `--inspect-config` is present.
if (process.argv.includes("--inspect-config")) {

console.warn("You can also run this command directly using 'npx @eslint/config-inspector' in the same directory as your configuration file.");

const spawn = require("cross-spawn");

spawn.sync("npx", ["@eslint/config-inspector"], { encoding: "utf8", stdio: "inherit" });

return;
}

// Otherwise, call the CLI.
const cli = require("../lib/cli");
const exitCode = await cli.execute(
Expand Down
47 changes: 46 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const fs = require("fs"),
path = require("path"),
{ promisify } = require("util"),
{ LegacyESLint } = require("./eslint"),
{ ESLint, shouldUseFlatConfig } = require("./eslint/eslint"),
{ ESLint, shouldUseFlatConfig, locateConfigFileToUse } = require("./eslint/eslint"),
createCLIOptions = require("./options"),
log = require("./shared/logging"),
RuntimeInfo = require("./shared/runtime-info"),
Expand Down Expand Up @@ -336,6 +336,27 @@ async function printResults(engine, results, format, outputFile, resultsMeta) {
*/
const cli = {

/**
* Calculates the command string for the --inspect-config operation.
* @param {string} configFile The path to the config file to inspect.
* @returns {Promise<string>} The command string to execute.
*/
async calculateInspectConfigFlags(configFile) {

// find the config file
const {
configFilePath,
basePath,
error
} = await locateConfigFileToUse({ cwd: process.cwd(), configFile });

if (error) {
throw error;
}

return ["--config", configFilePath, "--basePath", basePath];
},

/**
* Executes the CLI based on an array of arguments that is passed in.
* @param {string|Array|Object} args The arguments to process.
Expand Down Expand Up @@ -425,6 +446,30 @@ const cli = {
return 0;
}

if (options.inspectConfig) {

// we can only use this option with flat config
if (!usingFlatConfig) {
log.error("The --inspect-config option is only available when using an eslint.config.js file.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the actual result is:

Invalid option '--inspect-config' - perhaps you meant '--inline-config'?

seems the code was never excuted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, good call. Forgotten during refactoring.

return 2;
}

log.info("You can also run this command directly using 'npx @eslint/config-inspector' in the same directory as your configuration file.");

try {
const flatOptions = await translateOptions(options, "flat");
const spawn = require("cross-spawn");
const flags = await cli.calculateInspectConfigFlags(flatOptions.overrideConfigFile);

spawn.sync("npx", ["@eslint/config-inspector", ...flags], { encoding: "utf8", stdio: "inherit" });
} catch (error) {
log.error(error);
return 2;
}

return 0;
}

debug(`Running on ${useStdin ? "text" : "files"}`);

if (options.fix && options.fixDryRun) {
Expand Down
3 changes: 2 additions & 1 deletion lib/eslint/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -1214,5 +1214,6 @@ async function shouldUseFlatConfig() {

module.exports = {
ESLint,
shouldUseFlatConfig
shouldUseFlatConfig,
locateConfigFileToUse
};
Loading