-
Notifications
You must be signed in to change notification settings - Fork 28
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
The one lint config to rule them all (also how to get gjs/gts linting going) #71
Comments
cc @bendemboski as well |
since it's important to know how a file works when you first open it, we could move the actual .eslint config to the top of the file using using a getter within the main config: 'use strict';
module.exports = {
root: true,
/**
* No root rules needed, because we define everything with overrides
* so that understanding what set of rules is applied to what files
* is easier to understand.
*
* This can be debugged with
*
* eslint --print-config ./path/to/file
*/
rules: {},
get overrides() {
const config = proposedEmberDefault(personalPreferences);
return [
config.commonjs.node.js,
config.modules.browser.js,
config.modules.browser.ts,
config.modules.browser.declarations,
config.modules.tests.js,
config.modules.tests.ts,
].filter(Boolean);
}
};
// ... everything else in the file below here |
Proposed comments to be generated with the config file: 'use strict';
/**
* Demonstration of potential default Lint configuration for Ember.JS
* Supporting this matrix:
* - app, addon, tests, v2 addon
* - javascript, typescript, typescript declarations
*
* This first part is the minimal config provided to ESLint,
* represented in terms of "overrides"-only, which is much easier
* to understand than ESLint's traditional "cascading configs".
*
* See: https://eslint.org/blog/2022/08/new-config-system-part-2/
*
* Related: https:/eslint/eslint/discussions/16557
*/
module.exports = {
root: true,
/**
* No root rules needed, because we define everything with overrides
* so that understanding what set of rules is applied to what files
* is easier to understand.
*
* This can be debugged with
*
* eslint --print-config ./path/to/file
*/
rules: {},
/**
* Getters are used so that we can dynamically add-in various plugins
* based on the consumer's scenario.
*
* For example:
* - only include TypeScript rules if `typescript` is present in the
* hosting project.
*/
get overrides() {
/**
* Personal preferences may be passed to the config generator.
* It's only a little helpful utility for deep-merging some things into the browser-
* based config objects.
* This is because, when managing an eslint config, this is what folks will care about first.
* Overriding defaults.
*
* This is for integrating with with all the variants, the easy way.
* Obviously, if folks want to extend each of the `config.{format}.{platform}.{type}`
* objects above, the ESLint overrides API is all public, and doing so is straight forward.
*/
const config = proposedEmberDefault(personalPreferences);
return [
/**
* Each of these can be overriden via
* {
* ...config.commonjs.node.js,
* rules: {
* ...config.commonjs.node.js.rules,
* 'my-custom-rule-here': 'error',
* }
* }
*/
config.commonjs.node.js,
config.modules.browser.js,
config.modules.browser.ts,
config.modules.browser.declarations,
config.modules.tests.js,
config.modules.tests.ts,
].filter(Boolean);
}
}; |
It turns out that the latest eslint config documentation recommends that we do exactly what I'm proposing here! yay!! cc @bmish 🎉 |
gonna close this as it's really a meta issue across all ember projects, not addon-blueprint specifically -- also next time I propose a lint config change, I want it to use ESLint9's format (which is very nearly the above) |
Note, the details of this have changed a bit since we now have a real parser for eslint: https:/ember-cli/eslint-plugin-ember?tab=readme-ov-file#gtsgjs but the strategy is the same, and implemented over here: https:/NullVoxPopuli/eslint-configs/blob/main/configs/ember.js#L41-L43 |
A proposal in brief:
Covers:
typsecript
as a resolveable module -- cc @chriskrychoThoughts?:
sample repo if cloning is easier: https:/NullVoxPopuli/ember-lint-demonstrate-overrides-based-config
But also trying this out on a real project: NullVoxPopuli/limber#545
The text was updated successfully, but these errors were encountered: