Skip to content

Commit 535abd0

Browse files
committed
init eslint
1 parent 09ef400 commit 535abd0

10 files changed

+638
-38
lines changed

.babelrc

-15
This file was deleted.

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
node_modules
3+

.eslintrc.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const jest = {
2+
files: ['src/**/*.test.{ts,tsx}'],
3+
env: {
4+
jest: true,
5+
},
6+
}
7+
8+
const build = {
9+
files: ['webpack.config.js', 'babel.config.js'],
10+
env: {
11+
node: true,
12+
browser: false,
13+
},
14+
rules: {
15+
'@typescript-eslint/no-var-requires': 0,
16+
},
17+
}
18+
19+
module.exports = {
20+
env: {
21+
es6: true,
22+
browser: true,
23+
},
24+
parser: '@typescript-eslint/parser',
25+
extends: [
26+
'eslint:recommended',
27+
'plugin:@typescript-eslint/recommended',
28+
'plugin:react/recommended',
29+
30+
'plugin:import/errors',
31+
'plugin:import/warnings',
32+
33+
'prettier',
34+
'prettier/@typescript-eslint',
35+
'prettier/react',
36+
],
37+
plugins: ['react-hooks'],
38+
parserOptions: {
39+
project: './tsconfig.json',
40+
sourceType: 'module',
41+
},
42+
settings: {
43+
react: {
44+
version: 'detect',
45+
},
46+
'import/parsers': {
47+
'@typescript-eslint/parser': ['.ts', '.tsx'],
48+
},
49+
'import/resolver': {
50+
node: {
51+
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
52+
moduleDirectory: ['node_modules', 'src'],
53+
},
54+
},
55+
},
56+
rules: {
57+
'react-hooks/rules-of-hooks': 2,
58+
'no-console': 0,
59+
'@typescript-eslint/explicit-function-return-type': 0,
60+
'@typescript-eslint/member-delimiter-style': 0,
61+
'@typescript-eslint/indent': [2, 2],
62+
'@typescript-eslint/member-ordering': 2,
63+
'@typescript-eslint/explicit-member-accessibility': 0,
64+
'import/first': 2,
65+
'import/newline-after-import': 2,
66+
},
67+
overrides: [jest, build],
68+
}

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/*
2+
site/*
3+
yarn.lock

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
3+
"eslint.run": "onSave",
4+
"editor.formatOnSave": true
5+
}

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# webpack5-babel-typescript-react
2+
3+
> Playground for testing webpack 5, typescript with babel 7, react, jest

babel.config.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict'
2+
3+
module.exports = function(api) {
4+
const env = api.env()
5+
6+
const config = {
7+
presets: [
8+
'@babel/typescript',
9+
'@babel/preset-react',
10+
[
11+
'@babel/env',
12+
{
13+
modules: env === 'test' ? 'commonjs' : false,
14+
targets: {
15+
browsers: ['last 2 versions'],
16+
},
17+
},
18+
],
19+
],
20+
plugins: ['@babel/proposal-class-properties', '@babel/proposal-object-rest-spread'],
21+
}
22+
23+
return config
24+
}

package.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"dev:webpack": "webpack-dev-server --mode development --content-base ./site",
1111
"dev:ts": "tsc --watch --preserveWatchOutput",
1212
"test": "jest",
13-
"build": "yarn run clean && tsc && yarn run test && webpack --mode production"
13+
"build": "yarn run clean && yarn run lint && tsc && yarn run test && webpack --mode production",
14+
"prettier": "prettier --write '**/*.{ts,tsx,js,json,css}'",
15+
"lint": "eslint . --ext .js,.ts,.tsx"
1416
},
1517
"devDependencies": {
1618
"@babel/core": "^7.2.2",
@@ -22,7 +24,14 @@
2224
"@types/jest": "^23.3.13",
2325
"@types/react": "^16.7.22",
2426
"@types/react-dom": "^16.0.11",
27+
"@typescript-eslint/eslint-plugin": "^1.1.1",
28+
"@typescript-eslint/parser": "^1.1.1",
2529
"babel-loader": "^8.0.5",
30+
"eslint": "^5.12.1",
31+
"eslint-config-prettier": "^4.0.0",
32+
"eslint-plugin-import": "^2.16.0",
33+
"eslint-plugin-react": "^7.12.4",
34+
"eslint-plugin-react-hooks": "^0.0.0",
2635
"jest": "^24.0.0",
2736
"npm-run-all": "^4.1.5",
2837
"typescript": "^3.3.0-rc",

src/lib/Example.tsx

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
import React, { useState } from 'react'
22

3+
interface ExampleLabelProps {
4+
count: number
5+
}
6+
7+
class ExampleLabel extends React.Component<ExampleLabelProps, {}> {
8+
constructor(props: ExampleLabelProps) {
9+
super(props)
10+
}
11+
public render() {
12+
const { count } = this.props
13+
this.log()
14+
15+
return <p>You clicked {count} times!</p>
16+
}
17+
log() {
18+
console.log('render')
19+
}
20+
}
21+
322
interface Props {
423
initialCounter: number
524
}
@@ -11,7 +30,7 @@ export default function Example({ initialCounter }: Props) {
1130

1231
return (
1332
<div>
14-
<p>You clicked {count} times!</p>
33+
<ExampleLabel count={count} />
1534
<button onClick={() => setCount(count + 1)}>Click me</button>
1635
</div>
1736
)

0 commit comments

Comments
 (0)