Skip to content

Commit 3bb3cf3

Browse files
authored
Upgrade ESLint and make it part of the main process (codesandbox#2451)
* Apply new linting rules * More minor fixes * Remove some newlines * Remove tsignore lines * Fix common eslint errors * Fix more lint errors * Fix dynamic pages linting issues * Fix homepage lint * Don't enforce param destructure for a reassignment * Auto hooks * Add hooks for eslint fixes * Run app and common concurrently * Upgrade TS * Set standalone-packages as vendored * Fix ts
1 parent a0295e1 commit 3bb3cf3

File tree

292 files changed

+1292
-870
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

292 files changed

+1292
-870
lines changed

.eslintrc

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": ["airbnb", "prettier", "prettier/react", "prettier/flowtype"],
2+
"extends": ["airbnb", "prettier", "prettier/react"],
33
"plugins": ["react-hooks"],
44
"parser": "babel-eslint",
55
"env": {
@@ -19,11 +19,31 @@
1919
"rules": {
2020
"react/jsx-filename-extension": 0,
2121
"react/sort-comp": 0,
22+
"react/destructuring-assignment": 0,
23+
"react/state-in-constructor": 0,
24+
"react/jsx-props-no-spreading": 0,
25+
"react/static-property-placement": 0,
2226
"import/no-extraneous-dependencies": 0,
27+
"import/no-cycle": "warn",
2328
"react/prop-types": 0,
2429
"arrow-parens": 0,
30+
"prefer-destructuring": [
31+
"error",
32+
{
33+
"VariableDeclarator": {
34+
"array": false,
35+
"object": true
36+
},
37+
"AssignmentExpression": {
38+
"array": false,
39+
"object": false
40+
}
41+
}
42+
],
43+
"no-async-promise-executor": "warn",
2544
"import/prefer-default-export": 0,
2645
"class-methods-use-this": 0,
46+
"jsx-a11y/click-events-have-key-events": "warn",
2747
"no-console": ["error", { "allow": ["error", "warn"] }],
2848
"prefer-template": "off",
2949
"no-plusplus": 0,
@@ -52,7 +72,15 @@
5272
],
5373
"jsx-a11y/label-has-for": "off",
5474
"no-bitwise": "off",
55-
"arrow-body-style": ["error", "as-needed"]
75+
"arrow-body-style": ["error", "as-needed"],
76+
"no-restricted-globals": "off",
77+
"lines-between-class-members": [
78+
"error",
79+
"always",
80+
{
81+
"exceptAfterSingleLine": true
82+
}
83+
]
5684
},
5785
"overrides": [
5886
{

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* text=auto eol=lf
2+
standalone-packages/* linguist-vendored

.huskyrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

package.json

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"start:common": "lerna run start --scope @codesandbox/common --stream",
4949
"start:dev_api": "lerna run start:dev_api --scope app --stream",
5050
"start:dynamic": "lerna run dev --scope dynamic-pages --stream",
51-
"start:fast": "cd packages/app && yarn start",
51+
"start:fast": "concurrently --raw \"cd packages/app && yarn start\" \"cd packages/common && yarn start\"",
5252
"start:home": "yarn build:deps && yarn start:home:fast",
5353
"start:home:fast": "cd packages/homepage && yarn start",
5454
"start:overmind": "yarn build:deps && concurrently \"lerna run start --scope app --stream\" \"overmind-devtools\"",
@@ -70,22 +70,35 @@
7070
"all-contributors-cli": "^5.4.0",
7171
"babel-eslint": "^10.0.2",
7272
"concurrently": "^4.1.0",
73+
"cross-env": "^6.0.0",
7374
"eslint": "5.16.0",
74-
"eslint-config-airbnb": "^15.0.1",
75-
"eslint-config-prettier": "^4.2.0",
75+
"eslint-config-airbnb": "^18.0.1",
76+
"eslint-config-prettier": "^6.3.0",
7677
"eslint-import-resolver-webpack": "^0.8.1",
7778
"eslint-loader": "^1.7.1",
78-
"eslint-plugin-flowtype": "^2.34.0",
79-
"eslint-plugin-import": "^2.3.0",
79+
"eslint-plugin-import": "^2.18.2",
8080
"eslint-plugin-jsx-a11y": "^6.2.3",
81-
"eslint-plugin-react": "~7.4.0",
82-
"eslint-plugin-react-hooks": "^1.6.0",
81+
"eslint-plugin-react": "~7.14.3",
82+
"eslint-plugin-react-hooks": "^1.7.0",
8383
"gulp": "^3.9.1",
8484
"husky": "^2.2.0",
8585
"lerna": "^3.16.4",
86+
"lint-staged": "^9.2.5",
8687
"prettier": "1.17.0",
8788
"pretty-quick": "^1.10.0",
88-
"typescript": "3.5.3"
89+
"typescript": "3.6.3"
90+
},
91+
"husky": {
92+
"hooks": {
93+
"pre-commit": "lint-staged"
94+
}
95+
},
96+
"lint-staged": {
97+
"*.{js,jsx,ts,tsx}": [
98+
"cross-env LINT=1 eslint --fix",
99+
"pretty-quick --staged",
100+
"git add"
101+
]
89102
},
90103
"engines": {
91104
"node": "^10.0.0"

packages/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@
303303
"terser": "^4.1.4",
304304
"terser-webpack-plugin": "^1.4.1",
305305
"thread-loader": "^2.1.2",
306-
"typescript": "3.5.2",
306+
"typescript": "3.6.3",
307307
"url-loader": "1.0.1",
308308
"webpack": "^4.36.1",
309309
"webpack-bundle-analyzer": "^2.13.1",

packages/app/src/app/components/CodeEditor/CodeMirror/index.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const highlightLines = (
3939

4040
class CodemirrorEditor extends React.Component<Props, State> implements Editor {
4141
codemirror: typeof CodeMirror;
42+
4243
codemirrorElement: ?HTMLDivElement;
4344
server: $PropertyType<CodeMirror, 'TernServer'>;
4445
sandbox: $PropertyType<Props, 'sandbox'>;
@@ -143,7 +144,7 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
143144
return;
144145
}
145146

146-
const linterWorker = this.linterWorker;
147+
const { linterWorker } = this;
147148
if (linterWorker) {
148149
linterWorker.postMessage({
149150
code,
@@ -313,7 +314,7 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
313314
changeModule = async (newModule: Module) => {
314315
this.currentModule = newModule;
315316

316-
const currentModule = this.currentModule;
317+
const { currentModule } = this;
317318

318319
if (!documentCache[currentModule.id]) {
319320
const mode = (await this.getMode(currentModule.title)) || 'typescript';
@@ -358,7 +359,8 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
358359
return 'text/x-scss';
359360
}
360361
return 'css';
361-
} else if (kind[1] === 'html' || kind[1] === 'vue') {
362+
}
363+
if (kind[1] === 'html' || kind[1] === 'vue') {
362364
await import(
363365
/* webpackChunkName: 'codemirror-html' */ 'codemirror/mode/htmlmixed/htmlmixed'
364366
);
@@ -385,19 +387,23 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
385387
}
386388

387389
return 'htmlmixed';
388-
} else if (kind[1] === 'md') {
390+
}
391+
if (kind[1] === 'md') {
389392
await import(
390393
/* webpackChunkName: 'codemirror-markdown' */ 'codemirror/mode/markdown/markdown'
391394
);
392395
return 'markdown';
393-
} else if (kind[1] === 'json') {
396+
}
397+
if (kind[1] === 'json') {
394398
return 'application/json';
395-
} else if (kind[1] === 'sass') {
399+
}
400+
if (kind[1] === 'sass') {
396401
await import(
397402
/* webpackChunkName: 'codemirror-sass' */ 'codemirror/mode/sass/sass'
398403
);
399404
return 'sass';
400-
} else if (kind[1] === 'styl') {
405+
}
406+
if (kind[1] === 'styl') {
401407
await import(
402408
/* webpackChunkName: 'codemirror-stylus' */ 'codemirror/mode/stylus/stylus'
403409
);
@@ -441,7 +447,7 @@ class CodemirrorEditor extends React.Component<Props, State> implements Editor {
441447
getCode = () => this.codemirror.getValue();
442448

443449
handleSaveCode = async () => {
444-
const onSave = this.props.onSave;
450+
const { onSave } = this.props;
445451
if (onSave) {
446452
onSave(this.codemirror.getValue());
447453
}

packages/app/src/app/components/CodeEditor/Configuration/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ConfigurationFile } from '@codesandbox/common/lib/templates/configurati
99

1010
import CodeIcon from 'react-icons/lib/md/code';
1111

12-
import { Props as EditorProps, Editor } from '../types';
12+
import { Props as EditorProps, Editor } from '../types'; // eslint-disable-line
1313
import { Container, Icon, Title, Description } from './elements';
1414

1515
type Props = EditorProps & {
@@ -86,7 +86,7 @@ export class Configuration extends React.PureComponent<Props>
8686

8787
render() {
8888
const { config, width, height, sandbox } = this.props;
89-
const currentModule = this.currentModule;
89+
const { currentModule } = this;
9090

9191
const { ConfigWizard } = getUI(config.type);
9292

packages/app/src/app/components/CodeEditor/ImageViewer/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Input from '@codesandbox/common/lib/components/Input';
33
import { Button } from '@codesandbox/common/lib/components/Button';
44
import { Container, Title, SubTitle, Image, MaxWidth } from './elements';
55

6-
import { Props } from '../types';
6+
import { Props } from '../types'; // eslint-disable-line
77

88
export class ImageViewer extends React.Component<Props> {
99
onSubmit = (e: React.FormEvent<HTMLFormElement>) => {

packages/app/src/app/components/CodeEditor/Monaco/enable-emmet.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ const enableEmmet = (editor, monaco) => {
6161
// to ensure emmet triggered at the right time
6262
// we need to do grammar analysis
6363

64-
const model = editor.model;
64+
const { model } = editor;
6565
cursor = cur.position;
6666

67-
const column = cursor.column;
67+
const { column } = cursor;
6868
// there is no character before column 1
6969
// no need to continue
7070
if (column === 1) {
7171
emmetLegal.set(false);
7272
return;
7373
}
7474

75-
const lineNumber = cursor.lineNumber;
75+
const { lineNumber } = cursor;
7676

7777
/* eslint-disable no-underscore-dangle */
7878

packages/app/src/app/components/CodeEditor/Monaco/grammars/configure-tokenizer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export async function liftOff(monaco) {
2525
format: 'json',
2626
content: cssGrammar,
2727
};
28-
} else if (scopeName === 'text.html.basic') {
28+
}
29+
if (scopeName === 'text.html.basic') {
2930
return {
3031
format: 'json',
3132
content: htmlGrammar,

0 commit comments

Comments
 (0)