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-console-time-pairs

v0.0.2

Published

Ensure console.timeEnd is called for each console.time

Downloads

2

Readme

eslint-plugin-console-time-pairs

Ensure console.timeEnd is called for each console.time.

Why?

Finding out at runtime that you've typoed a label, or forgot to call time or timeEnd is not fun. This plugin makes sure every call to time has a matching call to timeEnd (and vice versa) so you can catch those mistakes at lint-time instead of run-time.

function() {
  console.time("Some long operation");
  // ...
  console.timeEnd("Some looong operation"); // Generates a warning!
}

Installation

# npm
npm install eslint-plugin-console-time-pairs --save-dev
# yarn
yarn add eslint-plugin-console-time-pairs --dev

In your .estlintrc.js add "console-time-pairs" to the plugin list.

plugins: [
  "console-time-pairs",
],

Then in the rules section set "console-time-pairs/console-time-pairs" pass the log level (either "error" or "warning").

rules: {
  "console-time-pairs/console-time-pairs": "error",
},

Configuration (Optional)

Object names

By default only console.time and console.timeEnd will be scanned. To also scan calls like logger.time specify "logger" in the objectNames array.

rules: {
  "console-time-pairs/console-time-pairs": ["error", {
    "objectNames": ["console", "logger", "myCustomTimerUtil"],
  }],
},

Scope

By default the entire file will be checked for matching time/timeEnd calls. But this behavior can be customized with the scope option:

  • SameFunction: the calls must be made from inside the same function definition
  • SameRootFunction: the calls must be defined in some shared encapsulating function definition
  • File (default): the calls can be made anywhere in the same file
rules: {
  "console-time-pairs/console-time-pairs": ["error", {
    "scope": "SameFunction" | "SameRootFunction" | "File",
  }],
},

Example

console.time("A"); // Will always produce a warning

function() {
  console.time("B"); //    Will produce a warning with "SameFunction", "SameRootFunction"
}
function() {
  console.timeEnd("B"); // Will produce a warning with "SameFunction", "SameRootFunction"
}
function() {
  setTimeout(() => console.time("C"), 100); //    Will only produce a warning with "SameFunction"
  setTimeout(() => console.timeEnd("C"), 200); // Will only produce a warning with "SameFunction"
}
function() {
  console.time("D"); //    Will never produce a warning
  console.timeEnd("D"); // Will never produce a warning
}

Limitations

If the label argument is not a string literal the plugin will attempt to match using the text of the source code. This handles many cases, such as: using a shared label variable, using identical string-template expressions, concatenating strings in the same way, etc.

However, it can still generate false positives if the expressions are not identical. In those cases using lint-skips, or extracting out a variable for the timer label should resolve the issue.