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-no-excess-property

v1.1.0

Published

ESLint rule for not using excess-property

Downloads

37

Readme

eslint-plugin-no-excess-property

npm version Test

TypeScript often causes problems such as information leakage due to excess properties. This eslint-plugin allows you to ban excess properties!

plugin-image-gif

Quick Start

Check out the effects of the plugin in the sample repository.

git clone [email protected]:tfs-tada/no-excess-property-sample.git
cd no-excess-property-sample/packages/react-vite-eslintrc
npm install
code .

Open the file src/App.tsx to see the effect !

Installation

npm install eslint-plugin-no-excess-property --save-dev

Usage

Add the following to your ESLint configuration file

eslintrc.json

{
  "plugins": ["no-excess-property"],
  "rules": {
    "no-excess-property/no-excess-property": [
      "error",
      {
        "skipWords": ["UncheckedTypeName"],
        "skipProperties": ["uncheckedPropertyName"],
        "checkJsx": true,
        "checkClass": false
      }
    ]
  },
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "sourceType": "module",
    "project": ["./tsconfig.json"]
  }
}

flat config

Please refer to the sample repository configuration.

Example

Check here for more information.

Object

type User = { name: string };
const taro = { name: "Taro" };
const user1: User = taro; // OK

const jiro = { name: "Jiro", age: 20 };
const user2: User = jiro; // Error

const dummyUsers: User[] = [...Array(10)].map((_, idx) => ({ name: `${idx}` })); // OK
const dummyUsers2: User[] = [...Array(10)].map((_, idx) => ({
  name: `${idx}`,
  age: idx,
})); // Error

JSX

type Props = { name: string };
const Component = (props: Props) => <div>{props.name}</div>;
const user = { name: "Taro", age: 20 };
const appOk = <Component name={user.name} />; // OK
const appError = <Component {...user} />; // Error

Function

type User = { name: string };
const taro = { name: "Taro" };
const jiro = { name: "Jiro", age: 20 };

const func = (user: User) => {};
func(taro); // OK
func(jiro); // Error

type Func = (user: User) => User;
const func2: Func = (user) => {
  const target = {
    name: user.name,
    age: 30,
  };
  return target; // Error
};

Setting

{
  "rules": {
    "no-excess-property/no-excess-property": [
      "error",
      {
        "skipWords": ["UserElement"],
        "skipProperties": ["skipProperty"],
        "checkJsx": true,
        "checkClass": false
      }
    ]
  }
}

skipWords

Types registered in skipWords are not inspected.

// "skipWords": ["UserElement"]
type UserElement = { name: string };
const taro = { name: "Taro", age: 20 };
const element: UserElement = taro; // OK

default is ["Element", "HTMLElement", "ReactNode", "ReactElement", "FC"].

skipProperties

Properties registered in skipProperties are not inspected.

// "skipProperties": ["skipProperty"]
type User = { name: string };
const taro = { name: "Taro", skipProperty: "000-000-000" };
const user: User = taro; // OK

default is [].

checkJsx

If false, the rule does not check JSX attributes. default is true.

checkClass

If false, the rule does not check class properties. default is false.

class BaseUser {
  name: string;
}
class ExtendedUser extends BaseUser {
  age: number;
}
const user: BaseUser = new ExtendedUser(); // OK

License

This project is published under the MIT license. For more details, see LICENSE.