Integrated ESLint rule for safe Environment Variable usage #46538
jasongerbes
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
@jasongerbes could you share the local custom lint rule you created, if you still have it? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the feature you'd like to request
Add a lint rule to ensure safe usage of
process.env
, as per Next's requirements.Valid:
process.env.PUBLISHABLE_KEY
process.env['PUBLISHABLE_KEY']
Invalid:
const { PUBLISHABLE_KEY } = process.env
process.env[varName]
From the Next.js docs:
And:
Describe the solution you'd like
A new custom Next ESLint rule to
@next/eslint-plugin-next
that ensures safe usage of environment variables.Describe alternatives you've considered
There don't appear to be any existing lint rules that prevent destructuring assignment and dynamic property access of
process.env
.I've created a local custom lint rule that works with the valid/invalid scenarios above. Happy to create a PR to add this to
@next/eslint-plugin-next
if you think this may be useful.Beta Was this translation helpful? Give feedback.
All reactions