Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define a max line length of 100 characters #639

Merged
merged 5 commits into from
Dec 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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