Skip to content

Commit b01ef97

Browse files
authored
feat: apply basic airbnb-base eslint rules (#490)
### Description Of Changes Applies [UIKIT-3632](https://sendbird.atlassian.net/browse/UIKIT-3632) 5 simple eslint rules are applied as a first step - forced to use double quotes -> single quote - removed redundant spaces - added trailing commas - fixed wrong indentation - removed duplicated imports \w eslint-config-airbnb-base plugin (bundle size info 👉🏻 https://bundlephobia.com/package/[email protected]) and disabled other rules for now but will enable one-by-one and create a PR for each.
1 parent e35ed49 commit b01ef97

File tree

165 files changed

+668
-588
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+668
-588
lines changed

.eslintrc.json

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"root": true,
3+
"env": {
4+
"browser": true,
5+
"es6": true,
6+
"jest": true
7+
},
38
"parser": "@typescript-eslint/parser",
49
"parserOptions": {
510
"ecmaVersion": 2020,
@@ -11,18 +16,85 @@
1116
"settings": {
1217
"react": {
1318
"version": "detect"
19+
},
20+
"import/resolver": {
21+
"node": {
22+
"extensions": [
23+
".js",
24+
".jsx",
25+
".ts",
26+
".tsx"
27+
]
28+
}
1429
}
1530
},
1631
"rules": {
1732
"no-unused-expressions": "off",
1833
"@typescript-eslint/ban-ts-comment": "off",
1934
"@typescript-eslint/no-explicit-any": "off",
2035
"@typescript-eslint/no-unused-expressions": "error",
21-
"react/display-name": "off"
36+
"react/display-name": "off",
37+
"import/extensions": "off",
38+
// TODO(Ahyoung): uncomment below after find a way not to get an error \w type.d.ts
39+
// "import/extensions": [
40+
// "warn",
41+
// "ignorePackages",
42+
// {
43+
// "js": "never",
44+
// "jsx": "never",
45+
// "ts": "never",
46+
// "tsx": "never"
47+
// }
48+
// ],
49+
// TODO(Ahyoung): fix and remove one by one
50+
"no-floating-decimal": "off",
51+
"no-shadow": "off",
52+
"no-useless-return": "off",
53+
"no-else-return": "off",
54+
"no-param-reassign": "off",
55+
"no-useless-escape": "off",
56+
"no-underscore-dangle": "off",
57+
"no-confusing-arrow": "off",
58+
"no-mixed-operators": "off",
59+
"no-nested-ternary": "off",
60+
"no-unneeded-ternary": "off",
61+
"no-use-before-define": "off",
62+
"no-cond-assign": "off",
63+
"no-plusplus": "off",
64+
"no-bitwise": "off",
65+
"no-restricted-syntax": "off",
66+
"no-prototype-builtins": "off",
67+
"import/no-unresolved": "off",
68+
"import/no-extraneous-dependencies": "off",
69+
"import/no-useless-path-segments": "off",
70+
"import/prefer-default-export": "off",
71+
"import/order": "off",
72+
"import/no-named-as-default-member": "off",
73+
"object-curly-newline": "off",
74+
"object-shorthand": "off",
75+
"consistent-return": "off",
76+
"max-len": "off",
77+
"arrow-body-style": "off",
78+
"function-paren-newline": "off",
79+
"prefer-template": "off",
80+
"semi": "off",
81+
"padded-blocks": "off",
82+
"arrow-parens": "off",
83+
"dot-notation": "off",
84+
"camelcase": "off",
85+
"radix": "off",
86+
"prefer-destructuring": "off",
87+
"default-case": "off",
88+
"curly": "off",
89+
"yoda": "off",
90+
"brace-style": "off",
91+
"nonblock-statement-body-position": "off",
92+
"func-names": "off"
2293
},
2394
"extends": [
2495
"plugin:react/recommended",
25-
"plugin:@typescript-eslint/recommended"
96+
"plugin:@typescript-eslint/recommended",
97+
"airbnb-base"
2698
],
2799
"plugins": [
28100
"react",

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
"storybook": "start-storybook -p 6006",
4747
"build-storybook": "build-storybook",
4848
"lint": "yarn run eslint; yarn run eslint-ts",
49-
"eslint": "eslint --no-eslintrc -c .eslintrc.js 'src/**'",
50-
"eslint-ts": "eslint --no-eslintrc -c .eslintrc.json './src/**/*.ts*'",
49+
"lint:fix": "yarn run eslint --fix; yarn run eslint-ts --fix",
50+
"eslint": "eslint --no-eslintrc -c .eslintrc.js 'src/**'",
51+
"eslint-ts": "eslint --no-eslintrc -c .eslintrc.json 'src/**/*.ts*'",
5152
"stylelint": "stylelint 'src/**'",
5253
"generate-component": "plop",
5354
"deploy-storybook": "storybook-to-ghpages",
@@ -111,8 +112,9 @@
111112
"dts-bundle-generator": "^6.5.0",
112113
"eslint": "^6.8.0",
113114
"eslint-config-airbnb": "^18.0.1",
115+
"eslint-config-airbnb-base": "^14.0.0",
114116
"eslint-plugin-babel": "^5.3.1",
115-
"eslint-plugin-import": "^2.20.0",
117+
"eslint-plugin-import": "^2.25.2",
116118
"eslint-plugin-jsx-a11y": "^6.2.3",
117119
"eslint-plugin-react": "^7.18.0",
118120
"eslint-plugin-react-hooks": "^1.7.0",

src/hooks/VoicePlayer/dux/actionTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ObjectValues } from "../../../utils/typeHelpers/objectValues";
1+
import { ObjectValues } from '../../../utils/typeHelpers/objectValues';
22

33
export const actionTypes = {
44
INITIALIZE_AUDIO_UNIT: 'INITIALIZE_AUDIO_UNIT',

src/hooks/VoicePlayer/dux/reducer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import {
44
ON_VOICE_PLAYER_PAUSE,
55
ON_VOICE_PLAYER_PLAY,
66
SET_CURRENT_PLAYER,
7-
} from "./actionTypes";
7+
} from './actionTypes';
88
import {
99
AudioStorageUnit,
1010
AudioUnitDefaultValue,
1111
VoicePlayerInitialState,
1212
VoicePlayerStatus,
13-
} from "./initialState";
13+
} from './initialState';
1414

1515
type InitializeAudioUnitPayload = { groupKey: string };
1616
type SetCurrentPlayerPayload = { audioPlayer: HTMLAudioElement, groupKey: string };

src/hooks/VoicePlayer/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface VoicePlayerContext {
3737
voicePlayerStore: VoicePlayerInitialState;
3838
}
3939

40-
const noop = () => {/* noop */ };
40+
const noop = () => { /* noop */ };
4141
const VoicePlayerStoreDefaultValue = {
4242
currentGroupKey: '',
4343
currentPlayer: null,

src/hooks/VoicePlayer/useVoicePlayer.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { useEffect, useState } from "react";
2-
import { useVoicePlayerContext } from ".";
3-
import { VOICE_PLAYER_AUDIO_ID } from "../../utils/consts";
4-
import { useVoiceRecorderContext } from "../VoiceRecorder";
1+
import { useEffect, useState } from 'react';
2+
import { useVoicePlayerContext } from '.';
3+
import { VOICE_PLAYER_AUDIO_ID } from '../../utils/consts';
4+
import { useVoiceRecorderContext } from '../VoiceRecorder';
55

6-
import { AudioUnitDefaultValue, VoicePlayerStatus } from "./dux/initialState";
7-
import { generateGroupKey } from "./utils";
6+
import { AudioUnitDefaultValue, VoicePlayerStatus } from './dux/initialState';
7+
import { generateGroupKey } from './utils';
88

99
export interface UseVoicePlayerProps {
1010
key: string;

src/hooks/VoiceRecorder/WebAudioUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Thanks to https://codesandbox.io/s/media-recorder-api-downsampling-16k-mp3-encode-using-lame-js-forked-n1pblw
2-
import { WavHeader, Mp3Encoder } from "../../_externals/lamejs/lame.all.js";
2+
import { WavHeader, Mp3Encoder } from '../../_externals/lamejs/lame.all';
33

44
function encodeMp3(arrayBuffer: ArrayBuffer): WavHeader {
55
const wav = WavHeader.readHeader(new DataView(arrayBuffer));
@@ -37,7 +37,7 @@ function encodeMp3(arrayBuffer: ArrayBuffer): WavHeader {
3737

3838
// Convert audioFile to arrayBuffer, because Mp3Encoder requires a parameter of ArrayBuffer type
3939
function downsampleToWav(file: File, callback: (buffer: ArrayBuffer) => void): void {
40-
//Browser compatibility
40+
// Browser compatibility
4141
// https://caniuse.com/?search=AudioContext
4242
const audioCtx = new AudioContext();
4343
const fileReader = new FileReader();
@@ -68,6 +68,7 @@ function downsampleToWav(file: File, callback: (buffer: ArrayBuffer) => void): v
6868
offlineAudioCtx
6969
.startRendering()
7070
.then(renderCompleteHandler)
71+
// eslint-disable-next-line no-console
7172
.catch((err) => console.warn(err));
7273
}
7374
};

src/hooks/VoiceRecorder/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface VoiceRecorderContext {
2424
stop: () => void,
2525
isRecordable: boolean;
2626
}
27-
const noop = () => {/* noop */ };
27+
const noop = () => { /* noop */ };
2828
const VoiceRecorderContext = createContext<VoiceRecorderContext>({
2929
start: noop,
3030
stop: noop,
@@ -52,7 +52,7 @@ export const VoiceRecorderProvider = (props: VoiceRecorderProps): React.ReactEle
5252
mimeType: VOICE_RECORDER_MIME_TYPE,
5353
audioBitsPerSecond: VOICE_RECORDER_AUDIO_BITS,
5454
});
55-
mediaRecorder.ondataavailable = (e) => {// when recording stops
55+
mediaRecorder.ondataavailable = (e) => { // when recording stops
5656
logger.info('VoiceRecorder: Succeeded getting an available data.', e.data);
5757
const audioFile = new File([e.data], VOICE_MESSAGE_FILE_NAME, {
5858
lastModified: new Date().getTime(),

src/hooks/VoiceRecorder/useVoiceRecorder.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface UseVoiceRecorderContext {
2525
recordingStatus: VoiceRecorderStatus;
2626
}
2727

28-
const noop = () => {/* noop */};
28+
const noop = () => { /* noop */ };
2929

3030
export const useVoiceRecorder = ({
3131
onRecordingStarted = noop,

src/hooks/useLongPress.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ interface UseLongPressType<T> {
6161
onTouchEnd: (e: React.TouchEvent<T>) => void;
6262
}
6363

64-
export default function useLongPress<T> ({
64+
export default function useLongPress<T>({
6565
onLongPress,
6666
onClick,
6767
}: PressHandlers<T>, {
@@ -117,7 +117,7 @@ export default function useLongPress<T> ({
117117
if (shouldPreventDefault && target.current) {
118118
target.current.removeEventListener('touchend', preventDefault);
119119
}
120-
},[shouldPreventDefault, onClick, longPressTriggered, dragTriggered]);
120+
}, [shouldPreventDefault, onClick, longPressTriggered, dragTriggered]);
121121

122122
return {
123123
onMouseDown: (e: React.MouseEvent<T>) => start(e),

0 commit comments

Comments
 (0)