mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import { defineRule } from "@oxlint/plugins";
|
|
import type { ESTree } from "@oxlint/plugins";
|
|
|
|
const FORBIDDEN_SYMBOL_NAME = "shape";
|
|
|
|
function containsForbiddenSymbolName(name: string): boolean {
|
|
return name.toLowerCase().includes(FORBIDDEN_SYMBOL_NAME);
|
|
}
|
|
|
|
/** Return whether an identifier names a statically accessed member owned by another value. */
|
|
function isBorrowedMemberName(node: ESTree.Node): boolean {
|
|
const parent = node.parent;
|
|
if (parent === null || parent.type !== "MemberExpression") return false;
|
|
return parent.property === node && parent.computed === false;
|
|
}
|
|
|
|
/** Ban the case-insensitive substring "shape" in every JavaScript and TypeScript symbol name. */
|
|
export const noForbiddenTermInSymbolNamesRule = defineRule({
|
|
meta: {
|
|
type: "problem",
|
|
docs: {
|
|
description:
|
|
'Disallow the case-insensitive substring "shape" in JavaScript, TypeScript, private, and JSX symbol names.',
|
|
},
|
|
messages: {
|
|
forbiddenSymbolName:
|
|
'Rename symbol "{{name}}" for its domain role; "shape" describes structure rather than ownership.',
|
|
},
|
|
},
|
|
createOnce(context) {
|
|
const reportForbiddenSymbolName = (node: ESTree.Node & { name: string }) => {
|
|
if (!containsForbiddenSymbolName(node.name) || isBorrowedMemberName(node)) return;
|
|
context.report({
|
|
node,
|
|
messageId: "forbiddenSymbolName",
|
|
data: { name: node.name },
|
|
});
|
|
};
|
|
|
|
return {
|
|
Identifier: reportForbiddenSymbolName,
|
|
PrivateIdentifier: reportForbiddenSymbolName,
|
|
JSXIdentifier: reportForbiddenSymbolName,
|
|
};
|
|
},
|
|
});
|