@itwin/eslint-plugin

4.1.1 • Public • Published

@itwin/eslint-plugin

ESLint plugin with default configuration and custom rules for iTwin.js projects. For best results, use with Typescript 4.1+

Installation

You'll first need to install ESLint and @itwin/eslint-plugin:

npm i eslint --save-dev
npm i @itwin/eslint-plugin --save-dev

Using with VSCode

In order for VSCode to use the config file as it is set up, add the following setting to the the VSCode settings (in .vscode/settings.json):

"eslint.experimental.useFlatConfig": true,

Usage

Create an eslint.config.js file at the root of your project. To set up the file, import @itwin/eslint-plugin. Then set the file to export an array of configuration files. This will be done differently depending on whether your project uses ESM or CJS.

ESM

import iTwinPlugin from "@itwin/eslint-plugin";

export default [
  {
    files: ["**/*.{ts,tsx}"],
    ...iTwinPlugin.configs.iTwinjsRecommendedConfig,
  },
  {
    files: ["**/*.{ts,tsx}"],
    ...iTwinPlugin.configs.jsdocConfig,
  },
];

CJS

const iTwinPlugin = require("@itwin/eslint-plugin");

module.exports = [
  {
    files: ["**/*.{ts,tsx}"],
    ...iTwinPlugin.configs.iTwinjsRecommendedConfig,
  },
  {
    files: ["**/*.{ts,tsx}"],
    ...iTwinPlugin.configs.jsdocConfig,
  }
];

Then configure the rules you want to override, add a section with rules to be overriden and their severity.

const iTwinPlugin = require("@itwin/eslint-plugin");

module.exports = [
  {
    files: ["**/*.{ts,tsx}"],
    ...iTwinPlugin.configs.iTwinjsRecommendedConfig,
  },
  {
    files: ["**/*.{ts,tsx}"],
    ...iTwinPlugin.configs.jsdocConfig,
  },
  {
    rules: {
      "@typescript-eslint/no-explicit-any": "error",
    }
  }
];

Rules not in recommended configs

To add rules not set in the recommended configurations, add a plugins section with the @itwin/eslint-plugin that was imported. Then, add a rules section with the rule that needs to be added and the severity of error for the rule.

If a configuration that defines the language parsing options is not used, add a languageOptions object. Below is an example of using the @itwin/no-internal rule where we define the language options to parse typescript.

no-internal - prevents use of internal/alpha APIs. Example configurations

// custom config
const iTwinPlugin = require("@itwin/eslint-plugin");

module.exports = [
  {
    languageOptions: {
      sourceType: "module",
      parser: require("@typescript-eslint/parser"),
      parserOptions: {
        project: "tsconfig.json",
        ecmaVersion: "latest",
        ecmaFeatures: {
          jsx: true,
          modules: true
        },
      },
    },
    plugins: {
      "@itwin": iTwinPlugin
    },
    files: ["**/*.{ts,tsx}"],
    rules: {
      "@itwin/no-internal": "error",
    }
  }
];
// default config
rules: {
  "@itwin/no-internal": "error"
}
// tag is set to ["internal", "alpha"] by default

The rule has some options:

  • tag - List of tags where the rule will report on usages of APIs documented as them. Allowed tags: internal, alpha, beta, public.
    • Default: internal, alpha
  • checkedPackagePatterns - List of regex patterns where the rule will only be enforced for APIs that are from a package whose name matches a pattern in the list.
    • Default: ^@itwin/, ^@bentley/
  • dontAllowWorkspaceInternal - Flag that if set to true, the rule will be enforced on usages of APIs from packages that are part of the same workspace/monorepo. If set to false, usages of APIs from workspace dependencies will not report an error.
    • Default: false

Helper commands

no-internal-report - Runs eslint with the @itwin/no-internal rule turned on ("error") using a custom formatter that summarizes the output

This can be run using npx or from the scripts section of package.json:

  "scripts": {
    "no-internal-report": "no-internal-report \"src/**/*.ts*\""
  },

This command forwards all arguments to eslint, so it can be further customized as needed. For example, to specify the tags for the no-internal rule:

  "scripts": {
    "no-internal-report": "no-internal-report --tags internal,alpha,beta \"src/**/*.ts*\""
  },

In addition to this we also have a custom formatter that can be used to generate a summary table report of the no-internal violations in your codebase.

It creates a easily readable summary table of all your violations. For example: Summary Table

In addition, this also creates a csv with the same table in the current working directory. You can call it like this:

eslint ./**/*.{ts,tsx} 1>&2 -f ./node_modules/@itwin/eslint-plugin/dist/formatters/no-internal-summary-with-table.js

If you want to import the table creator directly into your code and acquire the string before printing, you can do so by importing the function noInternalSummaryTableCreator from @itwin/eslint-plugin package, then pass in the Message[] type objects or directly pass in the LintResult[] objects you get when calling eslint.lintFiles().

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.8.02,800previous
4.1.12,318latest
5.0.0-dev.11,533nightly
3.8.0-dev.11rc

Version History

VersionDownloads (Last 7 Days)Published
5.0.0-dev.11,533
4.1.12,318
4.1.086
4.0.2228
4.0.2-dev.013
4.0.11,056
4.0.03
4.0.0-dev.5285
4.0.0-dev.511
4.0.0-dev.501
4.0.0-dev.491
3.8.02,800
3.8.0-dev.11
3.7.1721
3.7.162
3.7.151
3.7.141
3.7.131
4.0.0-dev.48194
3.7.121
4.0.0-dev.471
4.0.0-dev.461
4.0.0-dev.451
4.0.0-dev.4414
3.7.111
4.0.0-dev.431
4.0.0-dev.421
4.0.0-dev.411
4.0.0-dev.401
3.7.939
4.0.0-dev.391
3.7.8747
3.7.746
3.7.61
3.7.5139
4.0.0-dev.3898
4.0.0-dev.371
4.0.0-dev.36139
3.7.41
3.7.31
4.0.0-dev.351
4.0.0-dev.341
3.7.21
3.7.116
3.7.01
4.0.0-dev.331
3.7.0-dev.816
3.6.31
3.7.0-dev.71
3.7.0-dev.61
3.7.0-dev.51
4.0.0-dev.321
4.0.0-dev.311
3.7.0-dev.31
3.6.21
3.7.0-dev.21
4.0.0-dev.301
4.0.0-dev.281
3.6.11
3.5.61
4.0.0-dev.241
4.0.0-dev.231
4.0.0-dev.221
4.0.0-dev.211
4.0.0-dev.181
4.0.0-dev.171
3.7.0-dev.11
4.0.0-dev.151
4.0.0-dev.111
3.6.01
4.0.0-dev.101
4.0.0-dev.81
4.0.0-dev.71
4.0.0-dev.61
4.0.0-dev.41
3.6.0-dev.661
4.0.0-dev.21
4.0.0-dev.11
3.6.0-dev.651
3.6.0-dev.621
3.5.51
3.6.0-dev.601
3.6.0-dev.591
3.6.0-dev.551
3.6.0-dev.541
3.6.0-dev.531
3.6.0-dev.521
3.5.41
3.6.0-dev.511
3.6.0-dev.501
3.5.31
3.6.0-dev.471
3.6.0-dev.441
3.5.21
3.6.0-dev.411
3.6.0-dev.401
3.6.0-dev.381
3.6.0-dev.361
3.6.0-dev.351
3.6.0-dev.341
3.6.0-dev.331
3.6.0-dev.321
3.6.0-dev.221
3.6.0-dev.211
3.5.11
3.6.0-dev.141
3.6.0-dev.111
3.6.0-dev.101
3.6.0-dev.81
3.6.0-dev.71
3.5.01
3.5.0-dev.681
3.6.0-dev.51
3.5.0-dev.671
3.6.0-dev.31
3.6.0-dev.11
3.5.0-dev.661
3.5.0-dev.651
3.4.71
3.5.0-dev.631
3.5.0-dev.611
3.5.0-dev.601
3.5.0-dev.591
3.5.0-dev.581
3.5.0-dev.571
3.4.61
3.5.0-dev.531
3.5.0-dev.521
3.4.51
3.5.0-dev.511
3.5.0-dev.491
3.5.0-dev.471
3.5.0-dev.451
3.4.41
3.5.0-dev.431
3.5.0-dev.411
3.5.0-dev.351
3.5.0-dev.341
3.5.0-dev.331
3.5.0-dev.321
3.5.0-dev.311
3.5.0-dev.301
3.4.31
3.5.0-dev.291
3.5.0-dev.281
3.5.0-dev.271
3.5.0-dev.261
3.4.221
3.5.0-dev.251
3.5.0-dev.241
3.5.0-dev.221
3.5.0-dev.211
3.5.0-dev.201
3.5.0-dev.191
3.4.11
3.5.0-dev.181
3.5.0-dev.161
3.4.01
3.4.0-dev.631
3.5.0-dev.141
3.5.0-dev.131
3.4.0-dev.621
3.5.0-dev.121
3.5.0-dev.111
3.5.0-dev.81
3.4.0-dev.611
3.5.0-dev.71
3.4.0-dev.601
3.5.0-dev.51
3.5.0-dev.41
3.4.0-dev.591
3.4.0-dev.581
3.4.0-dev.571
3.4.0-dev.561
3.3.51
3.4.0-dev.551
3.4.0-dev.501
3.4.0-dev.481
3.4.0-dev.471
3.4.0-dev.461
3.4.0-dev.441
3.4.0-dev.431
3.4.0-dev.421
3.4.0-dev.411
3.4.0-dev.401
3.4.0-dev.391
3.4.0-dev.371
3.3.41
3.4.0-dev.361
3.4.0-dev.351
3.3.31
3.4.0-dev.341
3.4.0-dev.331
3.4.0-dev.321
3.4.0-dev.301
3.3.21
3.4.0-dev.291
3.4.0-dev.281
3.4.0-dev.271
3.4.0-dev.261
3.4.0-dev.251
3.4.0-dev.241
3.3.11
3.2.91
3.4.0-dev.231
3.4.0-dev.221
3.4.0-dev.211
3.4.0-dev.201
3.4.0-dev.191
3.4.0-dev.181
3.4.0-dev.161
3.3.01
3.3.0-dev.891
3.4.0-dev.151
3.4.0-dev.141
3.4.0-dev.121
3.4.0-dev.101
3.3.0-dev.881
3.4.0-dev.91
3.3.0-dev.871
3.3.0-dev.861
3.4.0-dev.81
3.4.0-dev.71
3.2.81
3.4.0-dev.31
3.3.0-dev.851
3.4.0-dev.21
3.4.0-dev.11
3.4.0-dev.01
3.3.0-dev.841
3.3.0-dev.831
3.2.71
3.3.0-dev.821
3.3.0-dev.811
3.3.0-dev.801
3.3.0-dev.791
3.3.0-dev.781
3.3.0-dev.771
3.3.0-dev.761
3.3.0-dev.751
3.3.0-dev.721
3.3.0-dev.711
3.3.0-dev.701
3.3.0-dev.691
3.3.0-dev.681
3.3.0-dev.671
3.3.0-dev.661
3.2.66
3.3.0-dev.651
3.3.0-dev.641
3.3.0-dev.631
3.2.51
3.3.0-dev.621
3.3.0-dev.611
3.3.0-dev.601
3.3.0-dev.581
3.3.0-dev.571
3.3.0-dev.561
3.3.0-dev.551
3.3.0-dev.541
3.3.0-dev.531
3.3.0-dev.521
3.3.0-dev.511
3.3.0-dev.501
3.3.0-dev.491
3.3.0-dev.481
3.3.0-dev.471
3.3.0-dev.461
3.3.0-dev.441
3.3.0-dev.431
3.3.0-dev.421
3.2.42
3.3.0-dev.411
3.3.0-dev.401
3.3.0-dev.391
3.3.0-dev.381
3.3.0-dev.371
3.3.0-dev.361
3.2.31
3.3.0-dev.351
3.3.0-dev.341
3.3.0-dev.331
3.3.0-dev.321
3.3.0-dev.311
3.3.0-dev.301
3.3.0-dev.291
3.2.21
3.3.0-dev.281
3.3.0-dev.271
3.3.0-dev.261
3.2.11
3.3.0-dev.251
3.3.0-dev.241
3.3.0-dev.231
3.3.0-dev.221
3.3.0-dev.211
3.3.0-dev.201
3.3.0-dev.191
3.3.0-dev.181
3.3.0-dev.131
3.3.0-dev.111
3.3.0-dev.101
3.3.0-dev.91
3.3.0-dev.81
3.2.01
3.3.0-dev.71
3.3.0-dev.61
3.2.0-dev.771
3.3.0-dev.51
3.2.0-dev.761
3.3.0-dev.41
3.3.0-dev.31
3.3.0-dev.21
3.3.0-dev.11
3.2.0-dev.751
3.2.0-dev.741
3.3.0-dev.01
3.2.0-dev.721
3.2.0-dev.711
3.2.0-dev.701
3.2.0-dev.691
3.2.0-dev.681
3.2.0-dev.671
3.2.0-dev.661
3.2.0-dev.651
3.2.0-dev.641
3.2.0-dev.631
3.2.0-dev.621
3.2.0-dev.611
3.2.0-dev.601
3.2.0-dev.591
3.2.0-dev.581
3.2.0-dev.571
3.2.0-dev.561
3.2.0-dev.551
3.2.0-dev.541
3.2.0-dev.531
3.2.0-dev.521
3.2.0-dev.511
3.2.0-dev.501
3.2.0-dev.491
3.2.0-dev.481
3.2.0-dev.471
3.2.0-dev.461
3.2.0-dev.451
3.1.31
3.2.0-dev.441
3.2.0-dev.431
3.2.0-dev.421
3.2.0-dev.411
3.2.0-dev.401
3.2.0-dev.391
3.2.0-dev.381
3.2.0-dev.371
3.2.0-dev.361
3.1.21
3.2.0-dev.351
3.2.0-dev.341
3.2.0-dev.331
3.2.0-dev.301
3.1.11
3.2.0-dev.291
3.2.0-dev.281
3.1.01
3.2.0-dev.271
3.2.0-dev.261
3.2.0-dev.251
3.2.0-dev.241
3.1.0-dev.481
3.0.31
3.2.0-dev.231
3.2.0-dev.221
3.2.0-dev.211
3.2.0-dev.201
3.1.0-dev.471
3.2.0-dev.191
3.2.0-dev.181
3.2.0-dev.171
3.2.0-dev.161
3.2.0-dev.151
3.2.0-dev.141
3.1.0-dev.461
3.2.0-dev.131
3.2.0-dev.121
3.1.0-dev.451
3.2.0-dev.91
3.0.21
3.2.0-dev.81
3.2.0-dev.71
3.1.0-dev.441
3.2.0-dev.61
3.2.0-dev.51
3.2.0-dev.31
3.2.0-dev.11
3.1.0-dev.421
3.2.0-dev.01
3.1.0-dev.411
3.1.0-dev.401
3.1.0-dev.391
3.1.0-dev.381
3.1.0-dev.371
3.1.0-dev.361
3.0.11
3.1.0-dev.351
3.1.0-dev.341
3.1.0-dev.331
3.1.0-dev.321
3.1.0-dev.311
3.1.0-dev.291
3.1.0-dev.281
3.1.0-dev.271
3.1.0-dev.261
3.1.0-dev.251
3.1.0-dev.241
3.1.0-dev.231
3.1.0-dev.221
3.1.0-dev.211
3.1.0-dev.201
3.1.0-dev.191
3.1.0-dev.151
3.1.0-dev.141
3.1.0-dev.131
3.1.0-dev.121
3.0.041
3.1.0-dev.111
3.1.0-dev.81
3.1.0-dev.71
3.1.0-dev.61
3.1.0-dev.51
3.1.0-dev.11
3.1.0-dev.01
3.0.0-dev.1851
3.0.0-dev.1841
3.0.0-dev.1831
3.0.0-dev.1821
3.0.0-dev.1811
3.0.0-dev.1801
3.0.0-dev.1791
3.0.0-dev.1781
3.0.0-dev.1771
3.0.0-dev.1761
3.0.0-dev.1751
3.0.0-dev.1741
3.0.0-dev.1731
3.0.0-dev.1721
3.0.0-dev.1701
3.0.0-dev.1691
3.0.0-dev.1681
3.0.0-dev.1671
3.0.0-dev.1661
3.0.0-dev.1631
3.0.0-dev.1611
3.0.0-dev.1601
3.0.0-dev.1591
3.0.0-dev.1571
3.0.0-dev.1561
3.0.0-dev.1551
3.0.0-dev.1541
3.0.0-dev.1531
3.0.0-dev.1521
3.0.0-dev.1511
3.0.0-dev.1491
3.0.0-dev.1481
3.0.0-dev.1471
3.0.0-dev.1461
3.0.0-dev.1451
3.0.0-dev.1441
3.0.0-dev.1431
3.0.0-dev.1411
3.0.0-dev.1401
3.0.0-dev.1391
3.0.0-dev.1381
3.0.0-dev.1361
3.0.0-dev.1351
3.0.0-dev.1341
3.0.0-dev.1331
3.0.0-dev.1311
3.0.0-dev.1301
3.0.0-dev.1291
3.0.0-dev.1281
3.0.0-dev.1271
3.0.0-dev.1261
3.0.0-dev.1258
3.0.0-dev.12415
3.0.0-dev.1238
3.0.0-dev.1228
3.0.0-dev.1218
3.0.0-dev.1201
3.0.0-dev.1191
3.0.0-dev.1171
3.0.0-dev.1161
3.0.0-dev.1151
3.0.0-dev.1148
3.0.0-dev.1131
3.0.0-dev.1121
3.0.0-dev.1091
3.0.0-dev.1081
3.0.0-dev.1071
3.0.0-dev.1061
3.0.0-dev.1051
3.0.0-dev.1041
3.0.0-dev.1031
3.0.0-extension.11
3.0.0-dev.1021
3.0.0-dev.1011
3.0.0-dev.1001
3.0.0-dev.991
3.0.0-dev.981
3.0.0-extension.01
3.0.0-dev.971
3.0.0-dev.961
3.0.0-dev.951
3.0.0-dev.941
3.0.0-dev.931
3.0.0-dev.921
3.0.0-dev.911
3.0.0-dev.901
3.0.0-dev.891
3.0.0-dev.881
3.0.0-dev.871
3.0.0-dev.861
3.0.0-dev.850
3.0.0-dev.840
3.0.0-dev.830
3.0.0-dev.820
3.0.0-dev.810
3.0.0-dev.800
3.0.0-dev.790
3.0.0-dev.780
3.0.0-dev.770
3.0.0-dev.760
3.0.0-dev.730
3.0.0-dev.720

Package Sidebar

Install

npm i @itwin/eslint-plugin

Weekly Downloads

8,614

Version

4.1.1

License

MIT

Unpacked Size

112 kB

Total Files

30

Last publish

Collaborators

  • wgoehrig
  • cshafer
  • aruniverse
  • imodeljs
  • colinkerr