mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 08:38:08 -05:00
Merge pull request #639 from chrisngobanh/max-len
[eslint config] [breaking] Define a max line length of 100 characters
This commit is contained in:
27
README.md
27
README.md
@@ -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
|
||||
@@ -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)**
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user