Skip to content

Commit

Permalink
fix/clean up: fix lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
xpadev-net committed Sep 18, 2022
1 parent a92097f commit 6466979
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/inputParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,20 @@ const fromLegacy = (data: rawApiResponse[]): formattedComment[] => {
* @return {formattedComment[]}
*/
const fromLegacyOwner = (data: string): formattedComment[] => {
let data_: formattedComment[] = [],
const data_: formattedComment[] = [],
comments = data.split("\n");
for (let i = 0; i < comments.length; i++) {
let commentData = comments[i]!.split(":");
const value = comments[i];
if (!value) continue;
const commentData = value.split(":");
if (commentData.length < 3) {
continue;
} else if (commentData.length > 3) {
for (let j = 3; j < commentData.length; j++) {
commentData[2] += ":" + commentData[j];
commentData[2] += `:${commentData[j]}`;
}
}
let tmpParam: formattedComment = {
const tmpParam: formattedComment = {
id: i,
vpos: Number(commentData[0]),
content: commentData[2] || "",
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ class NiconiComments {
width_arr.push(measure.width);
}
const width = width_arr.reduce((p, c) => p + c, 0) / width_arr.length;
let width_max = Math.max(...width_arr),
width_min = Math.min(...width_arr),
let width_max = Math.max(...width_arr);
const width_min = Math.min(...width_arr),
height =
comment.fontSize *
comment.lineHeight *
Expand Down Expand Up @@ -893,7 +893,7 @@ class NiconiComments {
* @param vpos - 動画の現在位置の100倍 ニコニコから吐き出されるコメントの位置情報は主にこれ
* @param forceRendering
*/
drawCanvas(vpos: number, forceRendering: boolean = false) {
drawCanvas(vpos: number, forceRendering = false) {
const drawCanvasStart = performance.now();
if (this.lastVpos === vpos && !forceRendering) return;
this.lastVpos = vpos;
Expand Down
22 changes: 17 additions & 5 deletions src/typeGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const typeGuard = {
config: {
initOptions: (item: unknown): item is InitOptions => {
if (typeof item !== "object" || !item) return false;
const keys: { [key: string]: Function } = {
const keys: { [key: string]: (i: unknown) => boolean } = {
useLegacy: isBoolean,
formatted: isBoolean,
showCollision: isBoolean,
Expand All @@ -227,16 +227,19 @@ const typeGuard = {
config: typeGuard.config.config,
format: (i: unknown) =>
typeof i === "string" &&
i.match(
!!i.match(
/^(niconicome|formatted|legacy|legacyOwner|owner|v1|default)$/
),
video: (i: unknown) =>
typeof i === "object" && (i as HTMLVideoElement).nodeName === "VIDEO",
};
for (const key in keys) {
console.log(keys[key]);
if (
(item as { [key: string]: unknown })[key] !== undefined &&
!(keys[key] as Function)((item as { [key: string]: unknown })[key])
!(keys[key] as (i: unknown) => boolean)(
(item as { [key: string]: unknown })[key]
)
) {
console.warn(
`[Incorrect input] var: initOptions, key: ${key}, value: ${
Expand Down Expand Up @@ -288,7 +291,7 @@ const typeGuard = {
) === 0
);
};
const keys: { [key: string]: Function } = {
const keys: { [key: string]: (i: unknown) => boolean } = {
commentYPaddingTop: isNumber,
commentYMarginBottom: isNumber,
fpsInterval: isNumber,
Expand All @@ -301,6 +304,11 @@ const typeGuard = {
sameCARange: isNumber,
sameCAGap: isNumber,
sameCAMinScore: isNumber,
contextStrokeOpacity: isNumber,
contextFillLiveOpacity: isNumber,
contextLineWidth: isNumber,
contextStrokeColor: isString,
contextStrokeInversionColor: isString,
colors: (i: unknown) =>
typeof i === "object" &&
Object.keys(i as { [key: string]: unknown }).reduce(
Expand All @@ -325,9 +333,12 @@ const typeGuard = {
) === 0,
};
for (const key in item) {
console.log(key, item, keys);
if (
(item as { [key: string]: unknown })[key] !== undefined &&
!(keys[key] as Function)((item as { [key: string]: unknown })[key])
!(keys[key] as (i: unknown) => boolean)(
(item as { [key: string]: unknown })[key]
)
) {
console.warn(
`[Incorrect input] var: initOptions, key: ${key}, value: ${
Expand All @@ -348,6 +359,7 @@ const typeGuard = {
};
const isBoolean = (i: unknown): i is boolean => typeof i === "boolean";
const isNumber = (i: unknown): i is number => typeof i === "number";
const isString = (i: unknown): i is string => typeof i === "string";
const isStringKeyObject = (i: unknown): i is { [key: string]: unknown } =>
typeof i === "object";

Expand Down

0 comments on commit 6466979

Please sign in to comment.