Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to TypeScript #9

Merged
merged 24 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .babelrc.json

This file was deleted.

35 changes: 4 additions & 31 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,18 @@
module.exports = {
env: {
browser: true,
es6: true,
},
extends: [
'standard',
'standard-react',
'prettier/react',
'react-app',
'prettier/@typescript-eslint',
Copy link
Author

Choose a reason for hiding this comment

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

These are the ejected defaults via yarn lint --write-file so I could use the hooks plugin. Do we want to be explicit here with our own standards?

Copy link

Choose a reason for hiding this comment

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

Good question, I've never looked, but do you know if there a good way to diff between different eslint configs?

Since we're currently in a reset phase, this may also be a good time to standardize an eslint config for JS and TS.

Copy link
Author

@andy-hook andy-hook Sep 29, 2020

Choose a reason for hiding this comment

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

I was thinking about this and I really like the idea of standardising around a single opinionated tool. The more of this configuration we can offload the more we can focus on the building, so for the TS projects I was thinking we could just straight up use the provided values and leave it there, see how we get on?

These customisations I made were actually unnecessary, the tool ships with all the setting we would want, my editor just couldn't see the configuration.

I followed their suggested fix jaredpalmer/tsdx#379 (comment) and exported unedited default settings in 9dd0d73

Copy link

Choose a reason for hiding this comment

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

Interesting, so VSC can't automatically resolve TSDX's default config without ejecting them?

I've been procrastinating on setting up "standard" linting configs in https://github.com/aragon/github for forever, but now is a good chance. I'll get a structure going—I was mainly thinking of packaging something like eslint-config-aragon-ts-react (and etc. for other environments).

Copy link
Contributor

Choose a reason for hiding this comment

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

Having a package for our config would be lovely! And yeah, for some reason VSCode sometimes has a hard time reading configs with TSDX 😅

'plugin:prettier/recommended',
],
parser: 'babel-eslint',
parserOptions: {
ecmaFeatures: {
experimentalObjectRestSpread: true,
jsx: true,
},
sourceType: 'module',
},
plugins: ['prettier', 'react', 'react-hooks'],
plugins: ['react-hooks'],
rules: {
'react/prop-types': 'warn',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'error',
'import/no-unresolved': [
andy-hook marked this conversation as resolved.
Show resolved Hide resolved
'error',
{ ignore: ['^react(-dom)?$', '^styled-components$'] },
],
'promise/no-nesting': ['off'],
'linebreak-style': ['error', 'unix'],
curly: 'error',
},
settings: {
react: {
pragma: 'React',
version: '16.6',
version: 'detect',
andy-hook marked this conversation as resolved.
Show resolved Hide resolved
},
},
overrides: [
{
files: ['**/*.test.js'],
env: { jest: true },
},
],
}
3 changes: 1 addition & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
"singleQuote": true
}
15 changes: 7 additions & 8 deletions examples/nodejs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

lodash.throttle@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
integrity sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ=
lodash-es@^4.17.15:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.15.tgz#21bd96839354412f23d7a10340e5eac6ee455d78"
integrity sha512-rlrc3yU3+JNOpZ9zj5pQtxnx2THmvRykwL4Xlxoa8I9lHBlVbbyPhgyPMioxVZ4NqyxaVVtaJnzsyOidQIhyyQ==

loose-envify@^1.1.0, loose-envify@^1.4.0:
version "1.4.0"
Expand All @@ -24,7 +24,7 @@ object-assign@^4.1.1:
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=

prop-types@^15.6.2, prop-types@^15.7.2:
prop-types@^15.6.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
Expand Down Expand Up @@ -66,7 +66,6 @@ scheduler@^0.19.1:
object-assign "^4.1.1"

"use-viewport@file:../..":
version "0.1.0"
version "0.2.0"
dependencies:
lodash.throttle "^4.1.1"
prop-types "^15.7.2"
lodash-es "^4.17.15"
12 changes: 0 additions & 12 deletions examples/simple-viewport/.babelrc

This file was deleted.

15 changes: 9 additions & 6 deletions examples/simple-viewport/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Simple Viewport</title>
</head>
<body>
<div id="app"></div>
<script src="./index.js"></script>

<body style="margin: 0;">
<div id="root"></div>
<script src="./index.tsx"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
import 'babel-polyfill'
import React from 'react'
import 'react-app-polyfill/ie11'
andy-hook marked this conversation as resolved.
Show resolved Hide resolved
import React, { useState } from 'react'
import ReactDOM from 'react-dom'
import { ViewportProvider, useViewport } from 'use-viewport'

function App() {
const { width, height, within, below, above } = useViewport()
const [throttleAmount, setThrottleAmount] = useState(100)

return (
<ViewportProvider throttle={throttleAmount}>
<div>
<Content />
<label style={{ marginTop: '20px' }}>
Throttle{' '}
<input
value={throttleAmount}
onChange={event => setThrottleAmount(Number(event.target.value))}
/>
</label>
</div>
</ViewportProvider>
)
}

function Content() {
const { width, height, within, below, above } = useViewport()
return (
<div>
{below('medium') && <div>small</div>}
Expand All @@ -19,7 +37,7 @@ function App() {
}

ReactDOM.render(
<ViewportProvider>
<>
<App />
<style>
{`
Expand All @@ -39,6 +57,6 @@ ReactDOM.render(
}
`}
</style>
</ViewportProvider>,
document.querySelector('#app')
</>,
document.getElementById('root')
)
14 changes: 8 additions & 6 deletions examples/simple-viewport/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"scripts": {
"start": "parcel serve index.html",
"start": "parcel index.html",
"build": "parcel build index.html"
},
"dependencies": {
"babel-polyfill": "^6.26.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react": "^16.13.1",
"react-app-polyfill": "^1.0.6",
"react-dom": "^16.13.1",
"use-viewport": "link:../.."
},
"devDependencies": {
"@babel/core": "^7.8.3",
"parcel": "^1.12.4"
"@types/react": "^16.9.49",
"@types/react-dom": "^16.9.8",
"parcel": "^1.12.3",
"typescript": "^3.4.5"
}
}
21 changes: 21 additions & 0 deletions examples/simple-viewport/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"target": "es5",
"module": "commonjs",
"jsx": "react",
"moduleResolution": "node",
"noImplicitAny": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"removeComments": true,
"strictNullChecks": true,
"preserveConstEnums": true,
"sourceMap": true,
"lib": ["es2015", "es2016", "dom"],
"types": ["node"],
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
Loading