Skip to content

Commit df6695c

Browse files
authoredNov 28, 2021
Add typescript parser for eslint, jsx/tsx check support, fix code errors (#124)
* feat: add .eslintignore * install: @babel/core, @babel/eslint-parser * fix: change parser to @babel/eslint-parser * install: @typescript-eslint/eslint-plugin, @typescript-eslint/parser, delete: @babel/core, @babel/eslint-parser * feat: add lint:code check to lint script * feat: add typescript parser, add react support * fix: eslint errors * refactor: change parameter name fun to fn
1 parent d807ec6 commit df6695c

File tree

14 files changed

+679
-196
lines changed

14 files changed

+679
-196
lines changed
 

‎.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

‎.eslintrc.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
2-
parser: "babel-eslint",
3-
extends: "plugin:markdown/recommended",
4-
plugins: ["markdown"],
2+
parser: "@typescript-eslint/parser",
3+
extends: ["plugin:react/recommended", "plugin:markdown/recommended"],
4+
plugins: ["@typescript-eslint", "react", "markdown"],
55
overrides: [
66
{
77
files: ["**/*.md"],
@@ -14,4 +14,9 @@ module.exports = {
1414
},
1515
},
1616
],
17+
settings: {
18+
react: {
19+
version: "17.0.2",
20+
},
21+
},
1722
};

‎lessons/lesson27/lecture.md

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ const login: ReduxAction<"login"> = {
139139

140140
[Условные типы (Conditional Types)](<https://nauchikus.gitlab.io/typescript-definitive-guide/book/contents/%D0%A3%D1%81%D0%BB%D0%BE%D0%B2%D0%BD%D1%8B%D0%B5%20%D1%82%D0%B8%D0%BF%D1%8B%20(Conditional%20Types).html>), это типы способные принимать одно из двух значений, основываясь на выражении,в котором устанавливается принадлежность к заданному типу данных. Условные типы семантически схожи с тернарным оператором.
141141

142+
<!-- eslint-skip -->
143+
142144
```ts
143145
T extends U ? T1 : T2
144146
```

‎lessons/lesson28/lecture.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ function draw2({
9595
Для callback функций есть стандартное [error-first соглашение](http://fredkschott.com/post/2014/03/understanding-error-first-callbacks-in-node-js/)
9696

9797
```ts
98-
function asyncOperation(param: any, (error: Error | null, data: any) => {});
98+
function asyncOperation(
99+
param: any,
100+
fn: (error: Error | null, data: any) => {}
101+
): any;
99102
```
100103

101104
<!-- v -->

‎lessons/lesson33/lecture.md

+8
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ description: Mediator и EventEmitter как инструмент организ
7171

7272
Может быть представлен как
7373

74+
<!-- eslint-skip -->
75+
7476
```ts
7577
IObservable {
7678
addObserver(event, handler)
@@ -83,6 +85,8 @@ IObservable {
8385

8486
или
8587

88+
<!-- eslint-skip -->
89+
8690
```ts
8791
EventTarget {
8892
addEventListener(event, handler)
@@ -95,6 +99,8 @@ EventTarget {
9599

96100
или
97101

102+
<!-- eslint-skip -->
103+
98104
```ts
99105
Backbone.Events {
100106
on(event, handler)
@@ -107,6 +113,8 @@ Backbone.Events {
107113

108114
Иногда могут добавлять вспомогательные методы, например
109115

116+
<!-- eslint-skip -->
117+
110118
```ts
111119
Backbone.Events {
112120
// ...

‎lessons/lesson34/lecture.md

+2
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ function usersReducer(
259259

260260
<!-- v -->
261261

262+
<!-- eslint-skip -->
263+
262264
```ts
263265
interface State {
264266
users: // ... <- usersReducer

‎lessons/lesson38/lecture.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ description: Работа с асинхронными actions в redux
7878

7979
<!-- v -->
8080

81-
```js [1-30
81+
```ts [1-30]
8282
const getStarredRepos = (username: string) => {
8383
return fetch(`https://api.github.com/users/${username}/starred`);
8484
};
8585
```
8686

8787
<!-- v -->
8888

89-
```js [1-30]
89+
```ts [1-30]
9090
const getStarredRepos = (username: string) => {
9191
return fetch(`https://api.github.com/users/${username}/starred`).then(
9292
(data) => saveData(data)
@@ -96,7 +96,7 @@ const getStarredRepos = (username: string) => {
9696

9797
<!-- v -->
9898

99-
```js [1-30]
99+
```ts [1-30]
100100
const getStarredRepos = (username: string) => {
101101
return fetch(`https://api.github.com/users/${username}/starred`)
102102
.then((data) => saveData(data))
@@ -106,7 +106,7 @@ const getStarredRepos = (username: string) => {
106106

107107
<!-- v -->
108108

109-
```js [1-30]
109+
```ts [1-30]
110110
const getStarredRepos = (username: string) => {
111111
saveIsLoading();
112112

@@ -118,7 +118,7 @@ const getStarredRepos = (username: string) => {
118118

119119
<!-- v -->
120120

121-
```js [1-30]
121+
```ts [1-30]
122122
const getStarredRepos = (username: string) => {
123123
dispatch({ type: "LOADING" });
124124

@@ -130,7 +130,7 @@ const getStarredRepos = (username: string) => {
130130

131131
<!-- v -->
132132

133-
```js [1-30]
133+
```ts [1-30]
134134
const reducer = (state = { isLoading: false }, action) => {
135135
switch (action.type) {
136136
case "LOADING":

‎lessons/lesson42/lecture.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -369,21 +369,21 @@ https://github.com/reduxjs/redux-toolkit/blob/master/package.json#L60
369369
```ts
370370
type ConfigureEnhancersCallback = (
371371
defaultEnhancers: StoreEnhancer[]
372-
) => StoreEnhancer[]
372+
) => StoreEnhancer[];
373373

374374
interface ConfigureStoreOptions<S = any, A extends Action = AnyAction> {
375375
// A single reducer function that will be used as the root reducer, or an
376376
// object of slice reudcers that will passed to `combineReducers()`
377-
reducer: Reducer<S, A> | ReducersMapObject<S, A>
377+
reducer: Reducer<S, A> | ReducersMapObject<S, A>;
378378
// An array of Redux middleware to install
379-
middleware?; Middleware<{}, S>[]
379+
middleware?: Middleware<{}, S>[];
380380
// Whether to enable Redux DevTools integration. Defaults to `true`.
381381
// Additional configuration can be done by passing Redux Devtools options
382-
devTools?: boolean | DevToolsOptions
382+
devTools?: boolean | DevToolsOptions;
383383
// the initial state, same as Redux's createStore.
384-
preloadedState?: DeepPartial<S extends any ? S : S>
384+
preloadedState?: DeepPartial<S extends any ? S : S>;
385385
// The store enhancers to apply. See Redux's `createStore()`.
386-
enhancers?: StoreEnhancer[] | ConfigureEnhancersCallback
386+
enhancers?: StoreEnhancer[] | ConfigureEnhancersCallback;
387387
}
388388
```
389389

‎lessons/lesson43/lecture.md

+16-5
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ describe("App", () => {
321321

322322
> RTL используется для взаимодействия с вашими компонентами React так, как это делает человек. То, что видит человек, - это просто визуализированный HTML из ваших компонентов React, поэтому вы видите эту структуру HTML как результат
323323
324-
```js [1-30]
324+
```html [1-30]
325325
<body>
326326
<div>
327327
<div>Hello React</div>
@@ -467,25 +467,25 @@ describe("App", () => {
467467

468468
`getByLabelText`:
469469

470-
```js
470+
```html
471471
<label for="search" />
472472
```
473473

474474
`getByPlaceholderText`:
475475

476-
```js
476+
```html
477477
<input placeholder="Search" />
478478
```
479479

480480
`getByAltText`:
481481

482-
```js
482+
```html
483483
<img alt="profile" />
484484
```
485485

486486
`getByDisplayValue`:
487487

488-
```js
488+
```html
489489
<input value="JavaScript" />
490490
```
491491

@@ -621,6 +621,9 @@ describe("App", () => {
621621
<!-- v -->
622622

623623
```js [1-30]
624+
import React from "react";
625+
import App from "./App";
626+
624627
describe("App", () => {
625628
test("renders App component", async () => {
626629
render(<App />);
@@ -677,7 +680,11 @@ describe("App", () => {
677680

678681
<!-- v -->
679682

683+
<!-- eslint-skip -->
684+
680685
```js
686+
import React from "react";
687+
681688
function Search({ value, onChange, children }) {
682689
return (
683690
<div>
@@ -691,6 +698,8 @@ function Search({ value, onChange, children }) {
691698
<!-- v -->
692699

693700
```js [1-30]
701+
import React from "react";
702+
import Search from "./Search";
694703
// FireEvent
695704
describe("Search", () => {
696705
test("calls the onChange callback handler", () => {
@@ -714,6 +723,8 @@ describe("Search", () => {
714723
<!-- v -->
715724

716725
```js [1-30]
726+
import React from "react";
727+
import Search from "./Search";
717728
// UserEvent
718729
describe("Search", () => {
719730
test("calls the onChange callback handler", async () => {

‎lessons/lesson46/lecture.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class Screen extends React.Component {
7171

7272
Для dispatch соответственно
7373

74+
<!-- eslint-skip -->
75+
7476
```ts [1-50]
7577
onClick() {
7678
store.dispatch(changePage({id: 'new'}))
@@ -85,6 +87,8 @@ class Screen extends React.Component {
8587

8688
<!-- v -->
8789

90+
<!-- eslint-skip -->
91+
8892
```ts [1-50]
8993
componentDidMount() {
9094
store.subscribe(() => this.forceUpdate());
@@ -193,7 +197,7 @@ export class App extends React.Component {
193197

194198
<!-- v -->
195199

196-
```ts [13-50]
200+
```tsx [13-50]
197201
import React, { Dispatch } from "react";
198202
import { AnyAction } from "redux";
199203
import { store } from "../store";
@@ -380,7 +384,7 @@ export const App = withRedux(RawApp, getAppPropsFromRedux);
380384

381385
[Provider](https://react-redux.js.org/api/provider)
382386

383-
```ts [1-50]
387+
```tsx [1-50]
384388
/**
385389
* Makes the Redux store available to the connect() calls in the componet hierarchy below.
386390
*/

‎lessons/lesson47/lecture.md

+17-9
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ unlisten();
6666

6767
<!--v-->
6868

69-
```js [1-100]
69+
```jsx [1-100]
70+
import React from "react";
7071
import { BrowserRouter, Route } from "react-router-dom";
72+
import News from "./News";
7173

7274
// BrowserRouter создает объект history и прокидывает
7375
// его вниз
@@ -89,8 +91,10 @@ const App = () => (
8991

9092
### Вложенные Route
9193

92-
```js [1-100]
94+
```jsx [1-100]
95+
import React from "react";
9396
import { BrowserRouter, Route, Switch } from "react-router-dom";
97+
import News from "./News";
9498

9599
// также обратите внимание на Switch
96100
const Category = () => (
@@ -115,7 +119,11 @@ const App = () => (
115119

116120
### Route с параметрами
117121

118-
```js [1-100]
122+
<!-- eslint-skip -->
123+
124+
```jsx [1-100]
125+
import React from "react";
126+
119127
const CatPage = ({ match }) => <h1>Viewing category {match.params.catid}</h1>;
120128

121129
const Category = () => (
@@ -130,7 +138,7 @@ const Category = () => (
130138

131139
### Действия при входе
132140

133-
```js [1-100]
141+
```jsx [1-100]
134142
class CatPage extends Component {
135143
// используем лайфсайкл-хук
136144
componentDidMount() {
@@ -189,7 +197,7 @@ const Category = () => (
189197
- **`<a>`** можно даже перетаскивать!
190198
- Если вместо **`<a>`** рисовать
191199

192-
```js [1-100]
200+
```jsx [1-100]
193201
<span onClick={() => history.pushState(/*...*/)}>link</span>
194202
```
195203

@@ -201,7 +209,7 @@ const Category = () => (
201209

202210
<!-- eslint-skip -->
203211

204-
```js [1-100]
212+
```jsx [1-100]
205213
import { Link } from "react-router-dom";
206214
// Хитрая ссылка
207215
<Link to="/news">Новости!</Link>
@@ -232,7 +240,7 @@ const target = {
232240

233241
<!-- eslint-skip -->
234242

235-
```js [1-100]
243+
```jsx [1-100]
236244
//у Link есть подвох
237245
// если на https://vasya-superman.ru написать
238246
<Link to="https://mail.yandex.ru">Yandex.Mail</Link>
@@ -259,7 +267,7 @@ const target = {
259267

260268
<!-- eslint-skip -->
261269

262-
```js [1-100]
270+
```jsx [1-100]
263271
import { Redirect } from "react-router-dom";
264272
// Рендерим Redirect - переходим по адресу
265273
<Redirect to="/view-ad" />
@@ -281,7 +289,7 @@ const withAuth = Cmp => props => {
281289

282290
### Парсим query string
283291

284-
```js [1-100]
292+
```jsx [1-100]
285293
// Противоречивое решение react-router v4:
286294
// убрать работу с queryString
287295
// Теперь все сами:

0 commit comments

Comments
 (0)
Please sign in to comment.