Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sonarlint): code smells and security reviews #303

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { html } from 'lit-html';

import mdx from './bq-notification.mdx';

import { getRandomFromArray } from '../../../shared/utils';
import { NOTIFICATION_TYPE } from '../bq-notification.types';

const meta: Meta = {
Expand Down Expand Up @@ -132,9 +133,7 @@ export const Warning: Story = {
export const Stacked: Story = {
render: (args: Args) => {
const onButtonClick = () => {
const getRandom = (arr: string[]) => arr[Math.floor(Math.random() * arr.length)];
const type = getRandom(NOTIFICATION_TYPE as unknown as string[]);

const [type] = getRandomFromArray(NOTIFICATION_TYPE as unknown as string[], 1);
const notification = Object.assign(document.createElement('bq-notification'), {
type,
autoDismiss: args['auto-dismiss'],
Expand Down
2 changes: 1 addition & 1 deletion packages/bee-q/src/shared/test-utils/computedStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const computedStyle = <T extends keyof CSSStyleDeclaration>(
throw new Error(`Could not find element ${lightDomSelector}`);
}

if (!!shadowDomSelector) {
if (shadowDomSelector) {
element = element.shadowRoot.querySelector(shadowDomSelector);

if (!element) {
Expand Down
12 changes: 6 additions & 6 deletions packages/bee-q/src/shared/utils/getRandom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
* @param {Number} n - The number of random items to take
* @returns {Array} An array with the number of random items specified
*/
export const getRandomFromArray = (arr: Array<unknown>, n: number): Array<unknown> => {
let len = arr.length;
export const getRandomFromArray = <T>(arr: T[], n: number): T[] => {
let length = arr.length;
const result = new Array(n);
const taken = new Array(len);
const taken = new Array(length);

if (n > len) throw new RangeError('getRandom: more elements taken than available');
if (n > length) throw new RangeError('getRandom: more elements taken than available');

while (n--) {
const x = Math.floor(Math.random() * len);
const x = Date.now() % length;
result[n] = arr[x in taken ? taken[x] : x];
taken[x] = --len in taken ? taken[len] : len;
taken[x] = --length in taken ? taken[length] : length;
}
return result;
};
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sonar.organization=endava
sonar.projectKey=Endava_bee-q

sonar.cpd.exclusions=packages/bee-q/src/components/*.tsx
sonar.cpd.exclusions=packages/bee-q/src/components/*.ts,packages/bee-q/src/components/*.tsx
sonar.test.inclusions=**/*.spec.*
sonar.testExecutionReportPaths=packages/bee-q/test-report.xml
sonar.javascript.lcov.reportPaths=packages/bee-q/coverage/lcov.info