Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-react-server-components

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-react-server-components - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

8

dist/index.js

@@ -171,3 +171,2 @@ // src/rules/use-client.ts

import componentUtil from "eslint-plugin-react/lib/util/componentUtil";
var HOOK_REGEX = /^use[A-Z]/;
var useClientRegex = /^('|")use client('|")/;

@@ -277,3 +276,3 @@ var browserOnlyGlobals = Object.keys(globals.browser).reduce(

}
if (HOOK_REGEX.test(name) && // Is in a function...
if (isClientOnlyHook(name) && // Is in a function...
context.getScope().type === "function" && // But only if that function is a component

@@ -300,3 +299,3 @@ Boolean(util.getParentComponent(expression))) {

}
if (expression.callee && HOOK_REGEX.test(expression.callee.name) && Boolean(util.getParentComponent(expression))) {
if (expression.callee && isClientOnlyHook(expression.callee.name) && Boolean(util.getParentComponent(expression))) {
instances.push(expression.callee.name);

@@ -371,2 +370,5 @@ reportMissingDirective("addUseClientHooks", expression.callee, {

}
function isClientOnlyHook(name) {
return /^use[A-Z]/.test(name) && name !== "useId";
}
var ClientComponents = { meta, create };

@@ -373,0 +375,0 @@

{
"name": "eslint-plugin-react-server-components",
"version": "1.1.1",
"version": "1.1.2",
"description": "Rules for React server components",

@@ -5,0 +5,0 @@ "type": "module",

@@ -159,2 +159,9 @@ "use strict";

},
{
code: `import {useId} from 'react';
const Button = () => {
const id = useId();
return <div id={id} />;
}`,
},
],

@@ -213,2 +220,17 @@ invalid: [

},
{
code: `const Button = () => {
const id = useIdentifier();
return <div id={id} />;
}`,
errors: [
{ messageId: "addUseClientHooks", data: { hook: "useIdentifier" } },
],
output: `'use client';
const Button = () => {
const id = useIdentifier();
return <div id={id} />;
}`,
},
],

@@ -215,0 +237,0 @@ });

@@ -19,3 +19,2 @@ import type { Rule } from "eslint";

const HOOK_REGEX = /^use[A-Z]/;
const useClientRegex = /^('|")use client('|")/;

@@ -165,3 +164,3 @@ const browserOnlyGlobals = Object.keys(globals.browser)

if (
HOOK_REGEX.test(name) &&
isClientOnlyHook(name) &&
// Is in a function...

@@ -211,3 +210,3 @@ context.getScope().type === "function" &&

expression.callee &&
HOOK_REGEX.test(expression.callee.name) &&
isClientOnlyHook(expression.callee.name) &&
Boolean(util.getParentComponent(expression))

@@ -300,2 +299,7 @@ ) {

function isClientOnlyHook(name: string) {
// `useId` is the only hook that's allowed in server components
return /^use[A-Z]/.test(name) && name !== 'useId'
}
export const ClientComponents = { meta, create };

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc