Skip to content

Commit

Permalink
Merge pull request #639 from chrisngobanh/max-len
Browse files Browse the repository at this point in the history
[eslint config] [breaking] Define a max line length of 100 characters
  • Loading branch information
ljharb committed Dec 24, 2015
2 parents fbf81eb + e2e4724 commit 6d00939
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ Other Style Guides
const name = 'Capt. Janeway';
```
- [6.2](#6.2) <a name='6.2'></a> Strings longer than 100 characters should be written across multiple lines using string concatenation.
- [6.2](#6.2) <a name='6.2'></a> Strings that cause the line to go over 100 characters should be written across multiple lines using string concatenation.
- [6.3](#6.3) <a name='6.3'></a> Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40).
```javascript
Expand Down Expand Up @@ -1692,6 +1692,31 @@ Other Style Guides
// good
const foo = { clark: 'kent' };
```
- [18.12](#18.12) <a name='18.12'></a> Avoid having lines of code that are longer than 100 characters (including whitespace).
> Why? This ensures readability and maintainability.

eslint rules: [`max-len`](http://eslint.org/docs/rules/max-len.html).

```javascript
// bad
const foo = 'Whatever national crop flips the window. The cartoon reverts within the screw. Whatever wizard constrains a helpful ally. The counterpart ascends!';
// bad
$.ajax({ method: 'POST', url: 'https://airbnb.com/', data: { name: 'John' } }).done(() => console.log('Congratulations!')).fail(() => console.log('You have failed this city.'));
// good
const foo = 'Whatever national crop flips the window. The cartoon reverts within the screw. ' +
'Whatever wizard constrains a helpful ally. The counterpart ascends!';
// good
$.ajax({
method: 'POST',
url: 'https://airbnb.com/',
data: { name: 'John' },
})
.done(() => console.log('Congratulations!'))
.fail(() => console.log('You have failed this city.'));
```

**[⬆ back to top](#table-of-contents)**

Expand Down
4 changes: 2 additions & 2 deletions linters/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
// Prohibit use of a variable before it is defined.
"latedef": true,

// Enforce line length to 80 characters
"maxlen": 80,
// Enforce line length to 100 characters
"maxlen": 100,

// Require capitalized names for constructor functions.
"newcap": true,
Expand Down
2 changes: 0 additions & 2 deletions packages/eslint-config-airbnb/rules/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module.exports = {
'rules': {
// specify the maximum depth that blocks can be nested
'max-depth': [0, 4],
// specify the maximum length of a line in your program
'max-len': [0, 80, 4],
// limits the number of parameters that can be used in the function declaration.
'max-params': [0, 3],
// specify the maximum number of statement allowed in a function
Expand Down
12 changes: 12 additions & 0 deletions packages/eslint-config-airbnb/rules/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ module.exports = {
'lines-around-comment': 0,
// disallow mixed 'LF' and 'CRLF' as linebreaks
'linebreak-style': 0,
// specify the maximum length of a line in your program
// https://github.com/eslint/eslint/blob/master/docs/rules/max-len.md
'max-len': [2, {
'code': 100,
'comments': 100,
'commentLength': 100,
'tabWidth': 2,
'ignoreUrls': false,
'ignorePattern': null,
'ignoreTrailingComments': false,
'ignoreComments': false
}],
// specify the maximum depth callbacks can be nested
'max-nested-callbacks': 0,
// require a capital letter for constructors
Expand Down

0 comments on commit 6d00939

Please sign in to comment.