Skip to content

Commit 4b15b98

Browse files
author
LongYinan
committed
style: migrate to eslint and prettier
1 parent a15a93c commit 4b15b98

23 files changed

+1397
-610
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lib
2+
coverage
3+
node_modules

.eslintrc.yml

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
parser: '@typescript-eslint/parser'
2+
3+
parserOptions:
4+
ecmaFeatures:
5+
jsx: true
6+
ecmaVersion: 2020
7+
sourceType: module
8+
9+
env:
10+
browser: true
11+
es6: true
12+
node: true
13+
14+
plugins:
15+
- import
16+
17+
extends:
18+
- eslint:recommended
19+
- plugin:prettier/recommended
20+
21+
settings:
22+
react:
23+
pragma: React
24+
version: 17.0.1
25+
26+
rules:
27+
# 0 = off, 1 = warn, 2 = error
28+
'no-unused-vars':
29+
[
30+
2,
31+
{
32+
varsIgnorePattern: '^_',
33+
argsIgnorePattern: '^_',
34+
ignoreRestSiblings: true,
35+
},
36+
]
37+
'no-undef': 2
38+
'no-console': [2, { allow: ['error', 'warn', 'info', 'assert'] }]
39+
'comma-dangle': ['error', 'only-multiline']
40+
'no-var': 2
41+
'one-var-declaration-per-line': 2
42+
'prefer-const': 2
43+
'no-const-assign': 2
44+
'no-use-before-define': [2, { 'functions': false, 'classes': false }]
45+
'eqeqeq': [2, 'always', { 'null': 'ignore' }]
46+
47+
# https://github.com/benmosher/eslint-plugin-import/pull/334
48+
'import/no-duplicates': 2
49+
'import/first': 2
50+
'import/newline-after-import': 2
51+
'import/order':
52+
[
53+
2,
54+
{
55+
'newlines-between': 'always',
56+
'alphabetize': { 'order': 'asc' },
57+
'groups':
58+
['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
59+
},
60+
]
61+
62+
overrides:
63+
- files:
64+
- src/**/*.{ts,tsx}
65+
- tests/**/*.{ts,tsx}
66+
plugins:
67+
- '@typescript-eslint'
68+
extends:
69+
- prettier/@typescript-eslint
70+
- plugin:import/typescript
71+
parserOptions:
72+
project:
73+
- ./tsconfig.json
74+
- ./tests/tsconfig.json
75+
rules:
76+
'no-undef': 0
77+
# TypeScript declare merge
78+
'no-redeclare': 0
79+
'no-useless-constructor': 0
80+
'no-unused-vars': 0
81+
'no-dupe-class-members': 0
82+
'no-case-declarations': 0
83+
'no-duplicate-imports': 0
84+
'no-return-await': 0
85+
# TypeScript Interface and Type
86+
'no-use-before-define': 0
87+
'@typescript-eslint/adjacent-overload-signatures': 2
88+
'@typescript-eslint/await-thenable': 2
89+
'@typescript-eslint/consistent-type-assertions': 2
90+
'@typescript-eslint/ban-types':
91+
[
92+
'error',
93+
{
94+
'types':
95+
{
96+
'String':
97+
{ 'message': 'Use string instead', 'fixWith': 'string' },
98+
'Number':
99+
{ 'message': 'Use number instead', 'fixWith': 'number' },
100+
'Boolean':
101+
{ 'message': 'Use boolean instead', 'fixWith': 'boolean' },
102+
'Function': { 'message': 'Use explicit type instead' },
103+
},
104+
},
105+
]
106+
'@typescript-eslint/explicit-member-accessibility':
107+
[
108+
'error',
109+
{
110+
accessibility: 'explicit',
111+
overrides:
112+
{
113+
accessors: 'no-public',
114+
constructors: 'no-public',
115+
methods: 'no-public',
116+
properties: 'no-public',
117+
parameterProperties: 'explicit',
118+
},
119+
},
120+
]
121+
'@typescript-eslint/method-signature-style': 2
122+
'@typescript-eslint/no-floating-promises': 2
123+
'@typescript-eslint/no-implied-eval': 2
124+
'@typescript-eslint/no-for-in-array': 2
125+
'@typescript-eslint/no-inferrable-types': 2
126+
'@typescript-eslint/no-invalid-void-type': 2
127+
'@typescript-eslint/no-misused-new': 2
128+
'@typescript-eslint/no-misused-promises': 2
129+
'@typescript-eslint/no-namespace': 2
130+
'@typescript-eslint/no-non-null-asserted-optional-chain': 2
131+
'@typescript-eslint/no-throw-literal': 2
132+
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 2
133+
'@typescript-eslint/prefer-for-of': 2
134+
'@typescript-eslint/prefer-nullish-coalescing': 2
135+
'@typescript-eslint/switch-exhaustiveness-check': 2
136+
'@typescript-eslint/prefer-optional-chain': 2
137+
'@typescript-eslint/prefer-readonly': 2
138+
'@typescript-eslint/prefer-string-starts-ends-with': 0
139+
'@typescript-eslint/no-array-constructor': 2
140+
'@typescript-eslint/require-await': 2
141+
'@typescript-eslint/return-await': 2
142+
'@typescript-eslint/ban-ts-comment':
143+
[
144+
2,
145+
{
146+
'ts-expect-error': false,
147+
'ts-ignore': true,
148+
'ts-nocheck': true,
149+
'ts-check': false,
150+
},
151+
]
152+
'@typescript-eslint/naming-convention':
153+
[
154+
2,
155+
{
156+
selector: 'memberLike',
157+
format: ['camelCase', 'PascalCase'],
158+
modifiers: ['private'],
159+
leadingUnderscore: 'forbid',
160+
},
161+
]
162+
163+
'@typescript-eslint/member-ordering':
164+
[
165+
2,
166+
{
167+
default:
168+
[
169+
'public-static-field',
170+
'protected-static-field',
171+
'private-static-field',
172+
'public-static-method',
173+
'protected-static-method',
174+
'private-static-method',
175+
'public-instance-field',
176+
'protected-instance-field',
177+
'private-instance-field',
178+
'public-constructor',
179+
'protected-constructor',
180+
'private-constructor',
181+
'public-instance-method',
182+
'protected-instance-method',
183+
'private-instance-method',
184+
],
185+
},
186+
]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ typings/
7474

7575
lib/
7676
.vscode
77+
esm/

README.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Emotion TypeScript Plugin
2+
23
[![CircleCI](https://circleci.com/gh/LeetCode-OpenSource/emotion-ts-plugin.svg?style=svg)](https://circleci.com/gh/LeetCode-OpenSource/emotion-ts-plugin)
34
[![codecov](https://codecov.io/gh/LeetCode-OpenSource/emotion-ts-plugin/branch/master/graph/badge.svg)](https://codecov.io/gh/LeetCode-OpenSource/emotion-ts-plugin)
45

56
## Features
7+
68
<table>
79
<thead>
810
<tr>
@@ -113,24 +115,27 @@ module.exports = {
113115
options: {
114116
transpileOnly: true,
115117
getCustomTransformers: () => ({
116-
before: [createEmotionPlugin({ // <------------------- here
117-
sourcemap: true,
118-
autoLabel: true,
119-
labelFormat: '[local]',
120-
// if the jsxFactory is set, should we auto insert the import statement
121-
autoInject: true,
122-
// set for react@17 new jsx runtime
123-
// only effect if `autoInject` is true
124-
// set it in createEmotionPlugin options rather than in `tsconfig.json` will generate more optimized codes:
125-
// import { jsx } from 'react/jsx-runtime' for files not using emotion
126-
// import { jsx } from '@emotion/react/jsx-runtime' for files using emotion
127-
jsxImportSource: "@emotion/react",
128-
})],
118+
before: [
119+
createEmotionPlugin({
120+
// <------------------- here
121+
sourcemap: true,
122+
autoLabel: true,
123+
labelFormat: '[local]',
124+
// if the jsxFactory is set, should we auto insert the import statement
125+
autoInject: true,
126+
// set for react@17 new jsx runtime
127+
// only effect if `autoInject` is true
128+
// set it in createEmotionPlugin options rather than in `tsconfig.json` will generate more optimized codes:
129+
// import { jsx } from 'react/jsx-runtime' for files not using emotion
130+
// import { jsx } from '@emotion/react/jsx-runtime' for files using emotion
131+
jsxImportSource: '@emotion/react',
132+
}),
133+
],
129134
}),
130135
compilerOptions: {
131136
// set jsx pragma to jsx or alias which is from the @emotion/react package to enable css property in jsx component
132-
jsxFactory: "jsx",
133-
}
137+
jsxFactory: 'jsx',
138+
},
134139
},
135140
exclude: /node_modules/,
136141
},
@@ -145,9 +150,8 @@ module.exports = {
145150
new HtmlWebpackPlugin({
146151
template: join(process.cwd(), 'tests', 'fixtures', 'index.html'),
147152
}),
148-
]
153+
],
149154
}
150-
151155
```
152156

153157
for customized exported(re-exported) styled
@@ -177,4 +181,4 @@ createEmotionPlugin({
177181
}
178182
]
179183
})
180-
```
184+
```

package.json

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,69 @@
33
"version": "1.0.1",
44
"description": "TypeScript Emotion Plugin",
55
"main": "lib/index.js",
6+
"module": "esm/index.js",
67
"types": "lib/index.d.ts",
78
"repository": "git@github.com:LeetCode-OpenSource/emotion-ts-plugin.git",
89
"author": "lynweklm@gmail.com",
910
"license": "MIT",
1011
"scripts": {
11-
"build": "rm -rf lib && tsc -p tsconfig.json --outDir lib --diagnostics",
12-
"dev": "rm -rf lib && tsc -p tsconfig.json --outDir lib --diagnostics -w",
13-
"lint": "tslint -c tslint.json -p tsconfig.json",
12+
"build": "tsc -p tsconfig.json --outDir lib --diagnostics && tsc -p tsconfig.json -m esnext --outDir esm --diagnostics",
13+
"dev": "tsc -p tsconfig.json --outDir lib --diagnostics -w",
14+
"format": "run-p format:md format:json format:source format:yml",
15+
"format:json": "prettier --parser json --write '**/*.json'",
16+
"format:md": "prettier --parser markdown --write './*.md'",
17+
"format:source": "prettier --config ./package.json './{src,tests}/**/*.{ts,tsx,js}' --write",
18+
"format:yml": "prettier --parser yaml --write './*.{yml,yaml}'",
19+
"lint": "eslint . -c ./.eslintrc.yml '{src,tests}/**/*.{js,ts,tsx}'",
1420
"start": "webpack serve --progress --color",
1521
"test": "jest --no-cache --ci"
1622
},
1723
"devDependencies": {
18-
"@emotion/react": "^11.1.1",
24+
"@emotion/react": "^11.1.4",
1925
"@emotion/styled": "^11.0.0",
2026
"@swc-node/jest": "^1.1.0",
2127
"@types/convert-source-map": "^1.5.1",
2228
"@types/find-root": "^1.1.2",
23-
"@types/jest": "^26.0.15",
24-
"@types/lodash": "^4.14.165",
29+
"@types/jest": "^26.0.20",
30+
"@types/lodash": "^4.14.168",
2531
"@types/react-dom": "^17.0.0",
26-
"html-webpack-plugin": "^4.5.0",
27-
"husky": "^4.3.0",
32+
"@typescript-eslint/eslint-plugin": "^4.14.1",
33+
"@typescript-eslint/parser": "^4.14.1",
34+
"eslint": "^7.18.0",
35+
"eslint-config-prettier": "^7.2.0",
36+
"eslint-plugin-import": "^2.22.1",
37+
"eslint-plugin-prettier": "^3.3.1",
38+
"html-webpack-plugin": "^4.5.1",
39+
"husky": "^4.3.8",
2840
"jest": "^26.6.3",
2941
"jest-specific-snapshot": "^4.0.0",
30-
"lint-staged": "^10.5.1",
31-
"mini-css-extract-plugin": "^1.3.1",
32-
"prettier": "^2.2.0",
42+
"lint-staged": "^10.5.3",
43+
"mini-css-extract-plugin": "^1.3.4",
44+
"npm-run-all": "^4.1.5",
45+
"prettier": "^2.2.1",
3346
"prop-types": "^15.7.2",
3447
"react": "^17.0.1",
3548
"react-dom": "^17.0.1",
36-
"ts-loader": "^8.0.11",
37-
"tslint": "^5.20.1",
38-
"tslint-config-prettier": "^1.18.0",
39-
"tslint-eslint-rules": "^5.4.0",
40-
"typescript": "^4.1.2",
41-
"webpack": "^5.6.0",
42-
"webpack-cli": "^4.2.0"
49+
"ts-loader": "^8.0.14",
50+
"typescript": "^4.1.3",
51+
"webpack": "^5.18.0",
52+
"webpack-cli": "^4.4.0"
4353
},
4454
"dependencies": {
4555
"@emotion/hash": "^0.8.0",
4656
"convert-source-map": "^1.7.0",
4757
"find-root": "^1.1.0",
4858
"lodash": "^4.17.20",
4959
"source-map": "^0.7.3",
50-
"tslib": "^2.0.3"
60+
"tslib": "^2.1.0"
5161
},
52-
"files": [
53-
"lib/**"
54-
],
62+
"files": ["lib/**", "esm/**"],
5563
"jest": {
5664
"preset": "@swc-node/jest",
57-
"moduleFileExtensions": [
58-
"ts",
59-
"tsx",
60-
"js",
61-
"jsx"
62-
],
65+
"moduleFileExtensions": ["ts", "tsx", "js", "jsx"],
6366
"testRegex": "/tests/.*\\.spec\\.(j|t)sx?$",
6467
"collectCoverage": true,
65-
"collectCoverageFrom": [
66-
"src/**/*.ts"
67-
]
68+
"collectCoverageFrom": ["src/**/*.ts"]
6869
},
6970
"prettier": {
7071
"printWidth": 80,
@@ -75,14 +76,18 @@
7576
"parser": "typescript"
7677
},
7778
"lint-staged": {
78-
"*.ts": [
79-
"prettier --write",
80-
"tslint -c tslint.json --fix"
81-
]
79+
"*.@(js|ts|tsx)": ["prettier --write", "eslint -c .eslintrc.yml --fix"],
80+
"*.@(yml|yaml)": ["prettier --parser yaml --write"],
81+
"*.md": ["prettier --parser markdown --write"],
82+
"*.json": ["prettier --parser json --write"]
8283
},
8384
"husky": {
8485
"hooks": {
8586
"pre-commit": "lint-staged"
8687
}
88+
},
89+
"funding": {
90+
"type": "github",
91+
"url": "https://github.com/sponsors/Brooooooklyn"
8792
}
88-
}
93+
}

0 commit comments

Comments
 (0)