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

@alexwende/eslint-config

v1.0.3

Published

ESLint config for JavaScript and TypeScript projects using the new FlatConfig format.

Downloads

51

Readme

@alexwende/eslint-config

ESLint config for JavaScript and TypeScript projects using the new FlatConfig format.

npm (scoped) Conventional Commits Commitizen friendly

Features

Installation

npm i -D eslint @alexwende/eslint-config

Usage

Create a eslint.config.js file in the root of your project:

// eslint.config.js
import { create } from '@alexwende/eslint-config';

export default create({
    typescript: true,
    style: true,
    ignores: [
        'dist/',
    ],
});

Run eslint from the command line:

npx eslint .
npx eslint . --fix

or add a script to your package.json:

// package.json
{
    "scripts": {
        "lint": "eslint ./src",
        "lint:fix": "eslint ./src --fix"
    }
}

Configuration

The create factory method accepts an optional configuration object with the following properties:

export interface ConfigOptions {
    /**
     * Ignore files matching the given glob patterns.
     */
    ignores?: Linter.Config['ignores'];
    /**
     * The type of JavaScript source code (defaults to `'module'`).
     */
    sourceType?: Linter.ParserOptions['sourceType'];
    /**
     * The version of ECMAScript to support (defaults to `'latest'`).
     */
    ecmaVersion?: Linter.ParserOptions['ecmaVersion'];
    /**
     * Enable jsx support.
     */
    jsx?: boolean;
    /**
     * Enable TypeScript support.
     *
     * @remarks
     * If set to `true`, TypeScript will be enabled for all `.ts` files in the project. If set to `false`,
     * TypeScript support will be disabled. You can also pass an object to configure TypeScript support.
     * See {@link configTypeScript} for details.
     */
    typescript?: boolean | {
        /**
         * The files to enable typescript linting for (defaults to `['**\/*.ts', '**\/*.tsx']`).
         */
        files?: Linter.Config['files'];
    };
    /**
     * Enable environment-specific globals for matching files.
     */
    environments?: {
        /**
         * The environment to enable (i.e. 'browser', 'node' or 'worker').
         */
        env: Environment;
        /**
         * The files to enable the environment for. If not set, the environment will be enabled for all files.
         */
        files?: Linter.Config['files'];
    }[];
    /**
     * Enable style rules.
     *
     * @remarks
     * Use this option if you want to use eslint to enforce code style and formatting.
     * Not recommended if you are using an external formatter, like prettier.
     */
    style?: boolean;
}

Examples

Customize Rules

Using the new FlatConfig format, you can easily customize rules by adding additional config objects to the array.

// eslint.config.js
import { create } from '@alexwende/eslint-config';

export default [
    ...create(),
    {
        // with `files`, the rules will only be applied to matching files
        // files: ['some-package/**/*.ts'],
        rules: {
            '@typescript-eslint/no-useless-constructor': 'off',
        },
    },
];

JavaScript for Node

The following configuration configures eslint to lint all JavaScript files in the working directory, adds Node.js specific globals and enables style rules.

// eslint.config.js
import { create } from '@alexwende/eslint-config';

export default create({
    environments: [{ env: 'node' }],
    style: true,
});

TypeScript for Browser

The following configuration configures eslint to lint all JavaScript and TypeScript files in the working directory, adds browser specific globals and enables style rules.

// eslint.config.js
import { create } from '@alexwende/eslint-config';

export default create({
    environments: [{ env: 'browser' }],
    typescript: true,
    style: true,
});

If you want to lint TypeScript files only, simply exclude all JavaScript files:

// eslint.config.js
import { create } from '@alexwende/eslint-config';

export default create({
    environments: [{ env: 'browser' }],
    typescript: true,
    style: true,
    ignores: [
        '**/*.js',
    ],
});

VSCode Integration

Ensure you have the VS Code ESLint extension installed.

Update your .vscode/settings.json with the following options:

// .vscode/settings.json
{
  // enable the new FlatConfig format
  "eslint.useFlatConfig": true,

  // if you want eslint to fix and format your code on save:

  // disable the default formatter...
  "editor.formatOnSave": false,

  // ...and enable eslint code actions on save
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "explicit",
    "source.organizeImports": "never"
  },
}