UNPKG

3.9 kBMarkdownView Raw
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
5tslint-react
6------------
7
8Lint rules related to React & JSX for [TSLint](https://github.com/palantir/tslint/).
9
10### Usage
11
12Sample 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-ban-props` (since v2.3.0)
47 - Allows blacklisting of props in JSX with an optional explanatory message in the reported failure.
48- `jsx-curly-spacing` (since v1.1.0)
49 - Requires _or_ bans spaces between curly brace characters in JSX.
50 - Rule options: `["always", "never"]`
51 - _Includes automatic code fix_
52- `jsx-no-lambda`
53 - 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.
54 - Rule options: _none_
55- `jsx-no-multiline-js`
56 - Disallows multiline JS expressions inside JSX blocks to promote readability
57 - Rule options: _none_
58- `jsx-no-string-ref`
59 - Passing strings to the `ref` prop of React elements is considered a legacy feature and will soon be deprecated.
60 Instead, [use a callback](https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute).
61 - Rule options: _none_
62- `jsx-use-translation-function` (since v2.4.0)
63 - Enforces use of a translation function. Plain string literals are disallowed in JSX when enabled.
64 - Rule options: _none_
65 - Off by default
66- `jsx-self-close` (since v0.4.0)
67 - Enforces that JSX elements with no children are self-closing.
68 ```ts
69 // bad
70 <div className="foo"></div>
71 // good
72 <div className="foo" />
73 ```
74 - Rule options: _none_
75- `jsx-wrap-multiline` (since v2.1)
76 - Enforces that multiline JSX expressions are wrapped with parentheses.
77 - Opening parenthesis must be followed by a newline.
78 - Closing parenthesis must be preceded by a newline.
79 - Off by default
80 ```ts
81 // bad
82 const button = <button type="submit">
83 Submit
84 </button>;
85 // good
86 const button = (
87 <button type="submit">
88 Submit
89 </button>
90 );
91 ```
92
93### Development
94
95We 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).
96
97We'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).
98
99Quick Start (requires Node v6+, yarn v0.18):
100
1011. `yarn`
1021. `yarn compile`
1031. `yarn lint`
1041. `./scripts/verify.sh`
105
106### Changelog
107
108See the Github [release history](https://github.com/palantir/tslint-react/releases).
109
\No newline at end of file