|
| 1 | +RingCentral TypeScript |
| 2 | +====================== |
| 3 | + |
| 4 | +A stricter and TypeScript-enabled version of https://github.com/ringcentral/ringcentral-javascript. |
| 5 | + |
| 6 | +## Installation |
| 7 | + |
| 8 | +```bash |
| 9 | +$ npm install eslint eslint-config-ringcentral-typescript --save-dev |
| 10 | +``` |
| 11 | + |
| 12 | +Add this to `scripts` section of `package.json`: |
| 13 | + |
| 14 | +```json |
| 15 | +{ |
| 16 | + "scripts": { |
| 17 | + "lint": "eslint --cache --cache-location node_modules/.cache/eslint --fix ", |
| 18 | + "lint:all": "npm run lint 'src/**/*.ts' 'src/**/*.tsx'" |
| 19 | + } |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +You can add `--quiet` to suppress warnings, but that's not recommended. |
| 24 | +You can add `DEBUG=eslint:cli-engine` to output files that were linted. |
| 25 | + |
| 26 | +:warning: Please note commas around globs: `'src/**/*.ts'`, this will prevent your OS to expand those globs. |
| 27 | + |
| 28 | +Create `.eslintrc`: |
| 29 | + |
| 30 | +```json |
| 31 | +{ |
| 32 | + "extends": [ |
| 33 | + "ringcentral-typescript" |
| 34 | + ] |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +Create `.prettierrc` (optional): |
| 39 | + |
| 40 | +```bash |
| 41 | +{ |
| 42 | + "printWidth": 120 |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +:warning: Keep in mind that anything you set in `.prettierrc` may be overridden by config specified in this repo. |
| 47 | + |
| 48 | +You may use following trick in `.eslintrc` if you need to take control: |
| 49 | + |
| 50 | +```js |
| 51 | +const prettierOptions = JSON.parse(require('fs').readFileSync('./.prettierrc').toString()); |
| 52 | + |
| 53 | +module.exports = { |
| 54 | + ... |
| 55 | + rules: { |
| 56 | + 'prettier/prettier': ['warn', Object.assign({}, prettierOptions)] |
| 57 | + } |
| 58 | +}; |
| 59 | +``` |
| 60 | + |
| 61 | +Create a `.editorconfig` (optional): |
| 62 | + |
| 63 | +```ini |
| 64 | +root = true |
| 65 | + |
| 66 | +[*] |
| 67 | +indent_style = space |
| 68 | +end_of_line = lf |
| 69 | +charset = utf-8 |
| 70 | +trim_trailing_whitespace = true |
| 71 | +insert_final_newline = false |
| 72 | + |
| 73 | +[*.{js,jsx,ts,tsx}] |
| 74 | +indent_size = 4 |
| 75 | + |
| 76 | +[*.{css,sass,scss,yml,json}] |
| 77 | +indent_size = 2 |
| 78 | + |
| 79 | +[Makefile] |
| 80 | +indent_style = tab |
| 81 | +``` |
| 82 | + |
| 83 | +## Suggested use |
| 84 | + |
| 85 | +Works best when used together with [Husky](https://github.com/typicode/husky) and [Lint Staged](https://github.com/okonet/lint-staged): |
| 86 | + |
| 87 | +```bash |
| 88 | +$ npm install husky lint-staged --save-dev |
| 89 | +``` |
| 90 | + |
| 91 | +Add this to `scripts` section of `package.json`: |
| 92 | + |
| 93 | +```json |
| 94 | +{ |
| 95 | + "scripts": { |
| 96 | + "lint:staged": "lint-staged" |
| 97 | + } |
| 98 | +} |
| 99 | +``` |
| 100 | + |
| 101 | +Create `.huskyrc`: |
| 102 | + |
| 103 | +```json |
| 104 | +{ |
| 105 | + "hooks": { |
| 106 | + "pre-commit": "npm run lint:staged" |
| 107 | + } |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +Create `.lintstagedrc`: |
| 112 | + |
| 113 | +```json |
| 114 | +{ |
| 115 | + "*.{js,jsx,ts,tsx}": [ |
| 116 | + "npm run lint --", |
| 117 | + "git add" |
| 118 | + ] |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +## Integration with JetBrains products (Idea, WebStorm, PhpStorm) |
| 123 | + |
| 124 | +Due to a bug you need to manually add extensions to registry: click `Help -> Find Action -> Registry`, search for |
| 125 | +`eslint.additional.file.extensions` and add `ts,tsx`, see https://youtrack.jetbrains.com/issue/WEB-29829#focus=streamItem-27-3182764-0-0. |
0 commit comments