Skip to content

Commit

Permalink
[change] approved rules for styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Mollweide committed Jul 11, 2016
1 parent 9b5970f commit bca5c6c
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 53 deletions.
29 changes: 14 additions & 15 deletions documentation/best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ example = {
> specify the maximum cyclomatic complexity allowed in a program

✓ Enabled (warning)
✓ Enabled (error)

```javascript

Expand Down Expand Up @@ -166,8 +166,6 @@ function b(x) {
return x + 3;
case x === 3:
return x + 4;
case x === 4:
return x + 5;
default:
return 99;
}
Expand All @@ -184,20 +182,18 @@ function b(x) {
> require return statements to either always or never specify values

✓ Enabled (error)
✖ Disabled

```javascript

// Bad
/*
function doSomething(condition) {
if (condition) {
return true;
} else {
return;
}
}
*/

// Good
function doSomething(condition) {
Expand Down Expand Up @@ -662,14 +658,16 @@ Object.prototype.extra = 55;
var boundGetName = (function getName() {
return 'ESLint';
}).bind({ name: 'ESLint' });
console.log(boundGetName()); // "ESLint"
console.log(boundGetName());
// "ESLint"
*/

// Good
var boundGetName2 = (function getName() {
return this.name;
}).bind({ name: 'ESLint' });
console.log(boundGetName2()); // "ESLint"
console.log(boundGetName2());
// "ESLint"

```
<br />
Expand Down Expand Up @@ -769,17 +767,19 @@ var num3 = -0.7;
> disallow the type conversions with shorter notations

&#10006; Disabled
&#10003; Enabled (error)

```javascript

// Bad
/*
var b = !!foo;
var b = ~foo.indexOf('.');
var n = +foo;
var n = 1 * foo;
var s = '' + foo;
foo += '';
*/

// Good
var b = Boolean(foo);
Expand Down Expand Up @@ -1138,16 +1138,14 @@ var num = 07;
> disallow reassignment of function parameters + disallow parameter object manipulation

&#10003; Enabled (error)
&#10006; Disabled

```javascript

// Bad
/*
function foo(bar) {
bar = 13;
}
*/

```
<br />
Expand Down Expand Up @@ -1290,7 +1288,8 @@ a = b += 5, a + b;
*/

// Good
var a = (3, 5); // a = 5
var a = (3, 5);
// a = 5
a = (b += 5, a + b);

```
Expand Down Expand Up @@ -1472,7 +1471,7 @@ let bar = /:/;
> disallow use of void operator

&#10006; Disabled
&#10003; Enabled (error)

```javascript

Expand Down Expand Up @@ -1561,7 +1560,7 @@ var num = parseInt('71', 10);
> requires to declare all vars on top of their containing scope

&#10003; Enabled (error)
&#10006; Disabled

```javascript

Expand Down
127 changes: 125 additions & 2 deletions documentation/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,45 @@

&#10003; Enabled (error)

```javascript

// Bad
/*
if (a){
b();
}
function a(){}
for (;;) {
b();
}
try {} catch (a){}
class Foo{
constructor(){}
}
*/

// Good
if (a) {
b();
}

function a() {}

for (;;) {
b();
}

try {} catch (a) {}

class Foo {
constructor() {}
}

```
<br />


Expand All @@ -702,6 +741,53 @@

&#10003; Enabled (error)

```javascript

// Bad
/*
function foo () {
// ...
}
var bar = function() {
// ...
};
class Foo {
constructor () {
// ...
}
}
var foo = {
bar () {
// ...
}
};
*/

// Good
function foo() {
// ...
}

var bar = function () {
// ...
};

class Foo {
constructor() {
// ...
}
}

var foo = {
bar() {
// ...
}
};

```
<br />


Expand All @@ -713,6 +799,19 @@

&#10003; Enabled (error)

```javascript

// Bad
/*
foo( 'bar' );
var x = ( 1 + 2 ) * 3;
*/

// Good
foo('bar');
var x = (1 + 2) * 3;

```
<br />


Expand All @@ -724,6 +823,15 @@

&#10003; Enabled (error)

```javascript

// Bad
/*
var sum = 1+2;
*/
var sum = 1 + 2;

```
<br />


Expand Down Expand Up @@ -755,7 +863,7 @@
> require or disallow the Unicode Byte Order Mark

&#10003; Enabled (error)
&#10006; Disabled

<br />

Expand All @@ -766,8 +874,23 @@
> require regex literals to be wrapped in parentheses

&#10006; Disabled
&#10003; Enabled (error)

```javascript

// Bad
/*
function a() {
return /foo/.test('bar');
}
*/

// Good
function a() {
return (/foo/).test('bar');
}

```
<br />


2 changes: 1 addition & 1 deletion rules/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = {

// Validate props indentation in JSX
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md
'react/jsx-indent-props': [2, 2],
'react/jsx-indent-props': [2, 'tab'],

// Validate JSX has key prop when in array or iterator
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-key.md
Expand Down
Loading

0 comments on commit bca5c6c

Please sign in to comment.