Skip to content

Commit

Permalink
fix(sonarlint): code smells and security reviews (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgonzalezr committed Jul 3, 2023
1 parent 00fd221 commit 7862ba6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
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

0 comments on commit 7862ba6

Please sign in to comment.