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-aaa-comments

v1.0.5

Published

ESLint plugin for enforcing AAA comments.

Downloads

677

Readme

eslint-plugin-aaa-comments

This plugin provide rule for enforcing AAA (Arrange Act Assert) comments or enforces you to organize your it cases into 3 sections without enforcing comments in unit tests.

For the motivation refer to Making Better Unit Tests: part 1, the AAA pattern.

Installation

# inside your project's working tree
npm install eslint-plugin-aaa-comments --save-dev

Config - Legacy (.eslintrc)

All rules are off by default. Configuring manually:

{
  "rules": {
    "aaa-comments/enforce-aaa-comments": "error"
    // etc...
  },
},

Config - Flat (eslint.config.js)

All rules are off by default. However, you may configure them manually in your eslint.config.(js|cjs|mjs).

import js from '@eslint/js';

export default [
  js.configs.recommended,
  {
    files: ['**/*.{js,mjs,cjs}'],
    languageOptions: {
      ecmaVersion: 'latest',
      sourceType: 'module',
    },
    rules: {
      'aaa-comments/enforce-aaa-comments': 'error',
    },
  },
];

Rules

The package consists of only one single rule

aaa-comments/enforce-aaa-comments

Enforces you to write AAA (Arrange Act Assert) comments in unit tests. How the rule works:

  1. Find every it function
  2. Find the second argument of the function which is usually a function
  3. Within that function calculates how many line breaks does it have

Based on the number of line breaks it callback have:

  • If 0 and single statement – passes
  • If 0 and more than one statements – fails
  • If 1 or 2 line breaks – passes
  • If 3 line breaks – requires you to have AAA comments

Examples

Here's passing examples:

it('works', async () => {
  const result = await client.invalidate({ userId: Random.int(1000000) });

  assert.strictEqual(result.isSuccess, true);
});

it('works', async () => {
  const foo = 'bar';

  const result = await client.invalidate({ userId: Random.int(1000000) });

  assert.strictEqual(result.isSuccess, true);
});

it('works', async () => {
  // Arrange
  const foo = 'bar';

  // Act
  const result = await client.invalidate({ userId: Random.int(1000000) });

  const result2 = await client.invalidate({ userId: Random.int(1000001) });

  // Assert
  assert.strictEqual(result.isSuccess, true);
});

Here's examples which are not passing:

it('works', async () => {
  const result = await client.invalidate({ userId: Random.int(1000000) });
  assert.strictEqual(result.isSuccess, true);
});

it('works', async () => {
  const foo = 'bar';

  const result = await client.invalidate({ userId: Random.int(1000000) });

  const result2 = await client.invalidate({ userId: Random.int(1000001) });

  assert.strictEqual(result.isSuccess, true);
});