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

@focus21/eslint-config

v7.1.0

Published

Focus21's ESLint configs.

Downloads

34

Readme

@focus21/eslint-config

Focus21's ESLint configs.

[[TOC]]

Usage

Installation:

pnpm add --save-dev @focus21/eslint-config

In .eslintrc.js:

module.exports = {
  extends: "@focus21",
};

You do not need to use the eslint --ext option when extending @focus21. .js, .jsx, .ts, and .tsx files are included automatically.

Advanced Usage

Base Config Structure

Extending @focus21 is equivalent to the following config:

const { files, defaults } = require("@focus21/eslint-config/lib");

const { settings } = defaults;

module.exports = {
  overrides: [
    // Set the base rules
    {
      files: files.baseFiles,
      extends: [
        "@focus21/eslint-config/base",
        "@focus21/eslint-config/react",
        "@focus21/eslint-config/react-testing-library",
        "@focus21/eslint-config/jsdoc",
      ],
      settings,
    },
    // The overrides below target rules towards certain files
    {
      files: files.jestFiles,
      extends: "@focus21/eslint-config/jest",
      settings,
    },
    // The overrides below turn off settings for certain files
    {
      files: files.commonjsFiles,
      extends: "@focus21/eslint-config/commonjs",
      settings,
    },
    {
      files: files.testFiles,
      extends: "@focus21/eslint-config/test",
      settings,
    },
    {
      files: files.devFiles,
      extends: "@focus21/eslint-config/dev",
      settings,
    },
  ],
};

Use this default configuration as the basis for your own config. You must use overrides to override options.

Minimal configuration example:

const { files, defaults } = require("@focus21/eslint-config/lib");

const { settings } = defaults;

module.exports = {
  overrides: [
    {
      files: files.baseFiles,
      extends: "@focus21/eslint-config/base",
      settings,
    },
    {
      files: files.commonjsFiles,
      extends: "@focus21/eslint-config/commonjs",
      settings,
    },
    {
      files: files.testFiles,
      extends: "@focus21/eslint-config/test",
      settings,
    },
    {
      files: files.devFiles,
      extends: "@focus21/eslint-config/dev",
      settings,
    },
  ],
};

File Patterns

files are exported from @focus21/eslint-config/lib for your .eslintrc.js:

  • baseFiles: All files.
  • srcFiles: All files in the src/ directory.
  • commonjsFiles: Common patterns matching files which don't use ES6 import format.
  • jestFiles: Common patterns matching Jest files.
  • cypressFiles: Common patterns matching Cypress files.
  • mochaFiles: Common patterns matching Mocha files.
  • testFiles: All test patterns above.
  • storybookFiles: Common patterns matching Storybook files.
  • svelteFiles: Common patterns matching Svelte files.
  • devFiles: Common patterns matching all dev utilities, test files, and configs.

.js, .jsx, .ts, and .tsx files are included explicitly in file patterns where appropriate.

Example usage:

// .eslintrc.js

const files = require("@focus21/eslint-config/lib/files");

module.exports = {
  extends: "@focus21",
  overrides: [
    {
      files: files.baseFiles,
      rules: {
        "import/no-extraneous-dependencies": [
          "error",
          {
            devDependencies: devFiles,
            myExtraneousDependenciesSetting: true,
          },
        ],
      },
    },
    {
      files: files.commonjsFiles,
      rules: {
        "my-non-es6-rule": "error",
      },
    },
  ],
};

Defaults

defaults are exported from @focus21/eslint-config/lib for your .eslintrc.js.

Default settings

defaults.settings is the internal default settings object. You can override settings using the function defaults.mergeSettings.

Also available is defaults.preactSettings and defaults.mergePreactSettings for Preact projects.

Example usage:

// .eslintrc.js

const { defaults } = require("@focus21/eslint-config/lib");

const settings = defaults.mergeSettings({
  "import/resolver": {
    typescript: {
      "my-typescript-setting": true,
    },
  },
});

// ...rest of config...

Default Restricted Imports

defaults.restrictedImports is the internal default no-restricted-imports param. You can override its settings using defaults.mergeRestrictedImports.

Also available is defaults.reactRestrictedImports and defaults.mergeRestrictedImports for React projects.

Example usage:

// .eslintrc.js

const { files, defaults } = require("@focus21/eslint-config/lib");

const restrictedImports = defaults.mergeRestrictedImports({
  paths: [
    {
      name: "my-path",
      message: "My message.",
    },
  ],
  // Enable importing `moment`, which normally gives a warning
  patterns: ["!moment"],
});

module.exports = {
  extends: "@focus21",
  overrides: [
    {
      files: files.baseFiles,
      rules: {
        "no-restricted-imports": ["error", restrictedImports],
      },
    },
  ],
};

Default No Unresolved Import Options

defaults.unresolvedImportOptions are the internal default import/no-unresolved options. The defaults include some ignore files. You can merge options using defaults.mergeUnresolvedImportOptions.

Also available is defaults.preactUnresolvedImportOptions and defaults.mergePreactUnresolvedImportOptions for Preact projects.

Example usage:

// .eslintrc.js

const { files, defaults } = require("@focus21/eslint-config/lib");

const unresolvedImportOptions = defaults.mergeUnresolvedImportOptions({
  commonjs: false,
});

module.exports = {
  extends: "@focus21",
  overrides: [
    {
      files: files.baseFiles,
      rules: {
        "import/no-unresolved": ["error", unresolvedImportOptions],
      },
    },
  ],
};

Fixes

Some issues are not possible to fix in this package and must be fixed directly in your config.

Fix Dev Dependencies

The rule import/no-extraneous-dependencies may not work correctly when ESLint is run from subdirectories.

To fix this problem, extend the base config and use absolute paths in options.

module.exports = {
  overrides: [
    {
      files: files.baseFiles,
      extends: "@focus21/eslint-config/base",
      rules: {
        "import/no-extraneous-dependencies": [
          "error",
          {
            devDependencies: files.devFiles.map(
              (pattern) => `${__dirname}/${pattern}`
            ),
          },
        ],
      },
      settings,
    },
  ],
};

Additional Configs

  • @focus21/eslint-config/preact:
    • Use on Preact projects.
    • Does not conflict with react/react-testing-library.
    • Extend after react and before commonjs.
  • @focus21/eslint-config/svelte:
    • Use on Svelte projects.
    • Extend after base and before commonjs with svelteFiles.
  • @focus21/eslint-config/typescript:
    • Use on projects which use Typescript.
    • Conflicts with flowtype unless targetted towards custom files.
    • Extend after react and before commonjs.
  • @focus21/eslint-config/flowtype:
    • Use on projects which use flow.
    • Conflicts with typescript unless targetted towards custom files.
    • Extend after react and before commonjs.
  • @focus21/eslint-config/next:
    • Use on Next projects.
    • Extend after react and before commonjs.
  • @focus21/eslint-config/mocha:
    • Use on projects which use Mocha/Chai.
    • Conflicts with jest unless targetted towards custom files.
    • Extend after react and before commonjs with mochaFiles.
  • @focus21/eslint-config/cypress
    • Use on projects with Cypress.
    • Extend after react and before commonjs with cypressFiles.
  • @focus21/eslint-config/storybook
    • Use on projects with Storybook.
    • Extend after react and before commonjs.
  • @focus21/eslint-config/tailwindcss:
    • Use on projects which use TailwindCSS.
    • Extend after base and before commonjs.

Example usage:

// .eslintrc.js

const { files, defaults } = require("@focus21/eslint-config/lib/files");

const { settings } = default;

module.exports = {
  overrides: [
    {
      files: files.baseFiles,
      extends: [
        "@focus21/eslint-config/base",
        "@focus21/eslint-config/react",
        "@focus21/eslint-config/react-testing-library",
        "@focus21/eslint-config/jsdoc",
        // Enable Preact
        // Requires `preactSettings` below.
        "@focus21/eslint-config/preact",
        // Enable Typescript
        "@focus21/eslint-config/typescript",
        // Enable Next
        "@focus21/eslint-config/next",
        // Enable Storybook
        "@focus21/eslint-config/storybook",
        // Enable TailwindCSS
        "@focus21/eslint-config/tailwindcss",
      ],
      // For preact projects, requires `preactSettings`.
      settings,
    },
    {
      files: files.jestFiles,
      extends: "@focus21/eslint-config/jest",
      settings,
    },
    // Enable Svelte
    {
      files: files.svelteFiles,
      extends: "@focus21/eslint-config/svelte",
      settings,
    },
    // Enable Flow with custom files so it doesn't conflict with Typescript
    {
      files: ["myFlowFiles"],
      extends: "@focus21/eslint-config/flowtype",
      settings,
    },
    // Enable Mocha with custom files so it doesn't conflict with Jest
    {
      files: ["myMochaFiles"],
      extends: "@focus21/eslint-config/mocha",
      settings,
    },
    // Enable Cypress
    {
      files: files.cypressFiles,
      extends: "@focus21/eslint-config/cypress",
      settings,
    },
    {
      files: files.commonjsFiles,
      extends: "@focus21/eslint-config/commonjs",
      settings,
    },
    {
      files: files.testFiles,
      extends: "@focus21/eslint-config/test",
      settings,
    },
    {
      files: files.devFiles,
      extends: "@focus21/eslint-config/dev",
      settings,
    },
  ],
};