Skip to content

Commit 8791102

Browse files
committed
refactor: update Image component and format feature helper for consistency
1 parent fa936aa commit 8791102

4 files changed

Lines changed: 19 additions & 13 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
],
2424
"lint-staged": {
2525
"./src/**/*.(ts|tsx|js|jsx)": [
26-
"eslint --fix -c .eslintrc.cjs --ext .tsx,.ts,.jsx,.js"
26+
"eslint --fix -c eslint.config.js --ext .tsx,.ts,.jsx,.js"
2727
]
2828
},
2929
"author": "MobileTeleSystems",

src/components/Image.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
/* eslint-disable react/jsx-no-bind */
2+
/* eslint-disable react/destructuring-assignment */
3+
/* eslint-disable react/sort-comp */
4+
15
// For Next.js 13 and react 18. Switch component for support server components later.
26
"use client";
37

4-
import {Component} from "react";
8+
import React, {Component, JSX} from "react";
59
import {getFormatFeatures} from "../helpers/get-format-features.js";
610

711
export interface IImageOptions extends React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement> {
@@ -14,7 +18,7 @@ export interface IImageOptions extends React.DetailedHTMLProps<React.ImgHTMLAttr
1418

1519
export class Image<P extends IImageOptions> extends Component<P> {
1620

17-
public static isShowDiagnostic: boolean = false;
21+
public static isShowDiagnostic = false;
1822

1923
public static controlPoints: number[] = [160, 320, 640, 1280, 1920];
2024

@@ -27,7 +31,7 @@ export class Image<P extends IImageOptions> extends Component<P> {
2731
* Example:
2832
* Image.isUseSourceUrl = process.env.NODE_ENV !== "production";
2933
*/
30-
public static isUseSourceUrl: boolean = false;
34+
public static isUseSourceUrl = false;
3135

3236
/**
3337
* Image optimizer will change origin to other domain.
@@ -47,25 +51,25 @@ export class Image<P extends IImageOptions> extends Component<P> {
4751

4852
private static isWebP: boolean | null = null;
4953

50-
public resultUrl: string = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
54+
public resultUrl = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
5155

52-
public resizeCheckTimeout: number = 0;
56+
public resizeCheckTimeout = 0;
5357

5458
public thisComponent: HTMLImageElement | null = null;
5559

56-
protected sourceUrl: string = "";
60+
protected sourceUrl = "";
5761

5862
protected readonly extensionsRegexp: RegExp = /\.\w+$/u;
5963

6064
protected readonly windowResizeHandler: EventListenerOrEventListenerObject;
6165

62-
protected lastOptimalSize: number = 0;
66+
protected lastOptimalSize = 0;
6367

6468
/**
6569
* Serves to prevent recursion when resizing images to determine the optimal size.
6670
* This recursion can be caught with poor layout that does not take into account the scaling of images.
6771
*/
68-
protected checks: number = 0;
72+
protected checks = 0;
6973

7074
public constructor (props: P) {
7175
super(props);
@@ -112,7 +116,7 @@ export class Image<P extends IImageOptions> extends Component<P> {
112116
);
113117
}
114118

115-
protected async checkImage (isResize: boolean = false): Promise<void> {
119+
protected async checkImage (isResize = false): Promise<void> {
116120
if (this.checks > 1) {
117121
return;
118122
}
@@ -151,7 +155,7 @@ export class Image<P extends IImageOptions> extends Component<P> {
151155
}
152156

153157
protected getContainerSize (): number {
154-
let containerSize: number = 0;
158+
let containerSize = 0;
155159

156160
let element: HTMLElement | null = this.thisComponent;
157161

@@ -207,6 +211,7 @@ export class Image<P extends IImageOptions> extends Component<P> {
207211
}
208212

209213
protected extractImageFormat (path: string): string {
214+
// eslint-disable-next-line no-useless-assignment
210215
let format = "";
211216

212217
const match: RegExpExecArray | null = this.extensionsRegexp.exec(path);
@@ -267,6 +272,7 @@ export class Image<P extends IImageOptions> extends Component<P> {
267272
}
268273
}
269274

275+
// eslint-disable-next-line class-methods-use-this
270276
protected async initImageFormats (): Promise<void> {
271277
const format = await getFormatFeatures();
272278

src/helpers/get-format-features.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {checkAvifFeature} from "./check-avif-feature.js";
33
import {checkWebpFeature} from "./check-webp-feature.js";
44

5-
// eslint-disable-next-line @typescript-eslint/no-type-alias
5+
66
type FormatType = "avif" | "webp" | null;
77

88
const promisesPool: ((value: FormatType) => void)[] = [];

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"strict": true,
88
"skipLibCheck": true,
99
"declaration": true,
10-
"jsx": "react-jsx",
10+
"jsx": "react",
1111
"outDir": "./dist/",
1212
},
1313
"include": [

0 commit comments

Comments
 (0)