Skip to content

Commit

Permalink
Updated eslint to match with react-sdk-componenets
Browse files Browse the repository at this point in the history
  • Loading branch information
tumms2021389 committed Jan 13, 2024
1 parent 119a0a7 commit 8b303ca
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 117 deletions.
101 changes: 10 additions & 91 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,90 +47,19 @@
"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",
"jsx-a11y/click-events-have-key-events": "off",
"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": [
{
Expand Down Expand Up @@ -185,8 +105,7 @@
},
{
"files": "*.@(js|jsx|ts|tsx|mdx)",
"rules": {
}
"rules": {}
},
{
"files": ".storybook/*.js",
Expand Down
26 changes: 11 additions & 15 deletions src/samples/Embedded/EmbeddedTopLevel/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
<StoreContext.Provider value={{store: PCore.getStore(), displayOnlyFA: true}} >
// eslint-disable-next-line react/jsx-no-constructed-context-values
return <StoreContext.Provider value={{store: PCore.getStore(), displayOnlyFA: true}} >
<ThemeProvider theme={theme}>
<CssBaseline />
{thePConnObj}
</ThemeProvider>
</StoreContext.Provider>;

return theComp;

}


Expand Down Expand Up @@ -349,9 +345,9 @@ export default function EmbeddedTopLevel() {

// Initial render of component passed in (which should be a RootContainer)
render(
<React.Fragment>
<>
{theComponent}
</React.Fragment>,
</>,
target
)

Expand All @@ -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`);
Expand Down Expand Up @@ -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');
});
Expand All @@ -501,12 +497,12 @@ export default function EmbeddedTopLevel() {
});

return (
<React.Fragment>
<>
{theBanner}
<div className={classes.embedShoppingOptions}>
{theOptions}
</div>
</React.Fragment>
</>
)
}

Expand Down Expand Up @@ -553,7 +549,7 @@ export default function EmbeddedTopLevel() {
<div>
<div className={classes.pegaPartInfo} id="pega-part-of-page">
<div className={classes.pegaPartPega}>
<div id="pega-root"></div>
<div id="pega-root" />
<br />
<div className={classes.pegaPartText}> * - required fields</div>
</div>
Expand Down
18 changes: 7 additions & 11 deletions src/samples/FullPortal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function useQuery() {
export default function FullPortal() {
const [portalSelectionScreen, setPortalSelectionScreen] = useState(false);
const [defaultPortalName, setDefaultPortalName] = useState('');
const [availablePortals, setAvailablePortals] = useState<Array<string>>([]);
const [availablePortals, setAvailablePortals] = useState<string[]>([]);

const history = useHistory();
const query = useQuery();
Expand Down Expand Up @@ -62,17 +62,13 @@ export default function FullPortal() {
// const thePConnObj = <div>the RootComponent</div>;
const thePConnObj = <PegaConnectObj {...props} />;

const theComp = (
// eslint-disable-next-line react/jsx-no-constructed-context-values
<StoreContext.Provider value={{ store: PCore.getStore() }}>
// eslint-disable-next-line react/jsx-no-constructed-context-values
return <StoreContext.Provider value={{ store: PCore.getStore() }}>
<ThemeProvider theme={theme}>
<CssBaseline />
{thePConnObj}
</ThemeProvider>
</StoreContext.Provider>
);

return theComp;
</StoreContext.Provider>;
}

/**
Expand Down Expand Up @@ -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`);
Expand Down Expand Up @@ -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<string>);
setAvailablePortals(portals as string[]);
});
}
}
Expand Down Expand Up @@ -204,7 +200,7 @@ export default function FullPortal() {
/>
) : (
<div>
<div id='pega-root'></div>
<div id='pega-root' />
</div>
);
}

0 comments on commit 8b303ca

Please sign in to comment.