Skip to content

Commit

Permalink
style: ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
josejefferson committed Jan 9, 2025
1 parent c695349 commit eab9751
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@josejefferson/eslint-config-typescript"]
}
7 changes: 6 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ util
*.py
*.min.*
lib/**/*
src/js
src/js
build
bin
dist/js
server
venv
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/js/index/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/js/joystick/index.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
"dev": "node esbuild.config.js --watch",
"build": "node esbuild.config.js",
"format": "prettier -w .",
"lint": "eslint src",
"test": "tsc --noEmit",
"prepare": "husky install"
},
"devDependencies": {
"@josejefferson/eslint-config-typescript": "^1.1.0",
"esbuild": "^0.20.2",
"esbuild-plugin-clean": "^1.0.1",
"eslint": "^8",
"husky": "^8.0.3",
"prettier": "^2.7.1",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
"rimraf": "^3.0.2",
"typescript": "^4.8.2"
Expand Down
2 changes: 1 addition & 1 deletion src/index/import-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function importOptions() {
try {
const file = this.files![0]
if (!file) return
const content: string | ArrayBuffer = await new Promise((resolve, reject) => {
const content: string = await new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onload = () => resolve(reader.result as string)
reader.onerror = reject
Expand Down
4 changes: 2 additions & 2 deletions src/index/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function updateStartButton() {
}

// Contador de visitas
let hits = parseInt(ls('stats.hits.home'))
let hits = parseInt(ls('stats.hits.home'), 10)
if (isNaN(hits)) hits = 0
ls('stats.hits.home', ++hits)

Expand Down Expand Up @@ -57,7 +57,7 @@ if (!ls('events.addToHomescreenPopup') && (hits === 3 || hits % 10 === 0)) {
$video.loop = true
$video.muted = true
$athPopup.querySelector('.content')!.appendChild($video)
$video.play()
void $video.play()
$athPopup.classList.add('show')
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/element-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function playMacro(this: IElementNode<ButtonComponent, HTMLElement>) {

/** Entra em tela cheia */
function fullScreen() {
document.documentElement.requestFullscreen()
void document.documentElement.requestFullscreen()
}

// Detecta quando o modo de tela cheia é ativado/desativado e mostra/oculta o botão de tela cheia
Expand Down
8 changes: 4 additions & 4 deletions src/joystick/layout-editor/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Toolbar {
for (const $mode of Array.from(this.$modes)) {
const _this = this
$mode.addEventListener('click', function (e) {
const mode = <0 | 1>parseInt(this.dataset.mode!)
const mode = <0 | 1>parseInt(this.dataset.mode!, 10)
if (isNaN(mode)) return
_this.mode = mode
_this.render()
Expand All @@ -73,7 +73,7 @@ export class Toolbar {
this.$anchorX = document.querySelector('.anchor-x')!
this.$anchorX.addEventListener('click', (e) => {
editingElement!.anchorX += 1
if (editingElement!.anchorX > 2) editingElement!.anchorX = AnchorX.LEFT
if (editingElement!.anchorX > AnchorX.CENTER) editingElement!.anchorX = AnchorX.LEFT
this.render()
editingElement!.render()
anchorLines.update()
Expand All @@ -82,7 +82,7 @@ export class Toolbar {
this.$anchorY = document.querySelector('.anchor-y')!
this.$anchorY.addEventListener('click', (e) => {
editingElement!.anchorY += 1
if (editingElement!.anchorY > 2) editingElement!.anchorY = AnchorY.TOP
if (editingElement!.anchorY > AnchorY.CENTER) editingElement!.anchorY = AnchorY.TOP
this.render()
editingElement!.render()
anchorLines.update()
Expand Down Expand Up @@ -112,7 +112,7 @@ export class Toolbar {
this._y = y

for (const $mode of Array.from(this.$modes)) {
const mode = parseInt($mode.dataset.mode!)
const mode = parseInt($mode.dataset.mode!, 10)
if (isNaN(mode)) continue
$mode.classList[this.mode === mode ? 'add' : 'remove']('active-mode')
}
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/layout-editor/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Tree {
$groupContent = $tree
}

for (let el of (element as ILayoutComponent).parsedContent || element.content) {
for (const el of (element as ILayoutComponent).parsedContent || element.content) {
if ('content' in el && Array.isArray(el.content)) {
$groupContent.appendChild(this._html(el as IGroup, false))
} else {
Expand Down
9 changes: 4 additions & 5 deletions src/joystick/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ export function getAllElements(
elements: AnyComponent[] = []
) {
if (object.type === 'mobystk:layout' || object.type === 'mobystk:group') {
object = object as ILayoutComponent | GroupComponent
if (object.type !== 'mobystk:layout') elements.push(object as GroupComponent)
if (object.type !== 'mobystk:layout') elements.push(object)
for (const obj of object.parsedContent!) getAllElements(obj, elements)
} else {
elements.push(object as ButtonComponent | JoystickComponent)
elements.push(object)
}
return elements
}
Expand All @@ -92,14 +91,14 @@ export function parseElement(object: IElementsOrImport) {
// Botão
object = object as IButton
if (options.locked?.includes(objectID)) object = { ...object, lockable: true }
return new ButtonComponent(object as IButton)
return new ButtonComponent(object)
} else if (object.type === 'mobystk:group') {
// Grupo
object = object as IGroup
object.parsedContent = object.content
.map(parseElement)
.filter((e: AnyComponent | undefined) => e) as AnyComponent[]
const group = new GroupComponent(object as IGroup)
const group = new GroupComponent(object)
object.parsedContent = object.parsedContent.map((e: AnyComponent) => (e.parent = group))
return group
} else if (object.type === 'mobystk:joystick') {
Expand Down
3 changes: 2 additions & 1 deletion src/joystick/motion-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default function loadDriveMode() {
if (window.layoutEditor?.opened) return

// Inicia/para o sensor
drive.active ? stopSensor() : startSensor()
if (drive.active) stopSensor()
else startSensor()

/**
* Inicia o sensor
Expand Down
4 changes: 3 additions & 1 deletion src/joystick/user-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ $version.innerText = `v${VERSION}`
// CARREGAMENTO DAS OPÇÕES
$edit.addEventListener('click', loading)
$edit.addEventListener('contextmenu', () => {
window.layoutEditor.opened ? window.layoutEditor.end() : window.layoutEditor.start()
if (window.layoutEditor.opened) window.layoutEditor.end()
else window.layoutEditor.start()
})
if (options.debug) document.body.classList.add('debug')
if (options.invertL) document.body.classList.add('invertL')
Expand All @@ -54,6 +55,7 @@ document.body.append($customCSS)
if (options.customJS && options.customJS.trim()) {
if (confirm('Deseja executar os plugins?')) {
try {
// eslint-disable-next-line @typescript-eslint/no-implied-eval
new Function(options.customJS.trim())()
} catch (err: any) {
alert('Ocorreu um erro ao executar os plugins\n\n' + (err?.message || ''))
Expand Down
10 changes: 5 additions & 5 deletions src/shared/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ interface IController {
}

const Controller: IController = {
buttons: buttons,
groups: groups,
joysticks: joysticks,
gamepads: gamepads,
layout: layout,
buttons,
groups,
joysticks,
gamepads,
layout,
currentLayout: null,
currentTouches: [],
elements: {
Expand Down
2 changes: 1 addition & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type ValueAndUnit = [number, 'px' | '%' | string]
export type ValueAndUnit = [number, 'px' | '%']

0 comments on commit eab9751

Please sign in to comment.