Skip to content

Commit bd9673b

Browse files
Justin WilkersonJustin Wilkerson
Justin Wilkerson
authored and
Justin Wilkerson
committed
Added ESLint and linted the source code. Updated README.
1 parent 67e4f62 commit bd9673b

File tree

8 files changed

+1029
-41
lines changed

8 files changed

+1029
-41
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.css

.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "react-app"
3+
}

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Easily create TypeScript [Playground Plugins](https://www.typescriptlang.org/v2/
2020

2121
✔️ Create styles with stylesheets or CSS-in-JS with Goober.
2222

23+
✔️ Linting with ESLint
24+
2325
## About
2426

2527
The TypeScript Playground V3 beta comes packed with lots of new features, including the ability to create plugins. Per the TypeScript docs:

package.json

+11
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,24 @@
3333
"@types/prettier": "^1.19.0",
3434
"@types/react": "^16.9.22",
3535
"@types/react-dom": "^16.9.5",
36+
"@typescript-eslint/eslint-plugin": "2.x",
37+
"@typescript-eslint/parser": "2.x",
38+
"babel-eslint": "10.x",
3639
"concurrently": "^5.1.0",
3740
"cross-env": "^7.0.0",
41+
"eslint": "6.x",
42+
"eslint-config-react-app": "^5.2.0",
43+
"eslint-plugin-flowtype": "4.x",
44+
"eslint-plugin-import": "2.x",
45+
"eslint-plugin-jsx-a11y": "6.x",
46+
"eslint-plugin-react": "7.x",
47+
"eslint-plugin-react-hooks": "2.x",
3848
"monaco-editor": "^0.20.0",
3949
"prettier": "^1.19.1",
4050
"rollup": "^1.31.1",
4151
"rollup-plugin-babel": "^4.3.3",
4252
"rollup-plugin-css-only": "^2.0.0",
53+
"rollup-plugin-eslint": "^7.0.0",
4354
"rollup-plugin-postcss": "^2.1.1",
4455
"rollup-plugin-terser": "^5.2.0",
4556
"serve": "^11.3.0",

rollup.config.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import commonjs from "@rollup/plugin-commonjs";
44
import babel from "rollup-plugin-babel";
55
import postcss from "rollup-plugin-postcss";
66
import image from "@rollup/plugin-image";
7+
import { eslint } from "rollup-plugin-eslint";
78
import { terser } from "rollup-plugin-terser";
89

910
const isProd = process.env.NODE_ENV === "production";
@@ -16,6 +17,7 @@ export default {
1617
format: "amd"
1718
},
1819
plugins: [
20+
eslint(),
1921
postcss({
2022
plugins: [],
2123
minimize: true,
@@ -24,7 +26,7 @@ export default {
2426
replace({
2527
"process.env.NODE_ENV": JSON.stringify(
2628
isProd ? "production" : "development"
27-
),
29+
)
2830
}),
2931
image(),
3032
resolve({
@@ -47,7 +49,6 @@ export default {
4749
"@babel/preset-typescript"
4850
]
4951
}),
50-
5152
isProd && terser()
5253
]
5354
};

src/App.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ const App: React.FC = () => {
1818
formatCode,
1919
markers,
2020
setDebounce,
21-
sandbox,
22-
model,
23-
container,
21+
// sandbox,
22+
// model,
23+
// container,
2424
flashInfo,
25-
showModal,
25+
// showModal,
2626
prettier
2727
} = usePlugin();
2828

2929
setDebounce(true);
3030

3131
useEffect(() => {
3232
setCode(exampleCode.start, { format: "prettier" });
33-
}, []);
33+
}, [setCode]);
3434

3535
useEffect(() => {
3636
console.log(`The editor code changed:`);

src/plugin/Provider.tsx

+14-11
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ export const Provider: React.FC<ProviderProps> = ({
4848
const [markers, setMarkers] = useState<ModelMarker[]>([]);
4949
const [debounce, setDebounce] = useState(false);
5050

51-
const listenerFn = useCallback((evt: any): void => {
52-
setModel({ ...evt.detail.model });
53-
_setCode(sandbox.getText());
54-
}, []);
51+
const listenerFn = useCallback(
52+
(evt: any): void => {
53+
setModel({ ...evt.detail.model });
54+
_setCode(sandbox.getText());
55+
},
56+
[sandbox]
57+
);
5558

5659
useEffect(() => {
5760
const disposable = sandbox.editor.onDidChangeModelDecorations(() => {
@@ -65,16 +68,16 @@ export const Provider: React.FC<ProviderProps> = ({
6568
});
6669
setMarkers(allMarkers);
6770
});
68-
() => disposable.dispose();
69-
}, []);
71+
return () => disposable.dispose();
72+
}, [sandbox]);
7073

7174
useEffect(() => {
7275
const eventName = debounce ? "modelChangedDebounce" : "modelChanged";
7376
window.addEventListener(eventName, listenerFn);
7477
const otherEventName = debounce ? "modelChanged" : "modelChangedDebounce";
7578
window.removeEventListener(otherEventName, listenerFn, false);
76-
() => window.removeEventListener(eventName, listenerFn, false);
77-
}, [debounce]);
79+
return () => window.removeEventListener(eventName, listenerFn, false);
80+
}, [debounce, listenerFn]);
7881

7982
const setCode = useCallback(
8083
(value: string, options?: { format: "prettier" | "monaco" }) => {
@@ -87,12 +90,12 @@ export const Provider: React.FC<ProviderProps> = ({
8790
sandbox.setText(value);
8891
}
8992
},
90-
[]
93+
[sandbox]
9194
);
9295

9396
const formatCode = useCallback(() => {
9497
return sandbox.editor.getAction("editor.action.formatDocument").run();
95-
}, []);
98+
}, [sandbox.editor]);
9699

97100
const prettier = useCallback(
98101
(config?: Options) => {
@@ -103,7 +106,7 @@ export const Provider: React.FC<ProviderProps> = ({
103106

104107
sandbox.setText(prettyCode);
105108
},
106-
[code]
109+
[code, sandbox]
107110
);
108111

109112
// @ts-ignore

0 commit comments

Comments
 (0)