-
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
New rule 'no unsupported Node APIs in SSR-able components' #167
New rule 'no unsupported Node APIs in SSR-able components' #167
Conversation
docs/rules/no-unguarded-risky-node-api-in-ssrable-components.md
Outdated
Show resolved
Hide resolved
docs/rules/no-unguarded-risky-node-api-in-ssrable-components.md
Outdated
Show resolved
Hide resolved
if (import.meta.env.SSR) { | ||
// Risky Node API call within SSR context | ||
fs.writeFileSync('file.txt', 'data'); | ||
} |
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.
if (import.meta.env.SSR) { | |
// Risky Node API call within SSR context | |
fs.writeFileSync('file.txt', 'data'); | |
} | |
// Unsupported Node API call | |
fs.writeFileSync('file.txt', 'data'); |
```js | ||
if (import.meta.env.SSR) { | ||
try { | ||
// Safe guarded call | ||
require('something'); | ||
} catch (e) { | ||
// Handle error | ||
} | ||
} | ||
``` |
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.
```js | |
if (import.meta.env.SSR) { | |
try { | |
// Safe guarded call | |
require('something'); | |
} catch (e) { | |
// Handle error | |
} | |
} | |
``` | |
```js | |
// Do not use Node APIs |
Co-authored-by: Laura <49494194+lpomerleau@users.noreply.github.com>
README.md
Outdated
| [lwc/no-template-children](./docs/rules/no-template-children.md) | prevent accessing the immediate children of this.template | | | ||
| [lwc/no-leaky-event-listeners](./docs/rules/no-leaky-event-listeners.md) | prevent event listeners from leaking memory | | | ||
| [lwc/prefer-custom-event](./docs/rules/prefer-custom-event.md) | suggest usage of `CustomEvent` over `Event` constructor | | | ||
| [lwc/no-unsupported-node-api-in-ssrable-components](./docs/rules/no-unsupported-node-api-in-ssrable-components.md) | disallow unsupported Node API calls in SSR-able components | | |
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.
| [lwc/no-unsupported-node-api-in-ssrable-components](./docs/rules/no-unsupported-node-api-in-ssrable-components.md) | disallow unsupported Node API calls in SSR-able components | | | |
| [lwc/ssr/no-unsupported-node-api](./docs/rules/no-unsupported-node-api-in-ssrable-components.md) | disallow unsupported Node API calls in SSR-able components | | |
Feedback from @wjhsf
In the eslint plugin, there’s currently no consistency in the SSR rule names:
lwc/no-restricted-browser-globals-during-ssr
lwc/no-unsupported-ssr-properties
lwc/no-node-env-in-ssr
lwc/no-unsuppoted-node-api-in-ssrable-components
lwc/no-unguarded-async-event-in-ssr
lwc/no-form-factor-in-ssrable-components
lwc/no-static-imports-of-user-specific-scoped-modules-in-ssrable-components
To have a more consistent naming convention (and terser names), please change all of them to the format lwc/ssr/*
.
For rule and doc files names, Either "ssr/" or "ssr-" is probably fine. It depends on what eslint complains about, since it likes things to match the rule names.
For the few older ones that have already been published, we could either do a rename and release a major, or we could keep the old ones as aliases, but mark them as deprecated.
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.
Sure. I'll rename them.
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 renamed all references to the rule by prepending 'ssr-'.
@@ -0,0 +1,28 @@ | |||
# Disallow Node API Calls in SSR Context (`lwc/no-unsupported-node-api-in-ssrable-components`) |
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.
# Disallow Node API Calls in SSR Context (`lwc/no-unsupported-node-api-in-ssrable-components`) | |
# Disallow Node API Calls in SSR Context (`lwc/ssr/no-unsupported-node-api`) |
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.
@lpomerleau , we can't modify the path to a rule without altering the framework, but we can rename a rule by adding the prefix 'ssr-'.
No description provided.