From 427f3a848d3bdc2e9c4b6b7cb2b8699511339ee2 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 10 Apr 2024 19:36:37 +0100 Subject: [Statsig] Typecheck gates (#3467) * Typecheck gates * Lint against untyped useGate() * Alphabetic --- eslint/index.js | 1 + eslint/use-typed-gates.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 eslint/use-typed-gates.js (limited to 'eslint') diff --git a/eslint/index.js b/eslint/index.js index daf5bd81d..bb31a942d 100644 --- a/eslint/index.js +++ b/eslint/index.js @@ -3,5 +3,6 @@ module.exports = { rules: { 'avoid-unwrapped-text': require('./avoid-unwrapped-text'), + 'use-typed-gates': require('./use-typed-gates'), }, } diff --git a/eslint/use-typed-gates.js b/eslint/use-typed-gates.js new file mode 100644 index 000000000..3625a7da3 --- /dev/null +++ b/eslint/use-typed-gates.js @@ -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.", + }) + }, + } +} -- cgit 1.4.1