34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
// packages/core-eslint/rules/no-direct-socket-io.js
|
|
const ALLOWED = [
|
|
/\/packages\/core-realtime\/src\//,
|
|
/\/apps\/[^/]+\/server\.ts$/,
|
|
];
|
|
|
|
export default {
|
|
meta: {
|
|
type: "problem",
|
|
docs: { description: "Block direct socket.io imports outside core-realtime + app servers" },
|
|
messages: {
|
|
noDirectSocketIO: 'Import from "@repo/core-realtime" instead of "socket.io". Direct imports allowed only in packages/core-realtime/src/ and apps/*/server.ts.',
|
|
noDirectSocketIOClient: 'Use the realtime helpers from "@repo/core-realtime" / "@repo/core-testing/instrumentation" instead of "socket.io-client".',
|
|
},
|
|
schema: [],
|
|
},
|
|
create(context) {
|
|
const filename = context.filename ?? context.getFilename();
|
|
const allowed = ALLOWED.some((re) => re.test(filename));
|
|
if (allowed) return {};
|
|
|
|
return {
|
|
ImportDeclaration(node) {
|
|
const source = node.source.value;
|
|
if (source === "socket.io") {
|
|
context.report({ node, messageId: "noDirectSocketIO" });
|
|
} else if (source === "socket.io-client") {
|
|
context.report({ node, messageId: "noDirectSocketIOClient" });
|
|
}
|
|
},
|
|
};
|
|
},
|
|
};
|