|
27 | 27 | - [Section 4: Misc. Concerns](#section-4--misc-concerns)
|
28 | 28 | * [Component/Design System Development](#component-design-system-development)
|
29 | 29 | * [Building](#building)
|
30 |
| - * [Prettier + TSLint](#prettier---tslint) |
| 30 | + * [Prettier + TSLint](#prettier--tslint) |
| 31 | + * [ESLint + TSLint](#eslint--tslint) |
31 | 32 | * [Working with Non-Typescript Libraries (writing your own index.d.ts)](#working-with-non-typescript-libraries--writing-your-own-indexdts-)
|
32 | 33 | - [Troubleshooting Handbook: Types](#troubleshooting-handbook--types)
|
33 | 34 | * [Union types](#union-types)
|
@@ -490,7 +491,131 @@ For developing with Storybook, read the docs I maintain over here: <https://stor
|
490 | 491 |
|
491 | 492 | ## Prettier + TSLint
|
492 | 493 |
|
493 |
| -We have an active discussion on Linting [here](https://github.com/sw-yx/react-typescript-cheatsheet/issues/7). |
| 494 | +*Contributed by: [@azdanov](https://github.com/sw-yx/react-typescript-cheatsheet/pull/14)* |
| 495 | + |
| 496 | +To use prettier with TSLint you will need [`tslint-config-prettier`](https://github.com/alexjoverm/tslint-config-prettier) which disables all the conflicting rules and optionally [`tslint-plugin-prettier`](https://github.com/ikatyang/tslint-plugin-prettier) which will highlight differences as TSLint issues. |
| 497 | + |
| 498 | +Example configuration: |
| 499 | + |
| 500 | +<table> |
| 501 | + <tr> |
| 502 | + <th> |
| 503 | + <strong>tslint.json</strong> |
| 504 | + </th> |
| 505 | + <th> |
| 506 | + <strong>.prettierrc</strong> |
| 507 | + </th> |
| 508 | + </tr> |
| 509 | + <tr> |
| 510 | + <td> |
| 511 | + <pre> |
| 512 | +{ |
| 513 | + "rulesDirectory": ["tslint-plugin-prettier"], |
| 514 | + "extends": [ |
| 515 | + "tslint:recommended", |
| 516 | + "tslint-config-prettier" |
| 517 | + ], |
| 518 | + "linterOptions": { |
| 519 | + "exclude": ["node_modules/**/*.ts"] |
| 520 | + }, |
| 521 | + "rules": { |
| 522 | + "prettier": true |
| 523 | + } |
| 524 | +} |
| 525 | + </pre> |
| 526 | + </td> |
| 527 | + <td> |
| 528 | + <pre> |
| 529 | +{ |
| 530 | + "printWidth": 89, |
| 531 | + "tabWidth": 2, |
| 532 | + "useTabs": false, |
| 533 | + "semi": true, |
| 534 | + "singleQuote": true, |
| 535 | + "trailingComma": "all", |
| 536 | + "bracketSpacing": true, |
| 537 | + "jsxBracketSameLine": false |
| 538 | +} |
| 539 | + </pre> |
| 540 | + </td> |
| 541 | + </tr> |
| 542 | +</table> |
| 543 | + |
| 544 | +An example github repository with a project showing how to integrate [prettier + tslint + create-react-app-ts](https://github.com/azdanov/tslint-eslint-crats). |
| 545 | + |
| 546 | +## ESLint + TSLint |
| 547 | + |
| 548 | +Why? ESLint ecosystem is rich, with lots of different plugins and config files, whereas TSLint tend to lag behind in some areas. |
| 549 | + |
| 550 | +To remedy this nuisance there is an [`eslint-typescript-parser`](https://github.com/eslint/typescript-eslint-parser) which tries to bridge the differences between javascript and typescript. It still has some rough corners, but can provide consistent assistance with certain plugins. |
| 551 | + |
| 552 | +<table> |
| 553 | + <tr> |
| 554 | + <td> |
| 555 | + Usage |
| 556 | + </td> |
| 557 | + <td> |
| 558 | + .eslintrc |
| 559 | + </td> |
| 560 | + </tr> |
| 561 | + <tr> |
| 562 | + <td> |
| 563 | + <pre> |
| 564 | +// Install: |
| 565 | + |
| 566 | +npm i -D typescript-eslint-parser |
| 567 | + |
| 568 | +// And in your ESLint configuration file: |
| 569 | + |
| 570 | +"parser": "typescript-eslint-parser" |
| 571 | + </pre> |
| 572 | + </td> |
| 573 | + <td> |
| 574 | + <pre> |
| 575 | +{ |
| 576 | + "extends": [ |
| 577 | + "airbnb", |
| 578 | + "prettier", |
| 579 | + "prettier/react", |
| 580 | + "plugin:prettier/recommended", |
| 581 | + "plugin:jest/recommended", |
| 582 | + "plugin:unicorn/recommended" |
| 583 | + ], |
| 584 | + "plugins": ["prettier", "jest", "unicorn"], |
| 585 | + "parserOptions": { |
| 586 | + "sourceType": "module", |
| 587 | + "ecmaFeatures": { |
| 588 | + "jsx": true |
| 589 | + } |
| 590 | + }, |
| 591 | + "env": { |
| 592 | + "es6": true, |
| 593 | + "browser": true, |
| 594 | + "jest": true |
| 595 | + }, |
| 596 | + "settings": { |
| 597 | + "import/resolver": { |
| 598 | + "node": { |
| 599 | + "extensions": [".js", ".jsx", ".ts", ".tsx"] |
| 600 | + } |
| 601 | + } |
| 602 | + }, |
| 603 | + "overrides": [ |
| 604 | + { |
| 605 | + "files": ["**/*.ts", "**/*.tsx"], |
| 606 | + "parser": "typescript-eslint-parser", |
| 607 | + "rules": { |
| 608 | + "no-undef": "off" |
| 609 | + } |
| 610 | + } |
| 611 | + ] |
| 612 | +} |
| 613 | + </pre> |
| 614 | + </td> |
| 615 | + </tr> |
| 616 | +</table> |
| 617 | + |
| 618 | +An example github repository with a project showing how to integrate [eslint + tslint + create-react-app-ts](https://github.com/azdanov/tslint-eslint-crats). |
494 | 619 |
|
495 | 620 | ## Working with Non-Typescript Libraries (writing your own index.d.ts)
|
496 | 621 |
|
|
0 commit comments