mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +00:00
Bulk rename across 989 files: - Package names: posthog-js → @hanzo/insights, posthog-node → @hanzo/insights-node, etc. - Repository URLs: posthog/posthog-js → hanzoai/insights-js - Brand names: PostHog → Insights - File renames: 259 reference JSON files, source files, workflow files - Directory rename: eslint-plugin-posthog-js → eslint-plugin-insights Remaining: 8 refs to @posthog/rrweb-* (real npm deps, need fork+publish)
53 lines
2.1 KiB
JavaScript
53 lines
2.1 KiB
JavaScript
module.exports = {
|
|
create(context) {
|
|
return {
|
|
CallExpression: function (node) {
|
|
// Check if the callee object is a regex matching function pattern
|
|
const isFunctionPatternRegex =
|
|
node.callee.type === 'MemberExpression' &&
|
|
node.callee.object?.type === 'Literal' &&
|
|
node.callee.object?.regex &&
|
|
node.callee.object?.regex.pattern === '^\\s*\\bfunction\\b'
|
|
|
|
// Check if the callee property is 'test'
|
|
const isTestCall = node.callee.property?.type === 'Identifier' && node.callee.property?.name === 'test'
|
|
|
|
if (isFunctionPatternRegex && isTestCall) {
|
|
context.report({
|
|
node,
|
|
message: 'Do not use regex to check for functions. Use isFunction instead.',
|
|
})
|
|
}
|
|
},
|
|
BinaryExpression: function (node) {
|
|
// Check if the operator is 'instanceof' and the right operand is 'Function'
|
|
if (
|
|
node.operator === 'instanceof' &&
|
|
node.right.type === 'Identifier' &&
|
|
node.right.name === 'Function'
|
|
) {
|
|
context.report({
|
|
node,
|
|
message: "Do not use 'instanceof Function' to check for functions. Use isFunction instead.",
|
|
})
|
|
}
|
|
|
|
// Check for 'typeof x === "function"' pattern
|
|
if (
|
|
node.operator === '===' &&
|
|
node.left.type === 'UnaryExpression' &&
|
|
node.left.operator === 'typeof' &&
|
|
node.right.type === 'Literal' &&
|
|
node.right.value === 'function'
|
|
) {
|
|
context.report({
|
|
node,
|
|
message:
|
|
'Do not use \'typeof x === "function"\' to check for functions. Use isFunction instead.',
|
|
})
|
|
}
|
|
},
|
|
}
|
|
},
|
|
}
|