[Statsig] Typecheck gates (#3467)

* Typecheck gates

* Lint against untyped useGate()

* Alphabetic
This commit is contained in:
dan 2024-04-10 19:36:37 +01:00 committed by GitHub
parent bf974b147e
commit 427f3a848d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 45 additions and 6 deletions

View file

@ -3,5 +3,6 @@
module.exports = {
rules: {
'avoid-unwrapped-text': require('./avoid-unwrapped-text'),
'use-typed-gates': require('./use-typed-gates'),
},
}

31
eslint/use-typed-gates.js Normal file
View file

@ -0,0 +1,31 @@
'use strict'
exports.create = function create(context) {
return {
ImportSpecifier(node) {
if (
!node.local ||
node.local.type !== 'Identifier' ||
node.local.name !== 'useGate'
) {
return
}
if (
node.parent.type !== 'ImportDeclaration' ||
!node.parent.source ||
node.parent.source.type !== 'Literal'
) {
return
}
const source = node.parent.source.value
if (source.startsWith('.') || source.startsWith('#')) {
return
}
context.report({
node,
message:
"Use useGate() from '#/lib/statsig/statsig' instead of the one on npm.",
})
},
}
}