Skip to content

Commit

Permalink
chore: update eslint settings
Browse files Browse the repository at this point in the history
force inclusion of return type
  • Loading branch information
joshuaellis committed Mar 18, 2021
1 parent e0cc26c commit 88dcf38
Show file tree
Hide file tree
Showing 28 changed files with 286 additions and 258 deletions.
12 changes: 9 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@
"import/namespace": "off",
"import/default": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"no-unused-vars": ["warn"],
"no-unused-vars": ["off"],
"no-var": "error",
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "off",
"jest/consistent-test-it": ["error", { "fn": "it", "withinDescribe": "it" }]
"@typescript-eslint/no-explicit-any": "off"
},
"settings": {
"react": {
Expand All @@ -68,6 +67,13 @@
"parserOptions": {
"project": ["./tsconfig.json", "./storybook/tsconfig.json"]
}
},
{
// enable the rule specifically for TypeScript files
"files": ["*.ts", "*.tsx"],
"rules": {
"@typescript-eslint/explicit-function-return-type": ["error", { "allowHigherOrderFunctions": true }]
}
}
]
}
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
# there's a build step for post installation so we don't run build when "testing"
run: yarn install
- name: Lint test 🧪
run: yarn eslint:ci
run: yarn lint:ci
- name: Prettier test
run: yarn prettier:check
- name: Type check
Expand Down
2 changes: 1 addition & 1 deletion demos/ssr/components/Lights.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const Lights = () => {
export const Lights = (): JSX.Element => {
return (
<group>
<spotLight position={[-3, 6, -4]} intensity={10} angle={Math.PI / 4} decay={3.5} distance={35} penumbra={2} />
Expand Down
2 changes: 1 addition & 1 deletion demos/ssr/components/Scene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Mesh } from 'three'
import { Lights } from './Lights'
import { Controls } from './Controls'

export const Scene = () => {
export const Scene = (): JSX.Element => {
const meshRef = useRef<Mesh>()

useFrame((_, delta) => {
Expand Down
3 changes: 2 additions & 1 deletion demos/ssr/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { createGlobalStyle } from 'styled-components'
import type { AppProps } from 'next/app'

const GlobalStyle = createGlobalStyle`
*,
Expand Down Expand Up @@ -45,7 +46,7 @@ const GlobalStyle = createGlobalStyle`
}
`

const App = ({ Component, pageProps }) => {
const App = ({ Component, pageProps }: AppProps): JSX.Element => {
return (
<>
<Component {...pageProps} />
Expand Down
16 changes: 11 additions & 5 deletions demos/ssr/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import Document, { Html, Head, Main, NextScript } from 'next/document'
import Document, { Html, Head, Main, NextScript, DocumentContext } from 'next/document'
import { ServerStyleSheet } from 'styled-components'

export default class Doc extends Document {
static async getInitialProps(ctx) {
static async getInitialProps(
ctx: DocumentContext,
): Promise<{
styles: JSX.Element
html: string
head?: (JSX.Element | null)[] | undefined
}> {
const sheet = new ServerStyleSheet()
const originalRenderPage = ctx.renderPage

try {
ctx.renderPage = () =>
ctx.renderPage = (): ReturnType<DocumentContext['renderPage']> =>
originalRenderPage({
enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />),
enhanceApp: (App) => (props): React.ReactElement => sheet.collectStyles(<App {...props} />),
})

const initialProps = await Document.getInitialProps(ctx)
Expand All @@ -27,7 +33,7 @@ export default class Doc extends Document {
}
}

render() {
render(): JSX.Element {
return (
<Html lang="en">
<Head />
Expand Down
2 changes: 1 addition & 1 deletion demos/ssr/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components'

import { Scene } from '../components/Scene'

export default function IndexPage() {
export default function IndexPage(): JSX.Element {
return (
<Root>
<Canvas>
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"build": "rollup -c && npm run copy",
"build-storybook": "build-storybook -s ./.storybook/public",
"copy": "copyfiles package.json README.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.husky=undefined; this.prettier=undefined; this.jest=undefined; this['lint-staged']=undefined;\"",
"eslint": "eslint --cache --fix src/**/*.ts",
"eslint:ci": "eslint src/**/*.ts",
"lint": "eslint --cache --fix src/**/*.ts",
"lint:ci": "eslint src/**/*.ts",
"prebuild": "rimraf dist && npm run typegen",
"prepare": "npm run build",
"prettier:write": "prettier --write .",
Expand All @@ -36,6 +36,9 @@
"url": "git+https://github.com/pmndrs/three-stdlib.git"
},
"author": "Paul Henschel",
"maintainers": [
"Josh Ellis (https://github.com/joshuaellis"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/pmndrs/three-stdlib/issues"
Expand All @@ -60,8 +63,8 @@
"@storybook/html": "^6.1.21",
"@storybook/preset-typescript": "^3.0.0",
"@types/three": "^0.126.0",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.2",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
Expand Down
16 changes: 8 additions & 8 deletions src/controls/DeviceOrientationControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DeviceOrientationControls extends EventDispatcher {
private EPS = 0.000001

enabled = true
deviceOrientation = { alpha: 0, beta: 0, gamma: 0 }
deviceOrientation: Partial<DeviceOrientationEvent> = { alpha: 0, beta: 0, gamma: 0 }
screenOrientation: string | number = 0
alphaOffset = 0 // radians

Expand All @@ -24,11 +24,11 @@ class DeviceOrientationControls extends EventDispatcher {
this.connect()
}

private onDeviceOrientationChangeEvent = (event: any) => {
private onDeviceOrientationChangeEvent = (event: DeviceOrientationEvent): void => {
this.deviceOrientation = event
}

private onScreenOrientationChangeEvent = () => {
private onScreenOrientationChangeEvent = (): void => {
this.screenOrientation = window.orientation || 0
}

Expand All @@ -44,14 +44,14 @@ class DeviceOrientationControls extends EventDispatcher {
beta: number,
gamma: number,
orient: number,
) => {
): void => {
this.euler.set(beta, alpha, -gamma, 'YXZ') // 'ZXY' for the device, but 'YXZ' for us
quaternion.setFromEuler(this.euler) // orient the device
quaternion.multiply(this.q1) // camera looks out the back of the device, not the top
quaternion.multiply(this.q0.setFromAxisAngle(this.zee, -orient)) // adjust for screen orientation
}

connect = () => {
connect = (): void => {
this.onScreenOrientationChangeEvent() // run once on load

// iOS 13+
Expand All @@ -78,15 +78,15 @@ class DeviceOrientationControls extends EventDispatcher {
this.enabled = true
}

disconnect = () => {
disconnect = (): void => {
window.removeEventListener('orientationchange', this.onScreenOrientationChangeEvent)
window.removeEventListener('deviceorientation', this.onDeviceOrientationChangeEvent)

this.enabled = false
}

private lastQuaternion = new Quaternion()
update = () => {
update = (): void => {
if (this.enabled === false) return

const device = this.deviceOrientation
Expand All @@ -106,7 +106,7 @@ class DeviceOrientationControls extends EventDispatcher {
}
}

dispose = () => this.disconnect()
dispose = (): void => this.disconnect()
}

export { DeviceOrientationControls }
26 changes: 13 additions & 13 deletions src/controls/DragControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DragControls extends EventDispatcher {
this.activate()
}

activate = () => {
activate = (): void => {
this._domElement.addEventListener('pointermove', this.onPointerMove)
this._domElement.addEventListener('pointerdown', this.onPointerDown)
this._domElement.addEventListener('pointerup', this.onPointerCancel)
Expand All @@ -40,7 +40,7 @@ class DragControls extends EventDispatcher {
this._domElement.addEventListener('touchend', this.onTouchEnd)
}

deactivate = () => {
deactivate = (): void => {
this._domElement.removeEventListener('pointermove', this.onPointerMove)
this._domElement.removeEventListener('pointerdown', this.onPointerDown)
this._domElement.removeEventListener('pointerup', this.onPointerCancel)
Expand All @@ -53,11 +53,11 @@ class DragControls extends EventDispatcher {
}

// TODO: confirm if this can be removed?
dispose = () => this.deactivate()
dispose = (): void => this.deactivate()

getObjects = () => this._objects
getObjects = (): Object3D[] => this._objects

private onMouseMove = (event: MouseEvent) => {
private onMouseMove = (event: MouseEvent): void => {
const rect = this._domElement.getBoundingClientRect()

this._mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1
Expand Down Expand Up @@ -104,7 +104,7 @@ class DragControls extends EventDispatcher {
}
}

private onMouseDown = (event: MouseEvent) => {
private onMouseDown = (event: MouseEvent): void => {
event.preventDefault()

this._intersections.length = 0
Expand All @@ -126,7 +126,7 @@ class DragControls extends EventDispatcher {
}
}

private onMouseCancel = (event: MouseEvent) => {
private onMouseCancel = (event: MouseEvent): void => {
event.preventDefault()

if (this._selected) {
Expand All @@ -138,7 +138,7 @@ class DragControls extends EventDispatcher {
this._domElement.style.cursor = this._hovered ? 'pointer' : 'auto'
}

private onPointerMove = (event: PointerEvent) => {
private onPointerMove = (event: PointerEvent): void => {
event.preventDefault()

switch (event.pointerType) {
Expand All @@ -151,7 +151,7 @@ class DragControls extends EventDispatcher {
}
}

private onPointerDown = (event: PointerEvent) => {
private onPointerDown = (event: PointerEvent): void => {
event.preventDefault()

switch (event.pointerType) {
Expand All @@ -164,7 +164,7 @@ class DragControls extends EventDispatcher {
}
}

private onPointerCancel = (event: PointerEvent) => {
private onPointerCancel = (event: PointerEvent): void => {
event.preventDefault()

switch (event.pointerType) {
Expand All @@ -177,7 +177,7 @@ class DragControls extends EventDispatcher {
}
}

private onTouchMove = (event: TouchEvent) => {
private onTouchMove = (event: TouchEvent): void => {
event.preventDefault()
const newEvent = event.changedTouches[0]

Expand All @@ -199,7 +199,7 @@ class DragControls extends EventDispatcher {
}
}

private onTouchStart = (event: TouchEvent) => {
private onTouchStart = (event: TouchEvent): void => {
event.preventDefault()
const newEvent = event.changedTouches[0]

Expand Down Expand Up @@ -232,7 +232,7 @@ class DragControls extends EventDispatcher {
}
}

private onTouchEnd = (event: TouchEvent) => {
private onTouchEnd = (event: TouchEvent): void => {
event.preventDefault()

if (this._selected) {
Expand Down
Loading

1 comment on commit 88dcf38

@vercel
Copy link

@vercel vercel bot commented on 88dcf38 Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.