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

@my-ul/eslint-plugin

v18.0.0-beta.3

Published

A set of custom eslint rules that make working with myUL projects easier.

Downloads

297

Readme

@my-ul/eslint-plugins

A set of custom eslint rules that make working with myUL projects easier.

Installation

If you are using Angular, make sure angular-eslint is installed first.

npm install --save-dev @my-ul/eslint-plugin

Rules

no-constructor-literal-initializers

has fixer

This rule disallows initializing class properties in the constructor.

Disallowed

These are examples of incorrect code.

class MyClass {
    myProperty: number;
    constructor() {
        this.myProperty = 0;
    }
}

Allowed

These are examples of correct code.

class MyClass {
    myProperty = 0;
}

Configuration

import myul from '@my-ul/eslint-plugin';
import tsParser from '@typescript-eslint/parser';

export default [
    {
        files: ['*.ts'],
        // this rules requires @typescript-eslint/parser for type checking
        languageOptions: {
            parser: tsParser,
            parserOptions: {
                project: './tsconfig.json'
            }
        },
        plugins: {
            myul
        }
        rules: {
            'myul/no-constructor-literal-initializers': ['error']
        }
    }
]

no-mismatched-fallback-labels

has fixer

This rule will ensure that uses of useTranslation hooks are using the correct fallback label.

Configuration


import myul from '@my-ul/eslint-plugin';

/***
 * The path to the default dictionary file.
 **/
const defaultDictionaryPath = 'assets/i18n/en-US.json';

/***
 * The action to take when a mismatch is found.
 * 'fix' will automatically update the fallback label.
 * 'report' will only report the issue.
 **/
const action = 'fix';
export default [
    {
        files: ['**/*.ts'],
        plugins: {
            myul
        }
        rules: {
            'myul/no-mismatched-fallback-labels': ['error', {
                defaultDictionaryPath,
                action
            }]
        }
    }
]

Disallowed

These are examples of incorrect code.

// assets/i18n/en-US.json
{
    "foo": "bar"
}
import { useTranslation } from '@my-ul/tod-angular-client';

@Component({
    selector: 'app-my-component',
    template: `
        @let i18n = translate();
        <div>{{ i18n.foo }}</div>
    `,
})
export class MyComponent {
    translate = useTranslationSignal({
        foo: 'baz', // eslint error: 'foo' does not match the fallback label 'bar'
    });
}

no-useless-rxjs-operators

has fixer

This rule detects and removes useless RxJS operators, such as an empty .pipe() or map(x => x) and throwError(e => { throw e }).

Disallowed

These are examples of incorrect code.

import { of, map, catchError } from 'rxjs';

export const myFunction = (number) =>
    of(number).pipe(
        map((x) => x),
        catchError((e) => {
            throw e;
        }),
    );

Allowed

These are examples of correct code.

import { of } from 'rxjs';

export const myFunction = (number) => of(number);

prefer-inject-function

has fixer

This rule will migrate from constructor injection to the inject(token) function.

Disallowed

These are examples of incorrect code.

import { Injectable, PLATFORM_ID } from '@angular/core';

@Injectable()
export class MyService {
    constructor(
        private dependency: Dependency,
        @Inject(PLATFORM_ID) private platformId,
    ) {}
}

Allowed

These are examples of correct code. (Note: the empty constructor should be removed by a different rule).

import { Injectable, inject } from '@angular/core';

@Injectable()
export class MyService {
    constructor() {}
    private dependency = inject(Dependency);
    private platformId = inject(PLATFORM_ID);
}

Configuration

  • autoFix (default: true): Automatically fix the code. When false, the rule will only report issues and suggest fixes.
import myul from '@my-ul/eslint-plugin';

/**
 * Fix the code automatically.  False is useful for CI/CD pipeline checks.
 */
const autoFix = true;

export default [
    {
        files: ['**/*.ts'],
        plugins: {
            myul
        }
        rules: {
            'myul/prefer-inject-function': ['error', { autoFix: true }]
        }
    }
]

prefer-signal-primitives

has fixer

This rule will automatically wrap primitive values in a signal. Most accesses will also be updated.

Disallowed

These are examples of incorrect code.

import { Component } from '@angular/core';

@Component({
    selector: 'app-my-component',
    template: ` <div>{{ isOpen ? 'Close' : 'Open' }}</div> `,
})
export class MyComponent {
    isOpen = false;

    toggle() {
        this.isOpen = !this.isOpen;
    }
}

Allowed

These are examples of correct code.

import { Component } from '@angular/core';

@Component({
    selector: 'app-my-component',
    template: ` <div>{{ isOpen() ? 'Close' : 'Open' }}</div> `,
})
export class MyComponent {
    isOpen = signal(false);

    toggle() {
        this.isOpen.set(!this.isOpen());
    }
}

remove-restricted-syntax

has fixer

This rule will remove restricted syntax from the codebase. This can be used to perform production builds.

Configuration

Provide an array of objects of { remove: 'selector' } or { report: 'selector' }. The remove option will remove the syntax from the codebase, while the report option will only report the syntax (suitable for CI/CI pre checks).

Example (HTML rule)

Automatically remove all data-testid attributes from the HTML at build time.

import myul from '@my-ul/eslint-plugin';
import templateParser from '@angular-eslint/template-parser';

export default [
    {
        files: ['*.html'],
        plugins: {
            myul,
        },
        parser: templateParser,
        rules: {
            // Remove all data-testid attributes
            'myul/remove-restricted-syntax': [
                'error',
                { report: 'Element$1 > TextAttribute[name=data-testid]' },
            ],
        },
    },
];

Example (TypeScript rule)

Automatically remove all console.* and debugger statements from the TypeScript codebase at build time.

import myul from '@my-ul/eslint-plugin';

export default [
    {
        files: ['*.ts'],
        plugins: {
            myul,
        },
        // requires @typescript-eslint/parser
        // parser: '@typescript-eslint/parser',
        rules: {
            'myul/remove-restricted-syntax': [
                'error',
                { remove: 'CallExpression[callee.name=console]' },
                { remove: 'DebuggerStatement' },
            ],
        },
    },
];