azure-sdk-for-js/common/tools/eslint-plugin-azure-sdk
Jeremy Meng d8b577111a
[EngSys] Pin @azure/msal-* version temporarily (#31819)
because upgrading them caused identity unit tests to fail. This allows
us to upgrade other packages to address security alerts.
2024-11-19 15:29:16 -08:00
..
config [EngSys] Fix format checking error (#27602) 2023-10-31 17:27:38 +00:00
docs/rules [eslint-plugin] update rule to allow .cjs main entry (#26120) 2023-06-07 16:42:53 -07:00
src [EngSys] Pin @azure/msal-* version temporarily (#31819) 2024-11-19 15:29:16 -08:00
tests [eslint-plugin] fix ts-naming-options rule issue 2024-10-02 16:40:01 +00:00
.markdownlint.json [eslint-plugin] Move eslint-plugin-azure-sdk to this repo (#6748) 2020-02-20 11:15:44 -08:00
CONTRIBUTING.md Update prettier dev-dependency to v2.5.1 in Eslint plugin (#19536) 2022-01-06 13:23:11 -06:00
README.md [EngSys] fix rush format (#21372) 2022-04-13 10:50:36 -07:00
ci.yml [engsys] Avoid running eslint plugin unit tests on every analyze (#27938) 2023-11-29 13:08:26 -08:00
eslint.config.mjs skip linting for config files for the two packages that don't depend on dev-tool 2024-08-23 16:38:09 -07:00
eslint.perftests.config.mjs [linting] move perf tests to use eslint flat config 2024-08-15 10:56:56 -07:00
package.json [EngSys] Pin @azure/msal-* version temporarily (#31819) 2024-11-19 15:29:16 -08:00
prettier.json [eslint-plugin] Move eslint-plugin-azure-sdk to this repo (#6748) 2020-02-20 11:15:44 -08:00
tsconfig.build.json [eslint-plugin] support Flat Config (#29751) 2024-05-21 18:12:00 +00:00
tsconfig.json [engsys] Update eslint plugin to 6.x (#29505) 2024-04-30 20:56:00 +00:00
tsconfig.lintjson.json [eslint-plugin] Move eslint-plugin-azure-sdk to this repo (#6748) 2020-02-20 11:15:44 -08:00
vitest.config.mts [EngSys] standardize OSS copyright header 2024-08-27 13:01:38 -07:00

README.md

eslint-plugin-azure-sdk

An ESLint plugin enforcing design guidelines for the JavaScript/TypeScript Azure SDK.

Installing and Building

Note: This is an internal package that can only be used within the azure-sdk-for-js monorepo.

To enable @azure/eslint-plugin-azure-sdk, you'll need to add it to the list of devDependencies in your package.json:

{
  ...,
  "devDependencies": {
    ...,
    "@azure/eslint-plugin-azure-sdk": "^3.0.0",
    ...
  },
  ...
}

The ESLint plugin must be built from source as part of your package's depdendencies. The fastest way to build a single package and its dependencies is to run the command rush build -t <package name>. For example, to rebuild the Form Recognizer package and all of its dependencies, we run rush build -t @azure/ai-form-recognizer. This will rebuild eslint-plugin-azure-sdk if necessary and make it available for use by the package's NPM scripts.

You must rebuild eslint-plugin-azure-sdk after making changes to its own source files, either using rush build as described above, or by entering the common/tools/eslint-plugin-azure-sdk directory (this directory) and running rushx build. Since the plugin is linked internally as part of our monorepo, the package does not need to be installed again after it is rebuilt.

See the contribution guide for more details about contributing to the azure-sdk-for-js repository.

Configuration

ESLint will automatically use the configuration file sdk/.eslintrc.json as explained in the docs. Optionally, you can have a custom .eslintrc.json file at the same location as your package.json file. A very simple one looks as follows: (note that the path to the base .eslintrc.json file may be different)

{
  "plugins": ["@azure/azure-sdk"],
  "extends": ["../../.eslintrc.json", "plugin:@azure/azure-sdk/recommended"],
  "parserOptions": {
    "createDefaultProgram": true
  }
}

If the main TypeScript entrypoint to your package is not in src/index.ts, set settings.main in your .eslintrc configuration file to the entrypoint as follows (for example, if the entrypoint is index.ts):

{
  "plugins": ["@azure/azure-sdk"],
  "extends": ["../../.eslintrc.json", "plugin:@azure/azure-sdk/recommended"],
  "parserOptions": {
    "createDefaultProgram": true
  },
  "settings": {
    "main": "index.ts"
  }
}

If you need to modify or disable specific rules, you can do so in the rules section of your .eslintrc configuration file. For example, if you are not targeting Node, disable ts-config-moduleresolution as follows:

{
  "plugins": ["@azure/azure-sdk"],
  "extends": ["../../.eslintrc.json", "plugin:@azure/azure-sdk/recommended"],
  "parserOptions": {
    "createDefaultProgram": true
  },
  "rules": {
    "@azure/azure-sdk/ts-config-moduleresolution": "off"
  }
}

Some rules (see table below) are fixable using the --fix ESLint option (added in 1.3.0).

Supported Rules

Key

Symbol Meaning
🚩 Error
⚠️ Warning
✖️ Off
✔️ Fixable and autofix-enabled
Not fixable

Rules

Rule Default Fixable Release
[github-source-headers]https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/eslint-plugin-azure-sdk/docs/rules/github-source-headers.md) 🚩 ✔️ 1.1.0
ts-apisurface-standardized-verbs 🚩 1.2.0
ts-apisurface-supportcancellation 🚩 1.2.0
ts-config-include 🚩 ✔️ 1.0.0
ts-doc-internal 🚩 1.1.0
ts-doc-internal-private-member 🚩 3.1.0
ts-error-handling ✖️ 1.1.0
ts-modules-only-named 🚩 1.1.0
ts-naming-drop-noun 🚩 1.2.0
ts-naming-options 🚩 1.2.0
ts-naming-subclients 🚩 1.2.0
ts-no-const-enums ⚠️ ✔️ 1.1.0
ts-no-window 🚩 ✔️ 3.1.0
ts-package-json-author 🚩 ✔️ 1.0.0
ts-package-json-bugs 🚩 ✔️ 1.0.0
ts-package-json-engine-is-present 🚩 ✔️ 1.1.0
ts-package-json-files-required 🚩 ✔️ 1.1.0
ts-package-json-homepage 🚩 1.0.0
ts-package-json-keywords 🚩 ✔️ 1.0.0
ts-package-json-license 🚩 ✔️ 1.0.0
ts-package-json-main-is-cjs 🚩 ✔️ 1.1.0
ts-package-json-module 🚩 ✔️ 1.1.0
ts-package-json-name 🚩 1.0.0
ts-package-json-repo 🚩 ✔️ 1.0.0
ts-package-json-required-scripts 🚩 1.0.0
ts-package-json-sdktype 🚩 3.1.0
ts-package-json-sideeffects 🚩 ✔️ 1.0.0
ts-package-json-types 🚩 1.1.0
ts-pagination-list 🚩 1.2.0
ts-use-interface-parameters ⚠️ 1.1.0
ts-use-promises 🚩 1.1.0
ts-versioning-semver 🚩 1.1.0