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

@qlik/eslint-config

v1.1.7

Published

Qlik's ESLint configs

Downloads

33,066

Readme

@qlik/eslint-config

Qlik's ESlint config for JavaScript/TypeScript environments with optional framework support.

Migrating from 0.x

  1. Install latest @qlik/eslint-config
  2. Update to ESLint 9
  3. Rename your config to eslint.config.js (if you have "type": "module" in your package json) / eslint.config.mjs (if otherwise)

example config that uses typescript, react, vitest, react-query plugin:

// @ts-check
import qlik from "@qlik/eslint-config";
import pluginQuery from "@tanstack/eslint-plugin-query";

export default qlik.compose(
  ...qlik.configs.react,
  ...qlik.configs.vitest,
  ...pluginQuery.configs["flat/recommended"],
  {
    rules: {
      // Override rules if needed
    },
  },
  // In its own object so it's global
  {
    ignores: ["dist", "node_modules", "script"],
  },
);
  1. If you are not using typescript to build your project, then include all files "include": [".*", "**/*"] in the project's tsconfig.json
  2. Run your lint script

v1 notable changes

Usage

The default exports configs works on both TypeScript and JavaSript out of the box. (as long as the file endings are any of .js, .jsx, .mjs, .cjs, .ts, .tsx, .cts, .mts). The configs are eslint flat config arrays populated with configs that has appropriate file endings attached to them. Designed to diminish the amount of configuration needed in an eslint.config.js file.

To get started, create eslint.config.js (if your package json has "type": "module"), otherwise create eslint.config.mjs. If you are not building your project with TypeScript (using Webpack or Vite for example), then tell TypeScript to include all files by setting "include": [".*", "**/*"] in tsconfig.json.

For a pure browser environment with no specific frameworks use:

// @ts-check
import qlik from "@qlik/eslint-config";

export default qlik.compose(
  ...qlik.configs.recommended, // adds linting on .js, .jsx, .mjs, .cjs, .ts, .tsx, .cts, .mts files. use for pure browser environment
  {
    ignores: ["dist", "npm", "node_modules"],
  },
);

Using React with vitest:

// @ts-check
import qlik from "@qlik/eslint-config";

export default qlik.compose(
  ...qlik.configs.react, // based on the recommended config and adds react linting on .jsx and .tsx files
  {
    ignores: ["dist", "node_modules"],
  },
);

Using Svelte:

// @ts-check
import qlik from "@qlik/eslint-config";

export default qlik.compose(
  ...qlik.configs.svelte, // based on the recommended config and adds svelte linting on .svelte files
  {
    ignores: ["dist", "node_modules"],
  },
);

Using React and Svelte:

// @ts-check
import qlik from "@qlik/eslint-config";

export default qlik.compose(
  ...qlik.configs.react,
  ...qlik.configs.svelte,
  {
    ignores: ["dist", "node_modules"],
  },
);

Node environment:

// @ts-check
import qlik from "@qlik/eslint-config";

export default qlik.compose(
  ...qlik.configs.esm, // or qlik.configs.cjs for commonjs, recommended config with node environment enabled
  {
    ignores: ["dist", "npm", "node_modules"],
  },
);

Additional configs that can be used in conjunction with the ones above:

// @ts-check
import qlik from "@qlik/eslint-config";

export default qlik.compose(
  ...qlik.configs.recommended,  // pure browser environment
  ...qlik.configs.vitest,       // enable vitest linting on files inside __test(s)__ folder
  ...qlik.configs.jest,         // enable jest linting on files inside __test(s)__ folder, DON'T use together with vitest
  ...qlik.configs.playwright,   // enable playwright linting on files inside ./test(s) folder.
  {
    ignores: ["dist", "npm", "node_modules"],
  },
);

Using the named exports configs

The different configs are also accessible through named imports. These configs can be used in specific scenarios where more control of the configs are needed. The extend property can be used to apply a config on certain file patterns.

Example only use javascript rules with react

import qlik, { recommendedJS, reactJS } from "@qlik/eslint-config";

export default qlik.compose(
  reactJS,
)

with typescript support

import qlik, { recommendedJS, reactJS } from "@qlik/eslint-config";

export default qlik.compose(
  reactJS,
  reactTS,
)

This is equal to:

import qlik from "@qlik/eslint-config";

export default qlik.compose(
  ...qlik.configs.react,
)

Using only javascript and svelte

import qlik, { recommendedJS, svelteJS } from "@qlik/eslint-config";

export default qlik.compose(
  recommendedJS,
  svelteJS,
)

The single configs can be useful together with the extend property. Below shows an example of a config that wants to use lint rules for node environment on a part of the code base.

import qlik, { esmJS } from "@qlik/eslint-config";

export default qlik.compose(
  // apply recommended config to all files
  ...qlik.configs.recommended,
  // set node esm config on .js files inside the tools folder
  {
    files: ["tools/**/*.js"],
    extend: [esmJS],
  },
)

This will take the configs in the extend array and perform a deep merge of whatever is defined in the object containing the extend property with the configs in the extend array and return them as separate configs. The deep merge has three exceptions. files, ignores and globals are always overwritten by the later config.

import qlik, { esmJS } from "@qlik/eslint-config";

export default qlik.compose(
  {
    extend: [...qlik.configs.recommended], // contains two configs (recommendedJS and recommendedTS)
    files: ["only_want_lint_here/**/*.js"],
  },
)

This will result in two configs, each with the given file pattern like this:

export default [
  {
    ...recommendedJS config
    files: ["only_want_lint_here/**/*.js"],
  },
  {
    ...recommendedTS config
    files: ["only_want_lint_here/**/*.js"],
  }
]

More examples with export

One GOTCHA about the flat configs. If there's no files property in one of the configs in the config array it is applied to every file. So in the case of turning off a rule that belongs to specific config e.g. @typescript/eslint. The following approach can be problematic.

// @ts-check
import qlik from "@qlik/eslint-config";

export default qlik.compose(
  ...qlik.configs.recommended, // <-- typescript-eslint is applied to .ts files only
  {
    rules: {
      // I want to change this rule, but it is applied to all files so if I have a .js file somewhere getting linted I will get an ERROR about missing plugin.
      "@typescript-eslint/method-signature-style": "off",
    },
  },
);

This will have to be fine-tuned. However, it is recommended to not disable rules.

// @ts-check
import qlik from "@qlik/eslint-config";

export default qlik.compose(
  ...qlik.configs.recommended, // <-- typescript-eslint is applied to .ts files only
  {
    files: ["**/*.ts"]
    rules: {
      // typescript specific rules here
      "@typescript-eslint/method-signature-style": "off",
    },
  },
  {
    rules: {
      // these are fine, since they are applied to all files
      "no-var": "off",
      "import-x/no-unresolved": "off"
    },
  },
);

Another GOTCHA can happen with the vitest and jest configs

// @ts-check
import qlik from "@qlik/eslint-config";

export default qlik.compose(
  ...qlik.configs.recommended,
  qlik.configs.vitest, // <-- this is applied to files inside __test(s)__ folders by default for our convenience
  {
    rules: {
      // I want to change this rule, but it doesn't work because it is applied to all files
      "vitest/max-nested-describe": [
        "error",
        {
          "max": 3
        },
      ],
    },
  },
);

Here the extend feature becomes helpful

// @ts-check
import qlik from "@qlik/eslint-config";

export default qlik.compose(
  ...qlik.configs.recommended,
  {
    extend: [qlik.configs.vitest],
    rules: {
      // This will add or overwrite the rule in the default config
      "vitest/max-nested-describe": [
        "error",
        {
          "max": 3
        },
      ],
    },
  },
);

Example of changing the default file patterns on the vitest config.

// @ts-check
import qlik from "@qlik/eslint-config";

export default qlik.compose(
  ...qlik.configs.recommended,  // pure browser environment, no framework config added
  {
    // adds vitest lint rules on the specified files with an altered rule
    files: ['**/my_tests_are_here/*.spec.ts']
    extend: [qlik.configs.vitest],
    rules: {
      "vitest/max-nested-describe": [
        "error",
        {
          "max": 3
        }
      ]
    }
  },
);

This will result in a final config looking like this:

export default [
  {
    ...recommendedJS config
  },
  {
    ...recommendedTS config
  },
  {
    files: ['**/my_tests_are_here/*.spec.ts'],
    ...vitest config
    rules: {
      ... vitest config rules,
      "vitest/max-nested-describe": [
        "error",
        {
          "max": 3
        }
      ]
    }
  }
]