Skip to content

Latest commit

 

History

History

eslint-plugin-azure-sdk

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-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-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