From 66f305ab07aa63286805641c9e35c4f1dd39d49b Mon Sep 17 00:00:00 2001 From: Tyler Butler Date: Tue, 17 May 2022 16:58:14 -0700 Subject: [PATCH] Enable prefer-includes eslint rule and pre-apply fixes (#10272) From the documentation on the rule: Until ES5, we were using String#indexOf method to check whether a string contains an arbitrary substring or not. Until ES2015, we were using Array#indexOf method to check whether an array contains an arbitrary value or not. ES2015 has added String#includes and ES2016 has added Array#includes. It makes code more understandable if we use those includes methods for the purpose. --- common/build/eslint-config-fluid/minimal.js | 1 + common/build/eslint-config-fluid/printed-configs/default.json | 3 +++ common/build/eslint-config-fluid/printed-configs/test.json | 3 +++ .../PropertyDDS/packages/property-changeset/.eslintrc.js | 2 ++ .../packages/property-common/src/datastructures/collection.ts | 2 +- .../packages/property-common/src/error_objects/httpError.ts | 2 +- .../packages/property-inspector-table/src/NameCell.tsx | 2 +- .../packages/property-inspector-table/src/NewDataForm.tsx | 2 +- .../src/PropertyDataCreationHandlers.ts | 2 +- .../PropertyDDS/packages/property-properties/.eslintrc.js | 1 + .../property-properties/src/propertyTemplateWrapper.js | 2 +- experimental/PropertyDDS/packages/property-proxy/.eslintrc.js | 2 +- experimental/dds/tree/src/Forest.ts | 2 +- packages/drivers/odsp-driver/src/odspUtils.ts | 2 +- packages/loader/driver-utils/src/blobAggregationStorage.ts | 2 +- packages/runtime/container-runtime/src/dataStoreContext.ts | 2 +- packages/test/test-service-load/src/utils.ts | 2 +- packages/utils/telemetry-utils/src/test/errorLogging.spec.ts | 2 +- 18 files changed, 23 insertions(+), 13 deletions(-) diff --git a/common/build/eslint-config-fluid/minimal.js b/common/build/eslint-config-fluid/minimal.js index f80b2c8b7f3b..fe681699bb4c 100644 --- a/common/build/eslint-config-fluid/minimal.js +++ b/common/build/eslint-config-fluid/minimal.js @@ -189,6 +189,7 @@ module.exports = { // This rule ensures that our Intellisense looks good by verifying the TSDoc syntax. "tsdoc/syntax": "error", + "@typescript-eslint/prefer-includes": "error", "@typescript-eslint/prefer-optional-chain": "error", }, "overrides": [ diff --git a/common/build/eslint-config-fluid/printed-configs/default.json b/common/build/eslint-config-fluid/printed-configs/default.json index 3ee1bea67781..7f86273372cf 100644 --- a/common/build/eslint-config-fluid/printed-configs/default.json +++ b/common/build/eslint-config-fluid/printed-configs/default.json @@ -266,6 +266,9 @@ "@typescript-eslint/prefer-function-type": [ "error" ], + "@typescript-eslint/prefer-includes": [ + "error" + ], "@typescript-eslint/prefer-namespace-keyword": [ "error" ], diff --git a/common/build/eslint-config-fluid/printed-configs/test.json b/common/build/eslint-config-fluid/printed-configs/test.json index 96717b89c03a..7299cdceabdf 100644 --- a/common/build/eslint-config-fluid/printed-configs/test.json +++ b/common/build/eslint-config-fluid/printed-configs/test.json @@ -266,6 +266,9 @@ "@typescript-eslint/prefer-function-type": [ "error" ], + "@typescript-eslint/prefer-includes": [ + "error" + ], "@typescript-eslint/prefer-namespace-keyword": [ "error" ], diff --git a/experimental/PropertyDDS/packages/property-changeset/.eslintrc.js b/experimental/PropertyDDS/packages/property-changeset/.eslintrc.js index e51edc6050f9..081089b7e254 100644 --- a/experimental/PropertyDDS/packages/property-changeset/.eslintrc.js +++ b/experimental/PropertyDDS/packages/property-changeset/.eslintrc.js @@ -11,6 +11,7 @@ module.exports = { "project": ["./tsconfig.json", "./src/test/tsconfig.json"] }, "rules": { + // Many rules are disabled in PropertyDDS projects. See https://github.com/microsoft/FluidFramework/pull/10272 "@typescript-eslint/ban-ts-comment": "off", "@typescript-eslint/ban-types": "off", "@typescript-eslint/consistent-type-definitions": "off", @@ -27,6 +28,7 @@ module.exports = { "@typescript-eslint/no-unused-expressions": "off", "@typescript-eslint/no-var-requires": "off", "@typescript-eslint/prefer-for-of": "off", + "@typescript-eslint/prefer-includes": "off", "@typescript-eslint/prefer-optional-chain": "off", "@typescript-eslint/quotes": "off", "@typescript-eslint/restrict-plus-operands": "off", diff --git a/experimental/PropertyDDS/packages/property-common/src/datastructures/collection.ts b/experimental/PropertyDDS/packages/property-common/src/datastructures/collection.ts index a9af8c9fde64..0f6578937eeb 100644 --- a/experimental/PropertyDDS/packages/property-common/src/datastructures/collection.ts +++ b/experimental/PropertyDDS/packages/property-common/src/datastructures/collection.ts @@ -175,7 +175,7 @@ export class Collection { if (_.isArray(in_filterKey)) { filterCb = function(in_key, in_item) { - if (in_filterKey.indexOf(in_key) >= 0) { + if (in_filterKey.includes(in_key)) { rtn.add(in_key, in_item); } }; diff --git a/experimental/PropertyDDS/packages/property-common/src/error_objects/httpError.ts b/experimental/PropertyDDS/packages/property-common/src/error_objects/httpError.ts index 0dafaf224d17..0ba1f7346fc8 100644 --- a/experimental/PropertyDDS/packages/property-common/src/error_objects/httpError.ts +++ b/experimental/PropertyDDS/packages/property-common/src/error_objects/httpError.ts @@ -60,7 +60,7 @@ export class HTTPError extends Error { const isFirefox = typeof window !== "undefined" && typeof window.navigator !== "undefined" && typeof window.navigator.userAgent !== "undefined" && - window.navigator.userAgent.toLowerCase().indexOf("firefox") > -1; + window.navigator.userAgent.toLowerCase().includes("firefox"); return isFirefox ? `${this.message}, stack:${stack}` : `stack:${stack}`; } diff --git a/experimental/PropertyDDS/packages/property-inspector-table/src/NameCell.tsx b/experimental/PropertyDDS/packages/property-inspector-table/src/NameCell.tsx index e2302b85506e..8a016e53ef62 100644 --- a/experimental/PropertyDDS/packages/property-inspector-table/src/NameCell.tsx +++ b/experimental/PropertyDDS/packages/property-inspector-table/src/NameCell.tsx @@ -85,7 +85,7 @@ const copyHandler = (rowData: IInspectorRow, ref: React.MutableRefObject { if (typeof (parent as NodeProperty).getDynamicIds === "function") { const dynamicIds = (parent as NodeProperty).getDynamicIds(); - if (dynamicIds.indexOf(rowName) > -1) { + if (dynamicIds.includes(rowName)) { return false; } } else if (parent.getContext() !== "single") { diff --git a/experimental/PropertyDDS/packages/property-inspector-table/src/NewDataForm.tsx b/experimental/PropertyDDS/packages/property-inspector-table/src/NewDataForm.tsx index d11bc8d8052b..a0a090bc0830 100644 --- a/experimental/PropertyDDS/packages/property-inspector-table/src/NewDataForm.tsx +++ b/experimental/PropertyDDS/packages/property-inspector-table/src/NewDataForm.tsx @@ -243,7 +243,7 @@ export const NewDataForm: React.FunctionComponent = (props) = ); - const isSiblingFound = siblingIds.indexOf(inputName) >= 0; + const isSiblingFound = siblingIds.includes(inputName); const createBtn = (