From 8b303cafa0a407d1be6858645122d50fa8ec2f6b Mon Sep 17 00:00:00 2001 From: tumms2021389 Date: Sat, 13 Jan 2024 21:44:22 +0530 Subject: [PATCH] Updated eslint to match with react-sdk-componenets --- .eslintrc.json | 101 ++---------------- .../Embedded/EmbeddedTopLevel/index.tsx | 26 ++--- src/samples/FullPortal/index.tsx | 18 ++-- 3 files changed, 28 insertions(+), 117 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index c696185f7..14157cc38 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -19,27 +19,18 @@ "version": "detect" } }, - "ignorePatterns": ["node_modules", "packages/*/lib", "!.storybook", ".storybook/public"], + "ignorePatterns": ["node_modules", "packages/*/lib", "!.storybook", ".storybook/public", "**/**/*.json"], "rules": { + // Note: the "0" means to allow it. 1 = warning, 2 = error + "react/jsx-filename-extension": [0, { "extensions": [".jsx", "*.tsx"] }], // Prettier recommends running separately from a linter. // https://prettier.io/docs/en/integrating-with-linters.html#notes "prettier/prettier": "off", // Disable rules from shared configs we're not ready for yet. - "sonarjs/cognitive-complexity": "off", - "sonarjs/no-identical-functions": "off", + "sonarjs/cognitive-complexity": ["warn", 20], "sonarjs/no-duplicate-string": "off", - "sonarjs/no-nested-template-literals": "off", - - // - // JA - Override some default lint handling here - "@typescript-eslint/array-type": ["error", { "default": "generic" }], - // "import/extensions": ["warn", "never"], // Turning off for now (see below) - - // Note: the "0" means to allow it. 1 = warning, 2 = error - // allowing this lets index.tsx files pass linting even though they only have an export (and no JSX) - "react/jsx-filename-extension": [0, { "extensions": [".js", ".jsx", "*.ts", "*.tsx"] }], // // Initial release: turning these off; phase in to "warn" or "error" over time @@ -56,9 +47,8 @@ "import/no-useless-path-segments": "off", "import/order": "off", - "no-else-return": "off", - "no-restricted-syntax": "off", - "no-underscore-dangle": "off", + "no-underscore-dangle": "off", // TODO : adhere to standard naming + "no-restricted-syntax": "warn", // TODO : fix for-in loops "jsx-a11y/alt-text": "off", "jsx-a11y/anchor-is-valid": "off", @@ -66,80 +56,10 @@ "jsx-a11y/label-has-associated-control": "off", "jsx-a11y/no-static-element-interactions": "off", - "react/jsx-fragments": "off", - "react/jsx-no-bind": "off", - "react/self-closing-comp": "off", - - "sonarjs/prefer-immediate-return": "off", - - "@typescript-eslint/dot-notation": "off", // prefer warn but needs different parserOptions - "@typescript-eslint/naming-convention": "off", // prefer warn but needs different parserOptions - "@typescript-eslint/ban-types": "off", // also, see override below - - // - // Initial release: set to error - "@typescript-eslint/no-inferrable-types": "error", - "eqeqeq": "error", - "no-alert": "error", - "no-console": "error", - "no-fallthrough": "error", - "no-undef": "warn", - "no-unused-vars": "error", - "no-var": "error", - "prefer-const": "error", - "yoda": "error", - - "import/no-mutable-exports": "error", - "sonarjs/max-switch-cases": "error", - "sonarjs/no-collapsible-if": "error", - "sonarjs/no-all-duplicated-branches": "error", - "sonarjs/no-duplicated-branches": "error", - "sonarjs/no-gratuitous-expressions": "error", - "sonarjs/no-ignored-return": "error", - "sonarjs/no-small-switch": "error", - "sonarjs/prefer-object-literal": "error", - "sonarjs/prefer-single-boolean-return": "error", - "@typescript-eslint/no-shadow": "error", - "react/default-props-match-prop-types": "error", - "react/no-unescaped-entities": "error", - "react/no-unused-prop-types": "error", - "react/static-property-placement": "error", - "array-callback-return": "error", - "camelcase": "error", - "default-case": "error", - "func-names": "error", - "no-case-declarations": "error", - "no-lonely-if": "error", - "no-nested-ternary": "error", - "no-plusplus": "error", - "no-restricted-globals": "error", - "no-restricted-properties": "error", - "no-shadow": "error", - "radix": "error", - "spaced-comment": "error", - - "import/newline-after-import": "error", - "sonarjs/no-nested-switch": "error", - "@typescript-eslint/no-array-constructor": "error", - "@typescript-eslint/no-empty-function": "error", - "@typescript-eslint/no-unused-vars": "error", - "@typescript-eslint/no-useless-constructor": "error", - "react/button-has-type": "error", - "react/jsx-curly-brace-presence": "error", - "react/jsx-boolean-value": "error", - "react/no-array-index-key": "error", - "class-methods-use-this": "error", - "guard-for-in": "error", - "no-unneeded-ternary": "error", - "no-unused-expressions": "error", - "operator-assignment": "error", - "prefer-template": "error", - "vars-on-top": "error", - - "no-use-before-define": "off", // doc for @typescript-eslint/no-use-before-define says to turn off the base implementation - "@typescript-eslint/no-use-before-define": "error", - "import/no-relative-packages": "warn" // arnab + "@typescript-eslint/naming-convention": "off", // prefer warn but needs different parserOptions + "@typescript-eslint/ban-types": "off", // also, see override below + "import/no-relative-packages": "off" // arnab }, "overrides": [ { @@ -185,8 +105,7 @@ }, { "files": "*.@(js|jsx|ts|tsx|mdx)", - "rules": { - } + "rules": {} }, { "files": ".storybook/*.js", diff --git a/src/samples/Embedded/EmbeddedTopLevel/index.tsx b/src/samples/Embedded/EmbeddedTopLevel/index.tsx index 092e119ad..711e0ffa1 100644 --- a/src/samples/Embedded/EmbeddedTopLevel/index.tsx +++ b/src/samples/Embedded/EmbeddedTopLevel/index.tsx @@ -1,6 +1,5 @@ /* eslint-disable react/button-has-type */ -// @ts-nocheck - TypeScript type checking to be added soon -import React, { useState, useEffect } from 'react'; +import { useState, useEffect } from 'react'; import { render } from "react-dom"; import Typography from '@material-ui/core/Typography'; import CssBaseline from '@material-ui/core/CssBaseline'; @@ -284,17 +283,14 @@ export default function EmbeddedTopLevel() { // VRS: Attempted to remove displayOnlyFA but it presently handles various components which // SDK does not yet support, so all those need to be fixed up before it can be removed. To // be done in a future sprint. - const theComp = - // eslint-disable-next-line react/jsx-no-constructed-context-values - + // eslint-disable-next-line react/jsx-no-constructed-context-values + return {thePConnObj} ; - return theComp; - } @@ -349,9 +345,9 @@ export default function EmbeddedTopLevel() { // Initial render of component passed in (which should be a RootContainer) render( - + <> {theComponent} - , + , target ) @@ -377,7 +373,7 @@ export default function EmbeddedTopLevel() { setShowAppName(true); // Initialize the SdkComponentMap (local and pega-provided) - // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars + // eslint-disable-next-line @typescript-eslint/no-unused-vars getSdkComponentMap(localSdkComponentMap).then( (theComponentMap: any) => { // eslint-disable-next-line no-console console.log(`SdkComponentMap initialized`); @@ -471,14 +467,14 @@ export default function EmbeddedTopLevel() { mashupCaseType = caseTypes[0].pyWorkTypeImplementationClassName; } - const options = { + const options: any = { pageName: 'pyEmbedAssignment', startingFields: mashupCaseType === "DIXL-MediaCo-Work-NewService" ? { Package: sLevel } : {} }; - PCore.getMashupApi().createCase(mashupCaseType, PCore.getConstants().APP.APP, options).then(() => { + (PCore.getMashupApi().createCase(mashupCaseType, PCore.getConstants().APP.APP, options) as any).then(() => { // eslint-disable-next-line no-console console.log('createCase rendering is complete'); }); @@ -501,12 +497,12 @@ export default function EmbeddedTopLevel() { }); return ( - + <> {theBanner}
{theOptions}
-
+ ) } @@ -553,7 +549,7 @@ export default function EmbeddedTopLevel() {
-
+

* - required fields
diff --git a/src/samples/FullPortal/index.tsx b/src/samples/FullPortal/index.tsx index 41e110f5f..c5ff1a7b1 100644 --- a/src/samples/FullPortal/index.tsx +++ b/src/samples/FullPortal/index.tsx @@ -24,7 +24,7 @@ function useQuery() { export default function FullPortal() { const [portalSelectionScreen, setPortalSelectionScreen] = useState(false); const [defaultPortalName, setDefaultPortalName] = useState(''); - const [availablePortals, setAvailablePortals] = useState>([]); + const [availablePortals, setAvailablePortals] = useState([]); const history = useHistory(); const query = useQuery(); @@ -62,17 +62,13 @@ export default function FullPortal() { // const thePConnObj =
the RootComponent
; const thePConnObj = ; - const theComp = ( - // eslint-disable-next-line react/jsx-no-constructed-context-values - + // eslint-disable-next-line react/jsx-no-constructed-context-values + return {thePConnObj} - - ); - - return theComp; + ; } /** @@ -134,7 +130,7 @@ export default function FullPortal() { compareSdkPCoreVersions(); // Initialize the SdkComponentMap (local and pega-provided) - // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars + // eslint-disable-next-line @typescript-eslint/no-unused-vars getSdkComponentMap(localSdkComponentMap).then((theComponentMap: any) => { // eslint-disable-next-line no-console console.log(`SdkComponentMap initialized`); @@ -169,7 +165,7 @@ export default function FullPortal() { setDefaultPortalName(defaultPortal); // Getting current user's access group's available portals list other than excluded portals (relies on Traditional DX APIs) getAvailablePortals().then((portals) => { - setAvailablePortals(portals as Array); + setAvailablePortals(portals as string[]); }); } } @@ -204,7 +200,7 @@ export default function FullPortal() { /> ) : (
-
+
); }