Coder Social home page Coder Social logo

foad / eslint-plugin-listeners Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 4.0 164 KB

ESLint plugin for preventing memory leaks around event listeners

Home Page: https://www.npmjs.com/package/eslint-plugin-listeners

License: MIT License

JavaScript 51.95% TypeScript 48.05%
hacktoberfest

eslint-plugin-listeners's Introduction

eslint-plugin-listeners

Test

This project aims to provide formatting rules to prevent memory leaks around event listeners

Installation

You'll first need to install ESLint:

$ yarn add eslint --dev

Next, install eslint-plugin-listeners:

$ yarn add eslint-plugin-listeners --dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-listeners globally.

Usage

Add listeners to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": ["listeners"]
}

Then configure the rules you want to use under the rules section.

{
  "rules": {
    "listeners/no-missing-remove-event-listener": "error",
    "listeners/matching-remove-event-listener": "error",
    "listeners/no-inline-function-event-listener": "error"
  }
}

or

You can use our "recommended" settings which enables most of the rules for you

{
  "extends": ["plugin:listeners/recommended"]
}

We also support a "strict" settings which enables all of the rules for you

{
  "extends": ["plugin:listeners/strict"]
}

Rule Documentation

Credits

This package is based off of https://github.com/tipsi/eslint-plugin-tipsi

eslint-plugin-listeners's People

Contributors

alvarocjunq avatar dependabot[bot] avatar fdiskas avatar foad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

eslint-plugin-listeners's Issues

Mismatched useCapture flag not reported

I just installed your plugin due to finding a devious bug where I had an addEventListener call with the useCapture argument set to true, and a removeEventListener call without the flag. This doesn't actually remove it, see MDN.

In other words, the following code is not flagged as a problem right now, and it probably should be:

private startListening() {
  const useCapture = true;
  document.addEventListener("mousemove", this.onMouseMove, useCapture);
}

private stopListening() {
  document.removeEventListener("mousemove", this.onMouseMove);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.