Skip to content

Commit f2faa43

Browse files
author
Yannick Croissant
committed
Add rules documentation
1 parent c62665c commit f2faa43

File tree

6 files changed

+238
-7
lines changed

6 files changed

+238
-7
lines changed

.eslintrc

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"settings": {
6+
"ecmascript": 6,
7+
"jsx": true
8+
},
9+
"rules": {
10+
// Possible Errors
11+
"no-comma-dangle": 2,
12+
"no-cond-assign": 2,
13+
"no-console": 2,
14+
"no-constant-condition": 2,
15+
"no-control-regex": 2,
16+
"no-debugger": 2,
17+
"no-dupe-keys": 2,
18+
"no-empty": 2,
19+
"no-empty-class": 2,
20+
"no-ex-assign": 2,
21+
"no-extra-boolean-cast": 2,
22+
"no-extra-parens": 0,
23+
"no-extra-semi": 2,
24+
"no-func-assign": 2,
25+
"no-inner-declarations": 2,
26+
"no-invalid-regexp": 2,
27+
"no-irregular-whitespace": 2,
28+
"no-negated-in-lhs": 2,
29+
"no-obj-calls": 2,
30+
"no-regex-spaces": 2,
31+
"no-reserved-keys": 2,
32+
"no-sparse-arrays": 2,
33+
"no-unreachable": 2,
34+
"use-isnan": 2,
35+
"valid-jsdoc": 0,
36+
"valid-typeof": 2,
37+
// Best Practices
38+
"block-scoped-var": 2,
39+
"complexity": [2, 10],
40+
"consistent-return": 2,
41+
"curly": 2,
42+
"default-case": 2,
43+
"dot-notation": 2,
44+
"eqeqeq": 2,
45+
"guard-for-in": 2,
46+
"no-alert": 2,
47+
"no-caller": 2,
48+
"no-div-regex": 2,
49+
"no-else-return": 2,
50+
"no-empty-label": 2,
51+
"no-eq-null": 2,
52+
"no-eval": 2,
53+
"no-extend-native": 2,
54+
"no-extra-bind": 2,
55+
"no-fallthrough": 2,
56+
"no-floating-decimal": 2,
57+
"no-implied-eval": 2,
58+
"no-iterator": 2,
59+
"no-labels": 2,
60+
"no-lone-blocks": 2,
61+
"no-loop-func": 2,
62+
"no-multi-spaces": 2,
63+
"no-multi-str": 0,
64+
"no-native-reassign": 2,
65+
"no-new": 2,
66+
"no-new-func": 2,
67+
"no-new-wrappers": 2,
68+
"no-octal": 2,
69+
"no-octal-escape": 2,
70+
"no-process-env": 2,
71+
"no-proto": 2,
72+
"no-redeclare": 2,
73+
"no-return-assign": 2,
74+
"no-script-url": 2,
75+
"no-self-compare": 2,
76+
"no-sequences": 2,
77+
"no-unused-expressions": 2,
78+
"no-void": 0,
79+
"no-warning-comments": 2,
80+
"no-with": 2,
81+
"radix": 2,
82+
"vars-on-top": 0,
83+
"wrap-iife": 2,
84+
"yoda": 2,
85+
// Strict Mode
86+
"global-strict": [2, "always"],
87+
"no-extra-strict": 2,
88+
"strict": 2,
89+
// Variables
90+
"no-catch-shadow": 2,
91+
"no-delete-var": 2,
92+
"no-label-var": 2,
93+
"no-shadow": 2,
94+
"no-shadow-restricted-names": 2,
95+
"no-undef": 2,
96+
"no-undef-init": 2,
97+
"no-undefined": 2,
98+
"no-unused-vars": 2,
99+
"no-use-before-define": 2,
100+
// Stylistic Issues
101+
"brace-style": 2,
102+
"camelcase": 0,
103+
"comma-spacing": 2,
104+
"comma-style": 2,
105+
"consistent-this": 0,
106+
"eol-last": 0,
107+
"func-names": 0,
108+
"func-style": 0,
109+
"key-spacing": 2,
110+
"max-nested-callbacks": [2, 3],
111+
"new-cap": 2,
112+
"new-parens": 2,
113+
"no-array-constructor": 2,
114+
"no-inline-comments": 0,
115+
"no-lonely-if": 2,
116+
"no-mixed-spaces-and-tabs": 2,
117+
"no-nested-ternary": 2,
118+
"no-new-object": 2,
119+
"no-space-before-semi": 2,
120+
"no-spaced-func": 2,
121+
"no-ternary": 0,
122+
"no-trailing-spaces": 2,
123+
"no-multiple-empty-lines": 2,
124+
"no-underscore-dangle": 0,
125+
"no-wrap-func": 2,
126+
"one-var": 0,
127+
"operator-assignment": [2, "always"],
128+
"padded-blocks": 0,
129+
"quotes": [2, "singe"],
130+
"quote-props": 0,
131+
"semi": [2, "always"],
132+
"sort-vars": 0,
133+
"space-after-keywords": 2,
134+
"space-before-blocks": 2,
135+
"space-in-brackets": 2,
136+
"space-in-parens": 2,
137+
"space-infix-ops": 2,
138+
"space-return-throw-case": 2,
139+
"space-unary-ops": 2,
140+
"spaced-line-comment": 2,
141+
"wrap-regex": 0,
142+
// Legacy
143+
"max-depth": [2, 3],
144+
"max-len": 0,
145+
"max-params": [2, 10],
146+
"max-statements": [2, 10],
147+
"no-bitwise": 2,
148+
"no-plusplus": 0,
149+
}
150+
}

docs/rules/no-multi-comp.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Prevent multiple component definition per file (no-multi-comp)
2+
3+
Declaring only one component per file improves readability and reusability of components.
4+
5+
## Rule Details
6+
7+
The following patterns are considered warnings:
8+
9+
```js
10+
var Hello = React.createClass({
11+
render: function() {
12+
return <div>Hello {this.props.name}</div>;
13+
}
14+
});
15+
16+
var HelloJohn = React.createClass({
17+
render: function() {
18+
return <Hello name="John" />;
19+
}
20+
});
21+
```
22+
23+
The following patterns are not warnings:
24+
25+
```js
26+
var Hello = require('./components/Hello');
27+
28+
var HelloJohn = React.createClass({
29+
render: function() {
30+
return <Hello name="John" />;
31+
}
32+
});
33+
```
34+
35+
## When Not To Use It
36+
37+
If you prefer to declare multiple components per files you can disable this rule.

docs/rules/prop-types.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Prevent missing propTypes in a React component definition (prop-types)
2+
3+
PropTypes improve the reusability of your component by validating the reveived data.
4+
5+
It can warn other developers if they make a mistake while reusing the component with improper data type.
6+
7+
## Rule Details
8+
9+
The following patterns are considered warnings:
10+
11+
```js
12+
var Hello = React.createClass({
13+
render: function() {
14+
return <div>Hello {this.props.name}</div>;
15+
}
16+
});
17+
```
18+
19+
The following patterns are not warnings:
20+
21+
```js
22+
var Hello = React.createClass({
23+
propTypes: {
24+
name: React.PropTypes.string.isRequired
25+
},
26+
render: function() {
27+
return <div>Hello {this.props.name}</div>;
28+
}
29+
});
30+
```

lib/rules/no-multi-comp.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
*/
55
'use strict';
66

7-
//------------------------------------------------------------------------------
7+
// ------------------------------------------------------------------------------
88
// Rule Definition
9-
//------------------------------------------------------------------------------
9+
// ------------------------------------------------------------------------------
1010

1111
module.exports = function(context) {
1212

1313
var componentCounter = 0;
1414

15-
//--------------------------------------------------------------------------
15+
// --------------------------------------------------------------------------
1616
// Public
17-
//--------------------------------------------------------------------------
17+
// --------------------------------------------------------------------------
1818

1919
return {
2020
'MemberExpression': function(node) {

lib/rules/prop-types.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
*/
55
'use strict';
66

7-
//------------------------------------------------------------------------------
7+
// ------------------------------------------------------------------------------
88
// Rule Definition
9-
//------------------------------------------------------------------------------
9+
// ------------------------------------------------------------------------------
1010

1111
module.exports = function(context) {
1212

1313
var hasPropTypes = false;
1414

15+
// --------------------------------------------------------------------------
16+
// Public
17+
// --------------------------------------------------------------------------
18+
1519
return {
1620

1721
'ObjectExpression': function(node) {

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"description": "React specific linting rules for ESLint",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "npm run lint && npm run unit-test --coverage && npm run check-coverage",
8+
"lint": "eslint ./",
9+
"unit-test": "istanbul test --dir build/coverage node_modules/mocha/bin/_mocha tests/**/*.js -- --recursive --reporter dot",
10+
"check-coverage": "istanbul check-coverage --statement 100 --branch 100 --function 100 --lines 100",
11+
"report-coverage-html": "istanbul report --dir build/coverage html"
812
},
913
"repository": {
1014
"type": "git",
@@ -16,6 +20,12 @@
1620
"eslint",
1721
"react"
1822
],
23+
"devDependencies": {
24+
"eslint": "^0.11.0-alpha.0",
25+
"eslint-tester": "^0.3.0",
26+
"istanbul": "0.3.0",
27+
"mocha": "1.21.4"
28+
},
1929
"author": "Yannick Croissant (https://github.com/yannickcr)",
2030
"licenses": [
2131
{

0 commit comments

Comments
 (0)