-
Notifications
You must be signed in to change notification settings - Fork 33
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
feat: add no-disallowed-lwc-imports rule #85
Conversation
|
||
```js | ||
export * from 'lwc'; | ||
``` |
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.
Incidentally, our current Babel validator allows export * from 'lwc'
and export * as foo from 'lwc'
. This rule fixes that.
|
||
// From "@lwc/engine-server" | ||
'renderComponent', | ||
]); |
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 based on our current list.
import { LightningElement, wire, api } from 'lwc'; | ||
``` | ||
|
||
If you disable this rule, then you may import unstable or otherwise undesirable APIs from `lwc`. |
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.
Shall we make this rule configurable to allow importing unstable API? Maybe it's something we can include in the future if needed.
{
rules: {
'no-disallowed-lwc-imports': ["error", { allowUnstable: true }]
}
}
or:
{
rules: {
'no-disallowed-lwc-imports': ["error", { allow: ['swapComponent'] }]
}
}
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 seems unnecessary to me. People who want to use unstable imports can disable the rule entirely.
The value-add of the other things that the rule checks is low IMO. Everything else that it checks for (e.g. import nonexistentDefault from 'lwc'
) will also throw an error either by Rollup or at runtime.
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.
Sounds good to me.
Co-authored-by: Pierre-Marie Dartus <[email protected]>
Co-authored-by: Pierre-Marie Dartus <[email protected]>
import { LightningElement, wire, api } from 'lwc'; | ||
``` | ||
|
||
If you disable this rule, then you may import unstable or otherwise undesirable APIs from `lwc`. |
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.
Sounds good to me.
Delaying until CLCO |
Co-authored-by: Pierre-Marie Dartus <[email protected]>
Co-authored-by: Pierre-Marie Dartus <[email protected]>
{ | ||
code: `export {} from "some-other-package"`, | ||
}, | ||
]; |
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.
Add a testcase for export { LightningElement as default } from "lwc";
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.
Done!
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.
LGTM, one suggestion for an additional test case
@jodarove Are we good to merge this PR and salesforce/lwc#1284 to master? |
yes @nolanlawson |
Fixes: salesforce/lwc#1284 and W-10151021
Adds a rule to disallow restricted APIs from the
lwc
package.