Open btmills opened 1 month ago
To implement the fallback configuration feature in ESLint, follow these steps:
Introduce a new command-line option --fallback-config
in lib/cli.js
. This option will allow users to specify a path to a fallback configuration file.
// lib/cli.js
// Add new CLI option
program.option('--fallback-config <path>', 'Path to a fallback configuration file');
Update the configuration resolution logic in lib/eslint/legacy-eslint.js
. This logic should now check for the --fallback-config
option when no other configuration is found. If the fallback configuration file exists, it should be used as the configuration file.
// lib/eslint/legacy-eslint.js
// Modify processOptions function to include fallbackConfigFile
function processOptions({
// ... existing parameters
fallbackConfigFile = null, // Add new parameter for fallback config
// ... rest of the parameters
}) {
// ... existing logic
// Modify the logic to use fallbackConfigFile when no configFile is found
if (!configFile && fallbackConfigFile) {
try {
if (fs.existsSync(fallbackConfigFile)) {
configFile = fallbackConfigFile;
} else {
throw new Error(`Fallback configuration file not found: ${fallbackConfigFile}`);
}
} catch (error) {
// Handle file not found or other errors
console.error(error.message);
process.exit(1);
}
}
// ... rest of the function
}
Enhance the ESLint documentation to explain the new --fallback-config
option. This should be done in docs/src/use/configure/configuration-files.md
. Include a new section under "Configuration File Resolution" detailing how the fallback configuration works and provide usage examples.
Ensure that the new documentation section is clear, concise, and includes necessary examples for users to understand how to use the --fallback-config
option effectively.
lib/eslint/legacy-eslint.js:163-707 | Contains 'overrideConfigFile' option handling, relevant to the issue of conflicting ESLint configurations.
lib/eslint/eslint-helpers.js:1-727 | The function 'processOptions' handles various configuration options including 'overrideConfigFile', which is directly relevant for implementing the fallback configuration feature.
ESLint version
v8.25.0
What problem do you want to solve?
I usually work with files that are not part of a project. They are just files on the fly on my machine.
Since I like to use the "standard" rule, I have installed it globally and added the option "overrideConfigFile" to vscode eslint extension. This way I don't have to install "standard" and any other plugins every single time.
The problem comes when I have to work on a project with its own eslint rules. If I use "overrideConfigFile", it will cause some problems, like a plugin is not found or the project itself is not using "standard".
To solve this problem, I just have to open vscode "settings.json" file and comment out "overrideConfigFile" option.
What do you think is the correct solution?
Skip the manual process of commenting out "overrideConfigFile" in vscode settings by following the next:
If any eslint config or config file is not found on root and up directories, use the file declared in "overrideConfigFile" option (or a new option name).
Participation
Additional comments
I'm opening the request over here instead of vscode eslint extension repository because while I was looking for a solution to this problem, I found out they rely entirely on the features you add: https://github.com/microsoft/vscode-eslint/issues/482#issuecomment-395336940
So I understand if this feature is added on a new version, it would be available on vscode eslint extension as well.