Skip to content

Commit 8da663d

Browse files
committed
lint
1 parent 03135e1 commit 8da663d

8 files changed

Lines changed: 46 additions & 36 deletions

File tree

example/react-entry.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ ReactDOM.render(
3232
<PictureSmart requireImages={differentBreakpoints} alt="Image with different breakpoints" />
3333

3434
<h3>Image without resize</h3>
35-
<PictureSmart
36-
requireImages={imageWithoutResize}
37-
alt="Image without resize"
38-
/>
35+
<PictureSmart requireImages={imageWithoutResize} alt="Image without resize" />
3936

4037
<h2>As background css</h2>
4138

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { getCompressionRatio } from '../index';
22

3-
43
test('Pixel ratios 1x', () => {
5-
expect(
6-
getCompressionRatio(['1x']),
7-
).toStrictEqual({"1x": 0});
4+
expect(getCompressionRatio(['1x'])).toStrictEqual({ '1x': 0 });
85
});
96

107
test('Pixel ratios 1x, 2x', () => {
11-
expect(
12-
getCompressionRatio(['1x','2x']),
13-
).toStrictEqual({"1x": 0.5, "2x": 0});
8+
expect(getCompressionRatio(['1x', '2x'])).toStrictEqual({ '1x': 0.5, '2x': 0 });
149
});
1510

1611
test('Pixel ratios 1x, 2x, 3x', () => {
17-
expect(
18-
getCompressionRatio(['1x','2x', '3x']),
19-
).toStrictEqual({"1x": 0.3333333333333333, "2x": 0.6666666666666666, "3x": 0});
12+
expect(getCompressionRatio(['1x', '2x', '3x'])).toStrictEqual({
13+
'1x': 0.3333333333333333,
14+
'2x': 0.6666666666666666,
15+
'3x': 0,
16+
});
2017
});
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import { getOriginalExtensionSrcSet } from '../index';
22

3-
43
test('Pixel ratios 1x, path "/images/mayImages.png"', () => {
5-
expect(
6-
getOriginalExtensionSrcSet(['1x'],'/images/mayImages.png'),
7-
).toStrictEqual({"1x": '/images/mayImages.png'});
4+
expect(getOriginalExtensionSrcSet(['1x'], '/images/mayImages.png')).toStrictEqual({
5+
'1x': '/images/mayImages.png',
6+
});
87
});
98

109
test('Pixel ratios 1x, 2x, path "/images/mayImages.png"', () => {
11-
expect(
12-
getOriginalExtensionSrcSet(['1x','2x'],'/images/mayImages.png'),
13-
).toStrictEqual({"1x": '/images/mayImages.png', "2x": '/images/mayImages.png'});
10+
expect(getOriginalExtensionSrcSet(['1x', '2x'], '/images/mayImages.png')).toStrictEqual({
11+
'1x': '/images/mayImages.png',
12+
'2x': '/images/mayImages.png',
13+
});
1414
});
1515

1616
test('Pixel ratios 1x, 2x, 3x, path "/images/mayImages.png"', () => {
17-
expect(
18-
getOriginalExtensionSrcSet(['1x','2x','3x'],'/images/mayImages.png'),
19-
).toStrictEqual({"1x": '/images/mayImages.png', "2x": '/images/mayImages.png', "3x": '/images/mayImages.png'});
17+
expect(getOriginalExtensionSrcSet(['1x', '2x', '3x'], '/images/mayImages.png')).toStrictEqual({
18+
'1x': '/images/mayImages.png',
19+
'2x': '/images/mayImages.png',
20+
'3x': '/images/mayImages.png',
21+
});
2022
});

src/utils/backgroundCss.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,31 @@ const srcSetCss = (selector: string, sources: ExtensionSrcSet[]): string => {
1717
(acc, source) => {
1818
const finalSelector = getSelector(selector, source.extension);
1919
acc['1x'].push(`${finalSelector} { background-image: url(${source.srcSet['1x']}); }`);
20-
source.srcSet['2x'] && acc['2x'].push(`${finalSelector} { background-image: url(${source.srcSet['2x']}); }`);
21-
source.srcSet['3x'] && acc['3x'].push(`${finalSelector} { background-image: url(${source.srcSet['3x']}); }`);
20+
source.srcSet['2x'] &&
21+
acc['2x'].push(`${finalSelector} { background-image: url(${source.srcSet['2x']}); }`);
22+
source.srcSet['3x'] &&
23+
acc['3x'].push(`${finalSelector} { background-image: url(${source.srcSet['3x']}); }`);
2224
return acc;
2325
},
2426
{ '1x': [], '2x': [], '3x': [] },
2527
);
2628

2729
return `
2830
${result['1x'].join(' ')}
29-
${result['2x'].length ? `@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) { ${result['2x'].join(' ')} }`:''}
30-
${result['3x'].length ? ` @media (-webkit-min-device-pixel-ratio: 3), (min-resolution: 288dpi) { ${result['3x'].join(' ')} }`:''}
31+
${
32+
result['2x'].length
33+
? `@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) { ${result['2x'].join(
34+
' ',
35+
)} }`
36+
: ''
37+
}
38+
${
39+
result['3x'].length
40+
? ` @media (-webkit-min-device-pixel-ratio: 3), (min-resolution: 288dpi) { ${result[
41+
'3x'
42+
].join(' ')} }`
43+
: ''
44+
}
3145
`;
3246
};
3347

src/utils/getOriginal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BreakpointSource } from '../types';
22

3-
export const getOriginal = (source: BreakpointSource) => {
3+
export const getOriginal = (source: BreakpointSource): string => {
44
const srcSet = source.srcSets[source.srcSets.length - 1].srcSet;
55

66
return srcSet['3x'] || srcSet['2x'] || srcSet['1x'];
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { SrcSet, Dpr } from '../types';
22

3-
export const getOriginalExtensionSrcSet = (pixelRatios: Dpr[], outputImagePath:string):SrcSet => {
4-
return pixelRatios.reduce((acc, item ) => {
5-
acc[item] = outputImagePath;
3+
export const getOriginalExtensionSrcSet = (pixelRatios: Dpr[], outputImagePath: string): SrcSet => {
4+
return pixelRatios.reduce((acc, item) => {
5+
acc[item] = outputImagePath;
66
return acc;
77
}, {} as SrcSet);
8-
}
8+
};

src/webpack/loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const loader = function (this: webpack.loader.LoaderContext, source: stri
7676
srcSets: [
7777
{
7878
extension: originalExtension,
79-
srcSet: getOriginalExtensionSrcSet(pixelRatios,outputImagePath),
79+
srcSet: getOriginalExtensionSrcSet(pixelRatios, outputImagePath),
8080
},
8181
],
8282
};

src/webpack/loaderOptionsSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export const schema: JSONSchema7 = {
5050
},
5151
originalPixelRatio: {
5252
type: 'string',
53-
pattern: "^(1x|2x|3x)$",
53+
pattern: '^(1x|2x|3x)$',
5454
},
5555
},
56-
required: ['breakpoints', 'imgproxy','originalPixelRatio'],
56+
required: ['breakpoints', 'imgproxy', 'originalPixelRatio'],
5757
additionalProperties: false,
5858
};

0 commit comments

Comments
 (0)