-
Notifications
You must be signed in to change notification settings - Fork 839
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
Chore/8201 deprecate json tokens #8246
base: main
Are you sure you want to change the base?
Chore/8201 deprecate json tokens #8246
Conversation
04461a6
to
5cd5dd5
Compare
5cd5dd5
to
6a751f9
Compare
6a751f9
to
b8d7a96
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thank you @weronikaolejniczak (also for the patience!)
I got this working locally without issues 👌
I added some comments, and I included [non-blocking]
in some of them, but thinking about it, all comments are non-blocking because they're mostly questions and ideas that could turn into improvements…
Let me know what you think and we can get this finally merged 🙂
return { | ||
ImportDeclaration(node) { | ||
allPatterns.forEach(({ pattern, message }) => { | ||
const regex = new RegExp(pattern.replace('*', '.*')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to ask this because I'm not well-versed with globs — will this pattern.replace('*', '.*')
play nicely with any custom user patterns? (I think yes but I'm not sure)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation will not work with any custom user pattern.
- It will only work with wildcards (
*
) but not globstars (**
) - this will result in an invalid regular expression after the replacement. - What's more, it could lead to incorrect matches if special characters are unescaped, e.g. in
'@elastic/eui/dist/eui_theme_*.json'
I didn't escape the dot, so it will be treated as a regular operator - it will match any single character - and will match'@elastic/eui/dist/eui_theme_borealis_darkkjson'
.
It's not a fully glob implementation but a simplification for the use case we're working with.
For a comprehensive implementation we could leverage a globbing library like the one you mentioned (multimatch; or we could go for more performant, safer micromatch that covers the functionality of both minimatch and multimatch).
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the rule could actually be used outside of our specific use case, I think it's worth it adding a library. I like the micromatch
one you found (I didn't know it)!
Preview staging links for this PR:
|
💚 Build Succeeded
History
cc @acstll |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improving the globbing part should make it ready to go, thanks for taking a look into that!
return { | ||
ImportDeclaration(node) { | ||
allPatterns.forEach(({ pattern, message }) => { | ||
const regex = new RegExp(pattern.replace('*', '.*')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the rule could actually be used outside of our specific use case, I think it's worth it adding a library. I like the micromatch
one you found (I didn't know it)!
Summary
I added a new rule to our ESLint plugin,
no-restricted-eui-imports
, that won't conflict with the inbuiltno-restricted-imports
rule and will allow us to define several error levels at once. I.e. we want some imports to be marked as warning and not an error, as it's done in Kibana.Context:
The JSON token imports in
@kbn/eslint/module_migration
need to be removed as well:https://github.com/elastic/kibana/blob/212b1926743ca5821992c2877d9c68f621e1875e/packages/kbn-eslint-config/.eslintrc.js#L131-L140
QA
yarn workspace @elastic/eslint-plugin-eui pack
"@elastic/eslint-plugin-eui": "file:path/to/the/package.tgz"
yarn
and bootstrap:yarn kbn bootstrap --no-validate
Unit tests:
yarn workspace @elastic/eslint-plugin-eui test