improve(eslint) modularize eslint configs #899
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of change
Dependencies added
Details
I was sporadically getting an error about eslint not being able to resolve the new config set up in fix(@roots/bud-eslint) use @babel/eslint-parser #892. require.resolve seems to fix it.
I am further modularizing the eslint configs in this PR. Now, each bud extension exports the configuration items it is responsible for. These smaller configs are composable and allow for a great deal more flexibility for people using bud and makes it a lot easier for us to change something like the base babel config across several extensions, in the future.
The simplest possible use case is: @roots/bud with @roots/bud-eslint. That project eslintrc might look like:
Later, we install @roots/bud-babel on and we want to support that syntax. So, we can add the new export:
Ultimately it makes sense to install a preset instead of individual extensions, and the presets export their own configs to make that easy. Here is the
@roots/bud-preset-recommend
example's eslint config:bud/examples/eslint/.eslintrc.js
Lines 1 to 6 in b2033ac
In the end, the Sage preset is actually the baseline wordpress preset (babel, react, wp global) combined with prettier and a couple custom rules:
bud/packages/@roots/sage/eslint-config/index.js
Lines 6 to 24 in b2033ac
The project config remains unchanged:
And if we want to make a change to it we should ask "is this specific to Sage or should it apply to all X projects?"
Here's how the different configs compose/inherit rules:
@roots/bud-eslint/eslint-config
)@roots/bud-babel/eslint-config
)@roots/bud-prettier/eslint-config
)@roots/bud-react/eslint-config
)