1 | [![NPM version](https://badge.fury.io/js/tslint-react.svg)](https://www.npmjs.com/package/tslint-react)
|
2 | [![Downloads](http://img.shields.io/npm/dm/tslint-react.svg)](https://npmjs.org/package/tslint-react)
|
3 | [![Circle CI](https://circleci.com/gh/palantir/tslint-react.svg?style=svg)](https://circleci.com/gh/palantir/tslint-react)
|
4 |
|
5 | tslint-react
|
6 | ------------
|
7 |
|
8 | Lint rules related to React & JSX for [TSLint](https://github.com/palantir/tslint/).
|
9 |
|
10 | ### Usage
|
11 |
|
12 | Sample configuration where `tslint.json` lives adjacent to your `node_modules` folder:
|
13 |
|
14 | ```js
|
15 | {
|
16 | "extends": ["tslint:latest", "tslint-react"],
|
17 | "rules": {
|
18 | // enable tslint-react rules here
|
19 | "jsx-no-lambda": true
|
20 | }
|
21 | }
|
22 | ```
|
23 |
|
24 | ### Rules
|
25 |
|
26 | - `jsx-alignment`
|
27 | - Enforces a consistent style for multiline JSX elements which promotes ease of editing via line-wise manipulations
|
28 | as well as maintainabilty via small diffs when changes are made.
|
29 | ```ts
|
30 | // Good:
|
31 | const element = <div
|
32 | className="foo"
|
33 | tabIndex={1}
|
34 | >
|
35 | {children}
|
36 | </div>;
|
37 |
|
38 | // Also Good:
|
39 | <Button
|
40 | appearance="pretty"
|
41 | disabled
|
42 | label="Click Me"
|
43 | size={size}
|
44 | />
|
45 | ```
|
46 | - `jsx-curly-spacing` (since v1.1.0)
|
47 | - Requires _or_ bans spaces between curly brace characters in JSX.
|
48 | - Rule options: `["always", "never"]`
|
49 | - _Includes automatic code fix_
|
50 | - `jsx-no-lambda`
|
51 | - Creating new anonymous functions (with either the `function` syntax or ES2015 arrow syntax) inside the `render` call stack works against _pure component rendering_. When doing an equality check between two lambdas, React will always consider them unequal values and force the component to re-render more often than necessary.
|
52 | - Rule options: _none_
|
53 | - `jsx-no-multiline-js`
|
54 | - Disallows multiline JS expressions inside JSX blocks to promote readability
|
55 | - Rule options: _none_
|
56 | - `jsx-no-string-ref`
|
57 | - Passing strings to the `ref` prop of React elements is considered a legacy feature and will soon be deprecated.
|
58 | Instead, [use a callback](https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute).
|
59 | - Rule options: _none_
|
60 | - `jsx-self-close` (since v0.4.0)
|
61 | - Enforces that JSX elements with no children are self-closing.
|
62 | ```ts
|
63 | // bad
|
64 | <div className="foo"></div>
|
65 | // good
|
66 | <div className="foo" />
|
67 | ```
|
68 | - Rule options: _none_
|
69 | - `jsx-wrap-multiline` (since v2.1)
|
70 | - Enforces that multiline JSX expressions are wrapped with parentheses.
|
71 | - Opening parenthesis must be followed by a newline.
|
72 | - Closing parenthesis must be preceded by a newline.
|
73 | ```ts
|
74 | // bad
|
75 | const button = <button type="submit">
|
76 | Submit
|
77 | </button>;
|
78 | // good
|
79 | const button = (
|
80 | <button type="submit">
|
81 | Submit
|
82 | </button>
|
83 | );
|
84 | ```
|
85 |
|
86 | ### Development
|
87 |
|
88 | We track rule suggestions on Github issues -- [here's a useful link](https://github.com/palantir/tslint-react/issues?q=is%3Aissue+is%3Aopen+label%3A%22Type%3A+Rule+Suggestion%22) to view all the current suggestions. Tickets are roughly triaged by priority (P1, P2, P3).
|
89 |
|
90 | We're happy to accept PRs for new rules, especially those marked as [Status: Accepting PRs](https://github.com/palantir/tslint-react/issues?q=is%3Aissue+is%3Aopen+label%3A%22Status%3A+Accepting+PRs%22). If submitting a PR, try to follow the same style conventions as the [core TSLint project](https://github.com/palantir/tslint).
|
91 |
|
92 | ### Changelog
|
93 |
|
94 | See the Github [release history](https://github.com/palantir/tslint-react/releases).
|
95 |
|
96 |
|
\ | No newline at end of file |