-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Autocreate configuration from existing project code #3567
Comments
Let's split out that secondary goal into a different feature. The bootstrapping experience is the top priority for us. |
Just as a reference there's a tool out there that does some of this: https://github.com/willklein/dryer |
Yeah, we wanted to reach out to see if incorporating it would be an option. |
Yep, @willklein and I have chatted, and he did a little investigatory work a while back towards integrating into ESLint. Then I think we both took a break until #1025 and #948 were addressed. Now that those are complete, I think we can jump back into it. I'm starting by putting together a small tool which will create rule combinations, which dryer does not currently do. |
I was talking with @MiguelCastillo, and he had the idea to pick a reasonable number (half dozen or so) of the most popular rules and start by autoconfiguring just those, and then add more in as demand dictates. My original thinking had been to examine all rules against the target project (or at least those rules with enumerable/binary configurations). Thoughts? |
Knowing how many rules we have that support more then one option, I think we might be talking about thousands of permutations here. I'm not sure all rules can be run against target. All rules without options would be fine though, I think. |
@ilyavolodin Is your concern about performance, user experience, or difficulty of implementation (or maybe something else)? Many of the more useful rules have enum options of just two values (such as "always" and "never") so they wouldn't add much overhead. Open-ended options like |
If we just take a small subset of rules, then I'm not sure it will be much more useful than what --init already does. I agree that performance shouldn't be a factor here so long as it doesn't take minutes. |
My initial testing showed it would take multiple (potentially many) minutes, but there have since been enhancements that should help us optimize this. Specifically, #948 and #1025 might help. I also think we should be able to handle the enumerable options, and we should test and configure the full set of rules with very few, if any, exceptions. For rules that can't be enumerated, it may suffice to test the default configuration. |
Can we cut into that time by pre-generating all possible rule configurations (maybe at release time)? |
That's probably a good idea. Let's see how long that generation takes first. I have a feeling it will be a drop in the bucket compared to the time needed for actually linting over and over with those configurations. I have some thoughts how to do that more efficiently as well, but need to do more thinking and prototyping to flesh them out. |
Getting started on this. So far I'm generating configurations for empty schemas and enums. |
I'm now also generating configs for some config object properties (enums). My thinking is to create configurations with all properties set explicitly (i.e. no defaults), so for instance, the configurations I check for [ [ 2, { align: 'colon', mode: 'strict' } ],
[ 2, { align: 'colon', mode: 'minimum' } ],
[ 2, { align: 'value', mode: 'strict' } ],
[ 2, { align: 'value', mode: 'minimum' } ] ] And once the boolean properties |
I think that's fine. I generally believe being explicit is better than trusting defaults anyway. :) |
Turns out that approach may not make sense for lines-around-comment, which has 10 boolean options. Rather than linting 1,024 times to check every possible combination, it would be better to check each option individually. All the other rules have reasonable numbers of combinations (two have 16, the rest have < 10). |
Is it reasonable to expect (at least for an initial implementation) the user to manually create an |
Here's another idea. Instead of adding a new |
That's what I was going to suggest. Either make it part of the |
👍 |
Oops, meant 👍 to making it part of |
I just ran autoconfig on a new repository and have a a few comments for the future. I wouldn't want to add those to the initial implementation, but wanted to record them somewhere for future enhancements:
|
Thanks, those are great ideas. Some other pieces I haven't had time to implement so far:
Metadata will be very useful for a number of reasons, as you've mentioned already. Right now the rules are being sorted alphabetically, which seemed to be the only logical order when we're talking about 200 rules, since it makes them easier to find if you're just scanning through. I thought about grouping on/off rules, but I think that's less desirable in the long run, since configs are not static, and personally I don't like to reorder my rules when I turn them on and off. But, maybe we can play with groupings that make sense. |
This adds an option to `--init`, which will ask for a set of files to examine, and then lint those files with various rule configuration settings. Based on the results of that linting, it will generate a configuration file which minimizes the number of errors. Rules in `eslint:recommended` will not be disabled, so they may still result in erorrs, but all other rules will not give errors when linted against the same set of files which was examined. This also adds some utility functions, like `getSourceCodeOfFiles()` from `lib/util/source-code-util.js`, utilities for working with npm (`lib/util/npm-util.js`) and it extracts the default cli options into `conf/cli-options.js`. At this time, this feature cannot be used for JSX code, due to #5007. Commits which were squashed into this commit: 74869b5 Create autoconfig module 0d01ec3 Address comments so far ebb9e56 Create helper for obtaining SourceCode from file(s) c5215b6 Add autogenerate option to `—-init` e00cb80 Add logic for collecting linting errors by rule config ea614d0 Create config files with sorted keys ab0a899 Add logic to choose “best” rule configs 1345e49 Do not initialize errorCount in registry to zero 5350fe5 Add a progress bar for reporting execution time. 7bec887 Use new parserOptions 06bedcc Remove manual rule blacklist dc95669 Define ruleConfig and registryItem in JSDoc typedefs 2036ec5 Avoid populating registry upon construction 6581c18 Refactor and improve f3290b8 Extend from “eslint:recommended” 7f39778 Doc cleanup 545a229 Break up Registry methods aa7318b Split rule configuration from autoconfig 8a370cc Only disable rules which have no determined error-free config 9033b62 Do not disable eslint:recommended rules a18b766 Add tests for config generation from schema 43c54b8 Pull default CLIEngineConfig into config file 10c0ea7 Add tests for createCoreRuleConfigs() f032556 Add initial tests for SourceCodeObtain aded766 Make options optional for getSourceCodeOfFiles 2480b42 Add more tests for SourceCodeObtain 67a8e75 Don’t export RuleConfigSet 9378f75 Account for new location of ecmaFeatures in config 3691dd4 Add some tests for config-initializer processAnswers() 3362eb9 Pass around Inquirer ui object explicitly f8b1689 Rename `source-code-obtain` to `source-code-util` 3199afa Use Uppercase for Object and Registry in JSDoc b39832a Install eslint-plugin-react before autoconfig runs 4c336fa Ask if the project is using ES6 modules 5e27d5c Pull npm installation into separate utility b99d288 Add cwd to default cli options ec526b3 Cleanups based on @gyandeeps’s review 1fcdc7b Stub out npm utility functions 36ed7e6 Fix bug when schema contains an enum and empty obj dd64ffc Add initial tests for autoconfig 59a7247 Use logging utility f486a5b Extend options from the defaults bb2f63d Add more tests for autoconfig f80d36e Disable autoconfig for JSX code, for now
This adds an option to `--init`, which will ask for a set of files to examine, and then lint those files with various rule configuration settings. Based on the results of that linting, it will generate a configuration file which minimizes the number of errors. Rules in `eslint:recommended` will not be disabled, so they may still result in erorrs, but all other rules will not give errors when linted against the same set of files which was examined. This also adds some utility functions, like `getSourceCodeOfFiles()` from `lib/util/source-code-util.js`, utilities for working with npm (`lib/util/npm-util.js`) and it extracts the default cli options into `conf/cli-options.js`. At this time, this feature cannot be used for JSX code, due to #5007. Commits which were squashed into this commit: 74869b5 Create autoconfig module 0d01ec3 Address comments so far ebb9e56 Create helper for obtaining SourceCode from file(s) c5215b6 Add autogenerate option to `—-init` e00cb80 Add logic for collecting linting errors by rule config ea614d0 Create config files with sorted keys ab0a899 Add logic to choose “best” rule configs 1345e49 Do not initialize errorCount in registry to zero 5350fe5 Add a progress bar for reporting execution time. 7bec887 Use new parserOptions 06bedcc Remove manual rule blacklist dc95669 Define ruleConfig and registryItem in JSDoc typedefs 2036ec5 Avoid populating registry upon construction 6581c18 Refactor and improve f3290b8 Extend from “eslint:recommended” 7f39778 Doc cleanup 545a229 Break up Registry methods aa7318b Split rule configuration from autoconfig 8a370cc Only disable rules which have no determined error-free config 9033b62 Do not disable eslint:recommended rules a18b766 Add tests for config generation from schema 43c54b8 Pull default CLIEngineConfig into config file 10c0ea7 Add tests for createCoreRuleConfigs() f032556 Add initial tests for SourceCodeObtain aded766 Make options optional for getSourceCodeOfFiles 2480b42 Add more tests for SourceCodeObtain 67a8e75 Don’t export RuleConfigSet 9378f75 Account for new location of ecmaFeatures in config 3691dd4 Add some tests for config-initializer processAnswers() 3362eb9 Pass around Inquirer ui object explicitly f8b1689 Rename `source-code-obtain` to `source-code-util` 3199afa Use Uppercase for Object and Registry in JSDoc b39832a Install eslint-plugin-react before autoconfig runs 4c336fa Ask if the project is using ES6 modules 5e27d5c Pull npm installation into separate utility b99d288 Add cwd to default cli options ec526b3 Cleanups based on @gyandeeps’s review 1fcdc7b Stub out npm utility functions 36ed7e6 Fix bug when schema contains an enum and empty obj dd64ffc Add initial tests for autoconfig 59a7247 Use logging utility f486a5b Extend options from the defaults bb2f63d Add more tests for autoconfig f80d36e Disable autoconfig for JSX code, for now Plus a few others ...
This adds an option to `--init`, which will ask for a set of files to examine, and then lint those files with various rule configuration settings. Based on the results of that linting, it will generate a configuration file which minimizes the number of errors. Rules in `eslint:recommended` will not be disabled, so they may still result in erorrs, but all other rules will not give errors when linted against the same set of files which was examined. This also adds some utility functions, like `getSourceCodeOfFiles()` from `lib/util/source-code-util.js`, utilities for working with npm (`lib/util/npm-util.js`) and it extracts the default cli options into `conf/cli-options.js`. At this time, this feature cannot be used for JSX code, due to #5007. Commits which were squashed into this commit: 74869b5 Create autoconfig module 0d01ec3 Address comments so far ebb9e56 Create helper for obtaining SourceCode from file(s) c5215b6 Add autogenerate option to `—-init` e00cb80 Add logic for collecting linting errors by rule config ea614d0 Create config files with sorted keys ab0a899 Add logic to choose “best” rule configs 1345e49 Do not initialize errorCount in registry to zero 5350fe5 Add a progress bar for reporting execution time. 7bec887 Use new parserOptions 06bedcc Remove manual rule blacklist dc95669 Define ruleConfig and registryItem in JSDoc typedefs 2036ec5 Avoid populating registry upon construction 6581c18 Refactor and improve f3290b8 Extend from “eslint:recommended” 7f39778 Doc cleanup 545a229 Break up Registry methods aa7318b Split rule configuration from autoconfig 8a370cc Only disable rules which have no determined error-free config 9033b62 Do not disable eslint:recommended rules a18b766 Add tests for config generation from schema 43c54b8 Pull default CLIEngineConfig into config file 10c0ea7 Add tests for createCoreRuleConfigs() f032556 Add initial tests for SourceCodeObtain aded766 Make options optional for getSourceCodeOfFiles 2480b42 Add more tests for SourceCodeObtain 67a8e75 Don’t export RuleConfigSet 9378f75 Account for new location of ecmaFeatures in config 3691dd4 Add some tests for config-initializer processAnswers() 3362eb9 Pass around Inquirer ui object explicitly f8b1689 Rename `source-code-obtain` to `source-code-util` 3199afa Use Uppercase for Object and Registry in JSDoc b39832a Install eslint-plugin-react before autoconfig runs 4c336fa Ask if the project is using ES6 modules 5e27d5c Pull npm installation into separate utility b99d288 Add cwd to default cli options ec526b3 Cleanups based on @gyandeeps’s review 1fcdc7b Stub out npm utility functions 36ed7e6 Fix bug when schema contains an enum and empty obj dd64ffc Add initial tests for autoconfig 59a7247 Use logging utility f486a5b Extend options from the defaults bb2f63d Add more tests for autoconfig f80d36e Disable autoconfig for JSX code, for now f1a77e9 Remove timeout c71bf08 Check package.json instead of installation status Plus a few others ...
This adds an option to `--init`, which will ask for a set of files to examine, and then lint those files with various rule configuration settings. Based on the results of that linting, it will generate a configuration file which minimizes the number of errors. Rules in `eslint:recommended` will not be disabled, so they may still result in erorrs, but all other rules will not give errors when linted against the same set of files which was examined. This also adds some utility functions, like `getSourceCodeOfFiles()` from `lib/util/source-code-util.js`, utilities for working with npm (`lib/util/npm-util.js`) and it extracts the default cli options into `conf/cli-options.js`. At this time, this feature cannot be used for JSX code, due to #5007. Commits which were squashed into this commit: 74869b5 Create autoconfig module 0d01ec3 Address comments so far ebb9e56 Create helper for obtaining SourceCode from file(s) c5215b6 Add autogenerate option to `—-init` e00cb80 Add logic for collecting linting errors by rule config ea614d0 Create config files with sorted keys ab0a899 Add logic to choose “best” rule configs 1345e49 Do not initialize errorCount in registry to zero 5350fe5 Add a progress bar for reporting execution time. 7bec887 Use new parserOptions 06bedcc Remove manual rule blacklist dc95669 Define ruleConfig and registryItem in JSDoc typedefs 2036ec5 Avoid populating registry upon construction 6581c18 Refactor and improve f3290b8 Extend from “eslint:recommended” 7f39778 Doc cleanup 545a229 Break up Registry methods aa7318b Split rule configuration from autoconfig 8a370cc Only disable rules which have no determined error-free config 9033b62 Do not disable eslint:recommended rules a18b766 Add tests for config generation from schema 43c54b8 Pull default CLIEngineConfig into config file 10c0ea7 Add tests for createCoreRuleConfigs() f032556 Add initial tests for SourceCodeObtain aded766 Make options optional for getSourceCodeOfFiles 2480b42 Add more tests for SourceCodeObtain 67a8e75 Don’t export RuleConfigSet 9378f75 Account for new location of ecmaFeatures in config 3691dd4 Add some tests for config-initializer processAnswers() 3362eb9 Pass around Inquirer ui object explicitly f8b1689 Rename `source-code-obtain` to `source-code-util` 3199afa Use Uppercase for Object and Registry in JSDoc b39832a Install eslint-plugin-react before autoconfig runs 4c336fa Ask if the project is using ES6 modules 5e27d5c Pull npm installation into separate utility b99d288 Add cwd to default cli options ec526b3 Cleanups based on @gyandeeps’s review 1fcdc7b Stub out npm utility functions 36ed7e6 Fix bug when schema contains an enum and empty obj dd64ffc Add initial tests for autoconfig 59a7247 Use logging utility f486a5b Extend options from the defaults bb2f63d Add more tests for autoconfig f80d36e Disable autoconfig for JSX code, for now f1a77e9 Remove timeout c71bf08 Check package.json instead of installation status Plus a few others ...
This adds an option to `--init`, which will ask for a set of files to examine, and then lint those files with various rule configuration settings. Based on the results of that linting, it will generate a configuration file which minimizes the number of errors. Rules in `eslint:recommended` will not be disabled, so they may still result in erorrs, but all other rules will not give errors when linted against the same set of files which was examined. This also adds some utility functions, like `getSourceCodeOfFiles()` from `lib/util/source-code-util.js`, utilities for working with npm (`lib/util/npm-util.js`) and it extracts the default cli options into `conf/cli-options.js`. At this time, this feature cannot be used for JSX code, due to #5007. Commits which were squashed into this commit: 74869b5 Create autoconfig module 0d01ec3 Address comments so far ebb9e56 Create helper for obtaining SourceCode from file(s) c5215b6 Add autogenerate option to `—-init` e00cb80 Add logic for collecting linting errors by rule config ea614d0 Create config files with sorted keys ab0a899 Add logic to choose “best” rule configs 1345e49 Do not initialize errorCount in registry to zero 5350fe5 Add a progress bar for reporting execution time. 7bec887 Use new parserOptions 06bedcc Remove manual rule blacklist dc95669 Define ruleConfig and registryItem in JSDoc typedefs 2036ec5 Avoid populating registry upon construction 6581c18 Refactor and improve f3290b8 Extend from “eslint:recommended” 7f39778 Doc cleanup 545a229 Break up Registry methods aa7318b Split rule configuration from autoconfig 8a370cc Only disable rules which have no determined error-free config 9033b62 Do not disable eslint:recommended rules a18b766 Add tests for config generation from schema 43c54b8 Pull default CLIEngineConfig into config file 10c0ea7 Add tests for createCoreRuleConfigs() f032556 Add initial tests for SourceCodeObtain aded766 Make options optional for getSourceCodeOfFiles 2480b42 Add more tests for SourceCodeObtain 67a8e75 Don’t export RuleConfigSet 9378f75 Account for new location of ecmaFeatures in config 3691dd4 Add some tests for config-initializer processAnswers() 3362eb9 Pass around Inquirer ui object explicitly f8b1689 Rename `source-code-obtain` to `source-code-util` 3199afa Use Uppercase for Object and Registry in JSDoc b39832a Install eslint-plugin-react before autoconfig runs 4c336fa Ask if the project is using ES6 modules 5e27d5c Pull npm installation into separate utility b99d288 Add cwd to default cli options ec526b3 Cleanups based on @gyandeeps’s review 1fcdc7b Stub out npm utility functions 36ed7e6 Fix bug when schema contains an enum and empty obj dd64ffc Add initial tests for autoconfig 59a7247 Use logging utility f486a5b Extend options from the defaults bb2f63d Add more tests for autoconfig f80d36e Disable autoconfig for JSX code, for now f1a77e9 Remove timeout c71bf08 Check package.json instead of installation status 86d6c09 Ignore existing eslint config files 3125f90 Use shelljs for execSync 764c291 Avoid changing process.cwd 9845060 Pass cwd to getSourceCodeOfFiles Plus a few others ...
This adds an option to `--init`, which will ask for a set of files to examine, and then lint those files with various rule configuration settings. Based on the results of that linting, it will generate a configuration file which minimizes the number of errors. Rules in `eslint:recommended` will not be disabled, so they may still result in erorrs, but all other rules will not give errors when linted against the same set of files which was examined. This also adds some utility functions, like `getSourceCodeOfFiles()` from `lib/util/source-code-util.js`, utilities for working with npm (`lib/util/npm-util.js`) and it extracts the default cli options into `conf/cli-options.js`. At this time, this feature cannot be used for JSX code, due to #5007. Commits which were squashed into this commit: 74869b5 Create autoconfig module 0d01ec3 Address comments so far ebb9e56 Create helper for obtaining SourceCode from file(s) c5215b6 Add autogenerate option to `—-init` e00cb80 Add logic for collecting linting errors by rule config ea614d0 Create config files with sorted keys ab0a899 Add logic to choose “best” rule configs 1345e49 Do not initialize errorCount in registry to zero 5350fe5 Add a progress bar for reporting execution time. 7bec887 Use new parserOptions 06bedcc Remove manual rule blacklist dc95669 Define ruleConfig and registryItem in JSDoc typedefs 2036ec5 Avoid populating registry upon construction 6581c18 Refactor and improve f3290b8 Extend from “eslint:recommended” 7f39778 Doc cleanup 545a229 Break up Registry methods aa7318b Split rule configuration from autoconfig 8a370cc Only disable rules which have no determined error-free config 9033b62 Do not disable eslint:recommended rules a18b766 Add tests for config generation from schema 43c54b8 Pull default CLIEngineConfig into config file 10c0ea7 Add tests for createCoreRuleConfigs() f032556 Add initial tests for SourceCodeObtain aded766 Make options optional for getSourceCodeOfFiles 2480b42 Add more tests for SourceCodeObtain 67a8e75 Don’t export RuleConfigSet 9378f75 Account for new location of ecmaFeatures in config 3691dd4 Add some tests for config-initializer processAnswers() 3362eb9 Pass around Inquirer ui object explicitly f8b1689 Rename `source-code-obtain` to `source-code-util` 3199afa Use Uppercase for Object and Registry in JSDoc b39832a Install eslint-plugin-react before autoconfig runs 4c336fa Ask if the project is using ES6 modules 5e27d5c Pull npm installation into separate utility b99d288 Add cwd to default cli options ec526b3 Cleanups based on @gyandeeps’s review 1fcdc7b Stub out npm utility functions 36ed7e6 Fix bug when schema contains an enum and empty obj dd64ffc Add initial tests for autoconfig 59a7247 Use logging utility f486a5b Extend options from the defaults bb2f63d Add more tests for autoconfig f80d36e Disable autoconfig for JSX code, for now f1a77e9 Remove timeout c71bf08 Check package.json instead of installation status 86d6c09 Ignore existing eslint config files 3125f90 Use shelljs for execSync 764c291 Avoid changing process.cwd 9845060 Pass cwd to getSourceCodeOfFiles f1c2176778f2c81390709e05ae848adb7cc6d976 Don’t split on commas Plus a few others ...
This issue is for discussion of a new feature which would generate a configuration file based on the code styles and conventions already in use in a project.
Background: When new users are adding ESLint to an existing project, the first step is often to sift through the many ESLint rules to find the ones which are applicable to the project. While it might be easy to simply enable all of the Possible Errors and Best Practices rules, Stylistic Issues are much more subjective and need to be carefully examined, one-by-one.
What is being proposed here is to allow the code style already in use in the project to guide the creation of an
.eslintrc
configuration file.The most likely way this can be accomplished is by repeatedly linting the code with rules set with different options, and comparing the number of linting errors that result from each option. Now that ea1871f has landed, it should only be necessary to parse the code once, thereby improving performance.
What still needs some thought and discussion, is the criteria for deciding which rules to enable in the generated config. Some ideas:
"always"
vs."never"
, if there are errors for both options, set to warn if one option has < X% of the errors when set to the other option. For example, if"always"
gives 5 errors, and"never"
gives 100, it's likely the style in the project is"always"
, and those 5 errors are just errors. However, if both options give 50 errors each, the project probably doesn't want to enforce that rule at all.A secondary goal of this is to be runnable against a project already using ESLint, to pick up new rules or make rules more strict if they are not erroring (see #3436).
The text was updated successfully, but these errors were encountered: