Skip to content

Commit

Permalink
chore: set printWidth to 120 (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tenth-crew authored Jun 2, 2024
1 parent 6ae3577 commit cf26c04
Show file tree
Hide file tree
Showing 65 changed files with 238 additions and 978 deletions.
45 changes: 5 additions & 40 deletions .github/hypertrons.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@
"name": "kind/CICD",
"description": "CI/CD related issue or pull",
"color": "0099ff",
"keywords": [
"continuous integration",
"continuous delivery",
"[ci]",
"[cd]",
"[ci/cd]"
]
"keywords": ["continuous integration", "continuous delivery", "[ci]", "[cd]", "[ci/cd]"]
}
]
},
Expand All @@ -65,48 +59,19 @@
{
"name": "committer",
"description": "Committer of the project",
"users": [
"frank-zsy",
"heming6666",
"LiuChangFreeman",
"tyn1998",
"zhuxiangning",
"wxharry",
"lhbvvvvv"
],
"commands": [
"/difficulty",
"/rerun",
"/complete-checklist",
"/start-vote"
]
"users": ["frank-zsy", "heming6666", "LiuChangFreeman", "tyn1998", "zhuxiangning", "wxharry", "lhbvvvvv"],
"commands": ["/difficulty", "/rerun", "/complete-checklist", "/start-vote"]
},
{
"name": "replier",
"description": "Replier is responsible for reply issues in time",
"users": [
"heming6666",
"LiuChangFreeman",
"xiaoya-Esther",
"tyn1998",
"zhuxiangning",
"wxharry",
"lhbvvvvv"
],
"users": ["heming6666", "LiuChangFreeman", "xiaoya-Esther", "tyn1998", "zhuxiangning", "wxharry", "lhbvvvvv"],
"commands": []
},
{
"name": "approver",
"description": "After approvers' approve, pulls should be merged automatically",
"users": [
"frank-zsy",
"heming6666",
"LiuChangFreeman",
"tyn1998",
"zhuxiangning",
"wxharry",
"lhbvvvvv"
],
"users": ["frank-zsy", "heming6666", "LiuChangFreeman", "tyn1998", "zhuxiangning", "wxharry", "lhbvvvvv"],
"commands": ["/approve"]
},
{
Expand Down
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"printWidth": 120,
"singleQuote": true,
"trailingComma": "es5",
"requirePragma": false,
Expand Down
12 changes: 2 additions & 10 deletions src/api/common.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { OSS_XLAB_ENDPOINT, ErrorCode } from '../constant';
import request from '../helpers/request';

export const getMetricByName = async (
owner: string,
metricNameMap: Map<string, string>,
metric: string
) => {
export const getMetricByName = async (owner: string, metricNameMap: Map<string, string>, metric: string) => {
try {
return await request(
`${OSS_XLAB_ENDPOINT}/open_digger/github/${owner}/${metricNameMap.get(
metric
)}.json`
);
return await request(`${OSS_XLAB_ENDPOINT}/open_digger/github/${owner}/${metricNameMap.get(metric)}.json`);
} catch (error) {
// the catched error being "404" means the metric file is not available so return a null
if (error === ErrorCode.NOT_FOUND) {
Expand Down
15 changes: 2 additions & 13 deletions src/components/Bars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,11 @@ interface BarsProps {
}

const Bars = (props: BarsProps): JSX.Element => {
const {
theme,
height,
legend1,
legend2,
yName1,
yName2,
data1,
data2,
onClick,
} = props;
const { theme, height, legend1, legend2, yName1, yName2, data1, data2, onClick } = props;
const startTime = Number(data1[0][0].split('-')[0]);
const endTime = Number(data1[data1.length - 1][0].split('-')[0]);
const timeLength = endTime - startTime;
const minInterval =
timeLength > 2 ? 365 * 24 * 3600 * 1000 : 30 * 3600 * 24 * 1000;
const minInterval = timeLength > 2 ? 365 * 24 * 3600 * 1000 : 30 * 3600 * 24 * 1000;
const divEL = useRef(null);

const TH = theme == 'light' ? LIGHT_THEME : DARK_THEME;
Expand Down
5 changes: 1 addition & 4 deletions src/components/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ interface GraphProps {

const NODE_SIZE = [10, 25];

const generateEchartsData = (
data: any,
focusedNodeID: string | undefined
): any => {
const generateEchartsData = (data: any, focusedNodeID: string | undefined): any => {
const generateNodes = (nodes: any[]): any => {
const values: number[] = nodes.map((item) => item[1]);
const minMax = [Math.min(...values), Math.max(...values)];
Expand Down
14 changes: 2 additions & 12 deletions src/components/TooltipTrigger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@ const TooltipTrigger: React.FC<ITooltipTriggerProps> = ({
tooltipFontColor = '#242A2E',
content,
}) => (
<Tooltip
placement="top"
title={<span style={{ color: tooltipFontColor }}>{content}</span>}
color={tooltipBackground}
>
<svg
className="tooltip-icon"
width={`${size}px`}
height={`${size}px`}
viewBox="0 0 48 48"
version="1.1"
>
<Tooltip placement="top" title={<span style={{ color: tooltipFontColor }}>{content}</span>} color={tooltipBackground}>
<svg className="tooltip-icon" width={`${size}px`} height={`${size}px`} viewBox="0 0 48 48" version="1.1">
<path fill={iconColor} d={iconTooltipTrigger}></path>
</svg>
</Tooltip>
Expand Down
3 changes: 1 addition & 2 deletions src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export enum ErrorCode {

export const OSS_XLAB_ENDPOINT = 'https://oss.x-lab.info';

export const HYPERTRONS_CRX_NEW_ISSUE =
'https://github.com/hypertrons/hypertrons-crx/issues/new/choose';
export const HYPERTRONS_CRX_NEW_ISSUE = 'https://github.com/hypertrons/hypertrons-crx/issues/new/choose';

export const HYPERCRX_GITHUB = 'https://github.com/hypertrons/hypertrons-crx';
28 changes: 5 additions & 23 deletions src/feature-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import exists from './helpers/exists';
import waitFor from './helpers/wait-for';
import sleep from './helpers/sleep';
import isRestorationVisit from './helpers/is-restoration-visit';
import shouldFeatureRun, {
ShouldRunConditions,
} from './helpers/should-feature-run';
import shouldFeatureRun, { ShouldRunConditions } from './helpers/should-feature-run';
import optionsStorage from './options-storage';
import { throttle } from 'lodash-es';

Expand Down Expand Up @@ -88,10 +86,7 @@ const globalReady = new Promise<object>(async (resolve) => {
resolve(options);
});

const setupPageLoad = async (
id: FeatureId,
config: InternalRunConfig
): Promise<void> => {
const setupPageLoad = async (id: FeatureId, config: InternalRunConfig): Promise<void> => {
const { asLongAs, include, exclude, init } = config;

if (!(await shouldFeatureRun({ asLongAs, include, exclude }))) {
Expand Down Expand Up @@ -138,27 +133,14 @@ const add = async (

for (const loader of loaders) {
// Input defaults and validation
const {
asLongAs,
include,
exclude,
init,
restore,
awaitDomReady = true,
} = loader;
const { asLongAs, include, exclude, init, restore, awaitDomReady = true } = loader;

if (include?.length === 0) {
throw new Error(
`${id}: \`include\` cannot be an empty array, it means "run nowhere"`
);
throw new Error(`${id}: \`include\` cannot be an empty array, it means "run nowhere"`);
}

// 404 pages should only run 404-only features
if (
pageDetect.is404() &&
!include?.includes(pageDetect.is404) &&
!asLongAs?.includes(pageDetect.is404)
) {
if (pageDetect.is404() && !include?.includes(pageDetect.is404) && !asLongAs?.includes(pageDetect.is404)) {
continue;
}

Expand Down
11 changes: 3 additions & 8 deletions src/helpers/generate-data-by-month.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const generateDataByMonth = (originalData: any, updatedAt?: number) => {
// `originalData` is an object with keys like `2020-01`, `2020-02`, `2022`, `2022-Q1`, `all`.
// A normal month is a key like `2020-01`(yyyy-mm). They are the keys we handle later in this function.
// An unnormal month is a key like `2020`, `2020-Q1`, `all`. They are not used in any feature yet.
const normalMonths = Object.keys(originalData).filter((key) =>
isNormalMonth(key)
);
const normalMonths = Object.keys(originalData).filter((key) => isNormalMonth(key));
const orderedMonths = normalMonths.sort((a, b) => {
const dateA = new Date(a);
const dateB = new Date(b);
Expand All @@ -33,16 +31,13 @@ const generateDataByMonth = (originalData: any, updatedAt?: number) => {

const oldestMonth = orderedMonths[0];
const newestMonth =
lastDataAvailableMonth.getFullYear() +
'-' +
(lastDataAvailableMonth.getMonth() + 1).toString().padStart(2, '0');
lastDataAvailableMonth.getFullYear() + '-' + (lastDataAvailableMonth.getMonth() + 1).toString().padStart(2, '0');
// insert no-event months (assigned to 0) and generate final data
const arrayData: [string, number][] = [];
const start = new Date(oldestMonth);
const end = new Date(newestMonth);
for (let i = start; i <= end; i.setMonth(i.getMonth() + 1)) {
const date =
i.getFullYear() + '-' + (i.getMonth() + 1).toString().padStart(2, '0');
const date = i.getFullYear() + '-' + (i.getMonth() + 1).toString().padStart(2, '0');
if (!originalData.hasOwnProperty(date)) {
arrayData.push([date, 0]);
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/helpers/get-developer-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ export function getDeveloperName() {
}

export async function isDeveloperWithMeta() {
return (
pageDetect.isUserProfile() && (await metaStore.has(getDeveloperName()))
);
return pageDetect.isUserProfile() && (await metaStore.has(getDeveloperName()));
}

export function checkLogined() {
Expand Down
6 changes: 1 addition & 5 deletions src/helpers/linear-map.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export default function linearMap(
val: number,
domain: number[],
range: number[]
): number {
export default function linearMap(val: number, domain: number[], range: number[]): number {
const d0 = domain[0];
const d1 = domain[1];
const r0 = range[0];
Expand Down
16 changes: 4 additions & 12 deletions src/helpers/should-feature-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ export type ShouldRunConditions = {
exclude: ((() => boolean) | (() => Promise<boolean>))[] | undefined;
};

export default async function shouldFeatureRun(
props: ShouldRunConditions
): Promise<boolean> {
export default async function shouldFeatureRun(props: ShouldRunConditions): Promise<boolean> {
const {
/** Every condition must be true */
asLongAs = [() => true],
Expand All @@ -16,14 +14,8 @@ export default async function shouldFeatureRun(
exclude = [() => false],
} = props;
return (
(await Promise.all(asLongAs.map((c) => c())).then((flags) =>
flags.every((flag) => flag === true)
)) &&
(await Promise.all(include.map((c) => c())).then((flags) =>
flags.some((flag) => flag === true)
)) &&
(await Promise.all(exclude.map((c) => c())).then((flags) =>
flags.every((flag) => flag === false)
))
(await Promise.all(asLongAs.map((c) => c())).then((flags) => flags.every((flag) => flag === true))) &&
(await Promise.all(include.map((c) => c())).then((flags) => flags.some((flag) => flag === true))) &&
(await Promise.all(exclude.map((c) => c())).then((flags) => flags.every((flag) => flag === false)))
);
}
5 changes: 1 addition & 4 deletions src/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@
"status": "Data does not exist",
"measure": {
"text": "Possible causes:",
"tips": [
"Recently created, has not been computed",
"No actions in selected period, nothing to be computed"
]
"tips": ["Recently created, has not been computed", "No actions in selected period, nothing to be computed"]
}
}
},
Expand Down
5 changes: 1 addition & 4 deletions src/locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@
"status": "对应数据不存在",
"measure": {
"text": "这可能是因为:",
"tips": [
"该对象为最近创建对象,数据还未被计算",
"该对象在此周期内无任何有效活动,不予计算"
]
"tips": ["该对象为最近创建对象,数据还未被计算", "该对象在此周期内无任何有效活动,不予计算"]
}
}
},
Expand Down
4 changes: 1 addition & 3 deletions src/options-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ export const defaults = Object.assign(
{
locale: 'en',
},
Object.fromEntries(
importedFeatures.map((name) => [`hypercrx-${name}` as FeatureId, true])
)
Object.fromEntries(importedFeatures.map((name) => [`hypercrx-${name}` as FeatureId, true]))
);

class OptionsStorage {
Expand Down
25 changes: 4 additions & 21 deletions src/pages/ContentScripts/components/NativePopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,10 @@ interface NativePopoverProps extends PropsWithChildren<any> {
anchor: JQuery<HTMLElement>;
width: number;
// for now, only support top-middle
arrowPosition:
| 'top-left'
| 'top-middle'
| 'top-right'
| 'bottom-left'
| 'bottom-middle'
| 'bottom-right';
arrowPosition: 'top-left' | 'top-middle' | 'top-right' | 'bottom-left' | 'bottom-middle' | 'bottom-right';
}

export const NativePopover = ({
anchor,
width,
arrowPosition,
children,
}: NativePopoverProps): JSX.Element => {
export const NativePopover = ({ anchor, width, arrowPosition, children }: NativePopoverProps): JSX.Element => {
useEffect(() => {
(async () => {
await elementReady('div.Popover');
Expand All @@ -44,14 +33,8 @@ export const NativePopover = ({
$popoverContent.css('padding', '10px 5px');
$popoverContent.css('width', width);
$popoverContainer.css('top', `${top + anchorHeight + 10}px`);
$popoverContainer.css(
'left',
`${left - (width - anchorWidth) / 2}px`
);
$popoverContent.attr(
'class',
`Popover-message Box color-shadow-large Popover-message--${arrowPosition}`
);
$popoverContainer.css('left', `${left - (width - anchorWidth) / 2}px`);
$popoverContent.attr('class', `Popover-message Box color-shadow-large Popover-message--${arrowPosition}`);
render(children, $popoverContent[0]);
$popoverContainer.css('display', 'block');
}, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { render, Container } from 'react-dom';
import $ from 'jquery';

import features from '../../../../feature-manager';
import {
getDeveloperName,
isDeveloperWithMeta,
} from '../../../../helpers/get-developer-info';
import { getDeveloperName, isDeveloperWithMeta } from '../../../../helpers/get-developer-info';
import { getActivity, getOpenrank } from '../../../../api/developer';
import { UserMeta, metaStore } from '../../../../api/common';
import View from './view';
Expand All @@ -24,10 +21,7 @@ const getData = async () => {
};

const renderTo = (container: Container) => {
render(
<View activity={activity} openrank={openrank} meta={meta} />,
container
);
render(<View activity={activity} openrank={openrank} meta={meta} />, container);
};

const init = async (): Promise<void> => {
Expand Down
Loading

0 comments on commit cf26c04

Please sign in to comment.