Skip to content

Commit

Permalink
refactor: adjust by the eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
oct16 committed Aug 13, 2020
1 parent d0a47ee commit ed5b766
Show file tree
Hide file tree
Showing 23 changed files with 94 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
@@ -0,0 +1,2 @@
dist
node_modules
36 changes: 35 additions & 1 deletion .eslintrc
@@ -1,4 +1,5 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
Expand All @@ -9,5 +10,38 @@
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
"rules": {}
"rules": {
"@typescript-eslint/ban-types": [
"off"
],
"@typescript-eslint/no-empty-function": [
"off"
],
"@typescript-eslint/no-this-alias": [
"error",
{
"allowDestructuring": true, // Allow `const { props, state } = this`; false by default
"allowedNames": [
"self",
"context"
] // Allow `const self = this`; `[]` by default
}
],
"@typescript-eslint/no-explicit-any": [
"off"
// "error",
// {
// "ignoreRestArgs": true
// }
],
"prefer-rest-params": [
"off"
],
"@typescript-eslint/no-non-null-assertion": [
"off"
],
"@typescript-eslint/explicit-module-boundary-types": [
"off"
]
}
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 9 additions & 12 deletions package.json
Expand Up @@ -31,7 +31,7 @@
"doc": "npx typedoc",
"embed": "cp packages/timecat/dist/timecatjs.min.js ../TimeCatChrome/src/assets/",
"count": "find ./packages -type f -not -path **/*.spec.ts -not -path **/global.* -not -path './node_modules/*' -not -path '**/dist/*' -name '*.ts' | xargs wc -l",
"lint": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix"
"lint": "eslint 'packages/**/*.{js,ts}' --quiet --fix"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.8.9",
Expand All @@ -46,7 +46,6 @@
"@types/node": "^13.9.2",
"@types/pako": "^1.0.1",
"@types/smoothscroll-polyfill": "^0.3.1",
"@types/socket.io-client": "^1.4.32",
"@zerollup/ts-transform-paths": "^1.7.17",
"diff": "^4.0.2",
"execa": "^4.0.0",
Expand All @@ -65,11 +64,16 @@
"rollup-plugin-typescript2": "^0.26.0",
"rollup-plugin-visualizer": "^4.0.4",
"smoothscroll-polyfill": "^0.4.4",
"socket.io": "^2.3.0",
"ts-jest": "^26.1.0",
"ttypescript": "^1.5.10",
"typedoc": "^0.17.7",
"typescript": "^4.0.0-beta"
"typescript": "^3.9.7",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"eslint": "^7.6.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"prettier": "^2.0.5"
},
"repository": {
"type": "git",
Expand All @@ -82,12 +86,5 @@
"files": [
"lib"
],
"dependencies": {
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"eslint": "^7.6.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"prettier": "^2.0.5"
}
"dependencies": {}
}
4 changes: 2 additions & 2 deletions packages/player/src/dom.ts
Expand Up @@ -97,7 +97,7 @@ export async function updateDom(this: PlayerComponent, Record: RecordData) {

case RecordType.SCROLL: {
const { top, left, id } = data as ScrollWatcherData
let target = id ? (nodeStore.getNode(id) as HTMLElement) : this.c.sandBoxDoc.documentElement
const target = id ? (nodeStore.getNode(id) as HTMLElement) : this.c.sandBoxDoc.documentElement

const curTop = target.scrollTop

Expand Down Expand Up @@ -274,7 +274,7 @@ export async function updateDom(this: PlayerComponent, Record: RecordData) {
if (src) {
const image = new Image()
image.src = src
image.onload = function(this: HTMLImageElement) {
image.onload = function (this: HTMLImageElement) {
ctx.drawImage(this, 0, 0)
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/player/src/keyboard.ts
Expand Up @@ -35,7 +35,7 @@ export class KeyboardComponent {
this.detectWindowIsActive()
}

dispatchPlay(speed: number = 0) {
dispatchPlay(speed = 0) {
reduxStore.dispatch({
type: PlayerTypes.SPEED,
data: {
Expand Down
8 changes: 1 addition & 7 deletions packages/player/src/player.ts
Expand Up @@ -90,13 +90,7 @@ export class PlayerComponent {
}

if (this.audioData.src) {
this.audioBlobUrl =
location.href
.split('/')
.slice(0, -1)
.join('/') +
'/' +
this.audioData.src
this.audioBlobUrl = location.href.split('/').slice(0, -1).join('/') + '/' + this.audioData.src
} else {
const bufferStrList = this.audioData.bufferStrList
if (!bufferStrList.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/record/src/audio/audio-recorder.ts
Expand Up @@ -37,7 +37,7 @@ export class Recorder {

this.mediaNode = this.audioContext.createMediaStreamSource(this.mediaStream)

let createScript = this.audioContext.createScriptProcessor
const createScript = this.audioContext.createScriptProcessor

this.processNode = createScript.call(this.audioContext, 4096, this.opts.channelCount, this.opts.channelCount)

Expand Down
6 changes: 3 additions & 3 deletions packages/record/src/watchers/canvas.ts
Expand Up @@ -40,7 +40,7 @@ export class CanvasWatcher extends Watcher<CanvasRecord> {
const id = self.getNodeId(this.canvas)!

return typeof method === 'function'
? function() {
? function () {
const args = [...arguments]
if (name === 'drawImage') {
args[0] = id
Expand All @@ -51,7 +51,7 @@ export class CanvasWatcher extends Watcher<CanvasRecord> {
}
: null
},
set: function(value: any) {
set: function (value: any) {
const id = self.getNodeId(this.canvas)!
self.aggregateDataEmitter(id, name, value)

Expand Down Expand Up @@ -82,7 +82,7 @@ export class CanvasWatcher extends Watcher<CanvasRecord> {

const blockInstances = [CanvasGradient]

return function(this: any, id: number, prop: Prop, args: any) {
return function (this: any, id: number, prop: Prop, args: any) {
const context = this

function emitData(id: number) {
Expand Down
2 changes: 1 addition & 1 deletion packages/record/src/watchers/dom.ts
Expand Up @@ -128,7 +128,7 @@ export class DOMWatcher extends Watcher<DOMRecord> {

const isParentSVG = parentVn && parentVn.extra.isSVG

let vn = addedSiblingMap.get(node)!
const vn = addedSiblingMap.get(node)!

if (isParentSVG && isVNode(vn)) {
;(vn as VNode).extra.isSVG = true
Expand Down
6 changes: 3 additions & 3 deletions packages/record/src/watchers/form-element.ts
Expand Up @@ -37,9 +37,9 @@ export class FormElementWatcher extends Watcher<FormElementRecord> {
const inputType = target.getAttribute('type') || 'text'

let key = 'value'
let value: any = target.value || ''
const value: any = target.value || ''
let newValue: any = ''
let patches: ReturnType<typeof getStrDiffPatches> = []
const patches: ReturnType<typeof getStrDiffPatches> = []

if (inputType === 'checkbox' || inputType === 'radio') {
if (eventType === 'input') {
Expand Down Expand Up @@ -115,7 +115,7 @@ export class FormElementWatcher extends Watcher<FormElementRecord> {
const [target, key] = item
const original = context.Object.getOwnPropertyDescriptor(target, key)
context.Object.defineProperty(target, key, {
set: function(value: string | boolean) {
set: function (value: string | boolean) {
setTimeout(() => {
handleEvent.call(this, key, value)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/record/src/watchers/location.ts
Expand Up @@ -27,7 +27,7 @@ export class LocationWatcher extends Watcher<LocationRecord> {
kidnapLocation(type: 'pushState' | 'replaceState') {
const original = this.context.history[type]

return function(this: any) {
return function (this: any) {
const e = new Event(type)
e.arguments = arguments
this.context.dispatchEvent(e)
Expand Down
2 changes: 1 addition & 1 deletion packages/share/src/index.ts
Expand Up @@ -118,7 +118,7 @@ export interface DOMRecord {
data: DOMWatcherData
time: string
}
export interface DOMWatcherData extends DOMUpdateDataType {}
export type DOMWatcherData = DOMUpdateDataType

export interface AttributesUpdateData {
id: number
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/src/redux/create-store.ts
Expand Up @@ -57,13 +57,13 @@ export function createStore(reducer: Reducer, initState: States = {}) {
function getState(): StateMap

function getState<T extends keyof StateMap>(name?: T): StateMap[T]

function getState<T extends keyof StateMap>(name?: T) {
const s = state as StateMap
if (name) {
return s[name] as StateMap[T]
}
return s
return s
}

function getTypeInTopics(type: TopicName): TopicName | undefined {
Expand All @@ -72,7 +72,7 @@ export function createStore(reducer: Reducer, initState: States = {}) {
progress: Object.keys(ProgressTypes)
}

for (let [key, enums] of Object.entries(topics)) {
for (const [key, enums] of Object.entries(topics)) {
if (enums.includes(type)) {
return key as TopicName
}
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/redux/reducers/player.ts
@@ -1,4 +1,4 @@
let initState = {
const initState = {
speed: 0
}

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/tools/dom.ts
Expand Up @@ -76,7 +76,7 @@ export function completeAttrHref(str: string, node?: Element) {
const doc = node.getRootNode() as Document
const context = doc.defaultView as Window

let { href, path } = context?.__ReplayLocation__ || {}
const { href, path } = context?.__ReplayLocation__ || {}

if (path && href) {
const relationHref = new URL(path, href)
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/tools/output.ts
Expand Up @@ -112,7 +112,7 @@ async function initOptions(html: Document, exportOptions: ExportOptions) {

async function injectScripts(html: Document, scripts?: ScriptItem[]) {
if (scripts) {
for (let scriptItem of scripts) {
for (const scriptItem of scripts) {
const { src, name } = scriptItem
let scriptContent = src
const script = document.createElement('script')
Expand Down Expand Up @@ -193,7 +193,7 @@ async function injectData(html: Document, exportOptions: ExportOptions) {
const jsonStrData = JSON.stringify(extractedData)

const zipArray = pako.gzip(jsonStrData)
let outputStr: string = ''
let outputStr = ''

for (let i = 0; i < zipArray.length; i++) {
let num = zipArray[i]
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/tools/scroll.ts
Expand Up @@ -22,7 +22,7 @@ export function disableScrolling(target: Document) {
'test' as any,
() => {},
Object.defineProperty({}, 'passive', {
get: function() {
get: function () {
supportsPassive = true
}
})
Expand Down
12 changes: 6 additions & 6 deletions packages/utils/src/tools/tool.ts
Expand Up @@ -37,10 +37,10 @@ export function objectEquals(x: any, y: any): boolean {
// recursive object equality check
const p = Object.keys(x)
return (
Object.keys(y).every(function(i) {
Object.keys(y).every(function (i) {
return p.indexOf(i) !== -1
}) &&
p.every(function(i) {
p.every(function (i) {
return objectEquals(x[i], y[i])
})
)
Expand All @@ -57,13 +57,13 @@ export function throttle(
let timeout: any = null
let previous = 0

const later = function() {
const later = function () {
previous = options.leading === false ? 0 : Date.now()
timeout = null
result = func.apply(context, args)
if (!timeout) context = args = null
}
return function(this: any) {
return function (this: any) {
const now = Date.now()
if (!previous && options.leading === false) previous = now
const remaining = wait - (now - previous)
Expand Down Expand Up @@ -99,10 +99,10 @@ export function debounce<F extends Procedure>(
): (this: ThisParameterType<F>, ...args: Parameters<F>) => void {
let timeoutId: ReturnType<typeof setTimeout> | undefined

return function(this: ThisParameterType<F>, ...args: Parameters<F>) {
return function (this: ThisParameterType<F>, ...args: Parameters<F>) {
const context = this

const doLater = function() {
const doLater = function () {
timeoutId = undefined
if (!options.isImmediate) {
func.apply(context, args)
Expand Down

0 comments on commit ed5b766

Please sign in to comment.