npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-server-component-rules

v0.0.4

Published

eslint for nextjs server component rule

Downloads

40

Readme

eslint-plugin-server-component-rules

Nextjs13의 server component, client component에 존재하는 룰을 eslint로 강제하기 위해서 만든 패키지입니다.

어떤 문제를 해결했는지?

기존 server component에서는 다양한 룰이 존재합니다.

  • 내부에서 useState, useEffect나 custom hook을 사용할 수 없는것.
  • browser api(window, document)등을 이용할 수 없는것
  • jsx 내부에서 event handler를 이용할 수 없는것
  • client component에서 server component를 이용할 수 없는것

이 룰들을 어기면 client component에서 server component를 이용할 수 없는것을 제외하고 빌드타임에 에러가 발생하게 되는데요.

이것을 개발하게 된 계기가 개발할떄 에디터 단위에서 바로 에러를 경고할 수 있도록 추가하여 server component 개발의 생산성을 올리기 위함이였습니다.

또한 client component에서 server component를 이용할 수 없는것 부분을 lint 단위에서 처리하기 위해 서버 컴포넌트에는 index.server.tsx 같은 file name convention을 강제하도록 설정하였습니다.

사용하는법

npm install -D eslint-plugin-server-component

eslintrc.js

module.exports = {
  extends: ["next/core-web-vitals"],
  plugins: ["server-component-rules"],
  rules: {
    "server-component/no-import-use-client": ["error", { middle: "server" }],
    "server-component/file-name": ["error", { middle: "server" }],
    "server-component/no-use-react-hook": ["error"],
    "server-component/no-use-browser-api": ["error"],
    "server-component/no-use-event-handler": ["error"],
  },
};

plugins에 server-component 추가후 rules추가

server-component/file-name

파일네임 컨벤션을 지정하기 위한 rule입니다. middle이라는 변수에 server를 하면 서버 컴포넌트에서는 *.server.tsx|jsx 처럼 컨벤션이 지정됩니다.

server-component/no-import-use-client

client component에서 server component를 import할떄 빌드타임에서 유일하게 에러를 잡지못하는 부분입니다. 이부분은 위의 file-name과 같이 이용하며 middle 변수를 동일하게 설정하면 됩니다.

server-component/no-use-react-hook

server component에서 react hook (useState, useEffect...)등을 이용하지 못하도록 막는 룰입니다.

server-component/no-use-browser-api

server component에서 document, window등을 참조하지 못하도록 막는 룰입니다.

server-component/no-use-event-handler

server component에서 jsx에 event handler를 추가하지 못하도록 막는 룰입니다.