mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 13:58:13 -05:00
Compare commits
20 Commits
es5-deprec
...
eslint-con
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fb9f2ec69 | ||
|
|
7d9af14ce4 | ||
|
|
be6e13f7b9 | ||
|
|
fb0f03f676 | ||
|
|
0b8e466397 | ||
|
|
d20f33f660 | ||
|
|
646fa70f59 | ||
|
|
31265099af | ||
|
|
c7d34b526a | ||
|
|
030598db09 | ||
|
|
dc7e7e77f2 | ||
|
|
6d2fc89bd1 | ||
|
|
bfc842e3ad | ||
|
|
f0b31960d3 | ||
|
|
f94f6e21c6 | ||
|
|
6454839e76 | ||
|
|
52a2da4182 | ||
|
|
9ffadff1fd | ||
|
|
a1edac348a | ||
|
|
53b4173b04 |
87
README.md
87
README.md
@@ -7,7 +7,7 @@
|
||||
[](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
|
||||
Other Style Guides
|
||||
- [ES5](es5/)
|
||||
- [ES5 (Deprecated)](https://github.com/airbnb/javascript/tree/es5-deprecated/es5)
|
||||
- [React](react/)
|
||||
- [CSS & Sass](https://github.com/airbnb/css)
|
||||
- [Ruby](https://github.com/airbnb/ruby)
|
||||
@@ -153,43 +153,6 @@ Other Style Guides
|
||||
const item = {};
|
||||
```
|
||||
|
||||
<a name="objects--reserved-words"></a><a name="3.2"></a>
|
||||
- [3.2](#objects--reserved-words) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
const superman = {
|
||||
default: { clark: 'kent' },
|
||||
private: true,
|
||||
};
|
||||
|
||||
// good
|
||||
const superman = {
|
||||
defaults: { clark: 'kent' },
|
||||
hidden: true,
|
||||
};
|
||||
```
|
||||
|
||||
<a name="objects--reserved-words-2"></a><a name="3.3"></a>
|
||||
- [3.3](#objects--reserved-words-2) Use readable synonyms in place of reserved words. jscs: [`disallowIdentifierNames`](http://jscs.info/rule/disallowIdentifierNames)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
const superman = {
|
||||
class: 'alien',
|
||||
};
|
||||
|
||||
// bad
|
||||
const superman = {
|
||||
klass: 'alien',
|
||||
};
|
||||
|
||||
// good
|
||||
const superman = {
|
||||
type: 'alien',
|
||||
};
|
||||
```
|
||||
|
||||
<a name="es6-computed-properties"></a><a name="3.4"></a>
|
||||
- [3.4](#es6-computed-properties) Use computed property names when creating objects with dynamic property names.
|
||||
|
||||
@@ -512,30 +475,32 @@ Other Style Guides
|
||||
// bad
|
||||
const name = "Capt. Janeway";
|
||||
|
||||
// bad - template literals should contain interpolation or newlines
|
||||
const name = `Capt. Janeway`;
|
||||
|
||||
// good
|
||||
const name = 'Capt. Janeway';
|
||||
```
|
||||
|
||||
<a name="strings--line-length"></a><a name="6.2"></a>
|
||||
- [6.2](#strings--line-length) Strings that cause the line to go over 100 characters should be written across multiple lines using string concatenation.
|
||||
- [6.2](#strings--line-length) Strings that cause the line to go over 100 characters should not be written across multiple lines using string concatenation.
|
||||
|
||||
<a name="strings--concat-perf"></a><a name="6.3"></a>
|
||||
- [6.3](#strings--concat-perf) 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).
|
||||
> Why? Broken strings are painful to work with and make code less searchable.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
const errorMessage = 'This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.';
|
||||
|
||||
// bad
|
||||
const errorMessage = 'This is a super long error that was thrown because \
|
||||
of Batman. When you stop to think about how Batman had anything to do \
|
||||
with this, you would get nowhere \
|
||||
fast.';
|
||||
|
||||
// good
|
||||
// bad
|
||||
const errorMessage = 'This is a super long error that was thrown because ' +
|
||||
'of Batman. When you stop to think about how Batman had anything to do ' +
|
||||
'with this, you would get nowhere fast.';
|
||||
|
||||
// good
|
||||
const errorMessage = 'This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.';
|
||||
```
|
||||
|
||||
<a name="es6-template-literals"></a><a name="6.4"></a>
|
||||
@@ -588,7 +553,7 @@ Other Style Guides
|
||||
## Functions
|
||||
|
||||
<a name="functions--declarations"></a><a name="7.1"></a>
|
||||
- [7.1](#functions--declarations) Use function declarations instead of function expressions. jscs: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations)
|
||||
- [7.1](#functions--declarations) Use function declarations instead of function expressions. eslint: [`func-style`](http://eslint.org/docs/rules/func-style) jscs: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations)
|
||||
|
||||
> Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-functions) in place of function expressions.
|
||||
|
||||
@@ -730,7 +695,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="functions--constructor"></a><a name="7.10"></a>
|
||||
- [7.10](#functions--constructor) Never use the Function constructor to create a new function.
|
||||
- [7.10](#functions--constructor) Never use the Function constructor to create a new function. eslint: [`no-new-func`](http://eslint.org/docs/rules/no-new-func)
|
||||
|
||||
> Why? Creating a function in this way evaluates a string similarly to eval(), which opens vulnerabilities.
|
||||
|
||||
@@ -743,7 +708,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="functions--signature-spacing"></a><a name="7.11"></a>
|
||||
- [7.11](#functions--signature-spacing) Spacing in a function signature.
|
||||
- [7.11](#functions--signature-spacing) Spacing in a function signature. eslint: [`space-before-function-paren`](http://eslint.org/docs/rules/space-before-function-paren) [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks)
|
||||
|
||||
> Why? Consistency is good, and you shouldn’t have to add or remove a space when adding or removing a name.
|
||||
|
||||
@@ -799,6 +764,27 @@ Other Style Guides
|
||||
}
|
||||
```
|
||||
|
||||
<a name="functions--spread-vs-apply"></a><a name="7.14"></a>
|
||||
- [7.14](#functions--spread-vs-apply) Prefer the use of the spread operator `...` to call variadic functions. eslint: [`prefer-spread`](http://eslint.org/docs/rules/prefer-spread)
|
||||
|
||||
> Why? It's cleaner, you don't need to supply a context, and you can not easily compose `new` with `apply`.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
const x = [1, 2, 3, 4, 5];
|
||||
console.log.apply(console, x);
|
||||
|
||||
// good
|
||||
const x = [1, 2, 3, 4, 5];
|
||||
console.log(...x);
|
||||
|
||||
// bad
|
||||
new (Function.prototype.bind.apply(Date, [null, 2016, 08, 05]));
|
||||
|
||||
// good
|
||||
new Date(...[2016, 08, 05]);
|
||||
```
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
## Arrow Functions
|
||||
@@ -1334,7 +1320,7 @@ Other Style Guides
|
||||
## Variables
|
||||
|
||||
<a name="variables--const"></a><a name="13.1"></a>
|
||||
- [13.1](#variables--const) Always use `const` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that.
|
||||
- [13.1](#variables--const) Always use `const` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that. eslint: [`no-undef`](http://eslint.org/docs/rules/no-undef) [`prefer-const`](http://eslint.org/docs/rules/prefer-const)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -2362,7 +2348,7 @@ Other Style Guides
|
||||
## Naming Conventions
|
||||
|
||||
<a name="naming--descriptive"></a><a name="22.1"></a>
|
||||
- [22.1](#naming--descriptive) Avoid single letter names. Be descriptive with your naming.
|
||||
- [22.1](#naming--descriptive) Avoid single letter names. Be descriptive with your naming. eslint: [`id-length`](http://eslint.org/docs/rules/id-length)
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -2904,6 +2890,7 @@ Other Style Guides
|
||||
- **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript)
|
||||
- **Springload**: [springload/javascript](https://github.com/springload/javascript)
|
||||
- **StratoDem Analytics**: [stratodem/javascript](https://github.com/stratodem/javascript)
|
||||
- **SteelKiwi Development**: [steelkiwi/javascript](https://github.com/steelkiwi/javascript)
|
||||
- **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/guide-javascript)
|
||||
- **SysGarage**: [sysgarage/javascript-style-guide](https://github.com/sysgarage/javascript-style-guide)
|
||||
- **Syzygy Warsaw**: [syzygypl/javascript](https://github.com/syzygypl/javascript)
|
||||
|
||||
1753
es5/README.md
1753
es5/README.md
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,8 @@
|
||||
5.0.2 / 2016-08-12
|
||||
==================
|
||||
- [deps] update `eslint`, `eslint-find-rules`, `eslint-plugin-import`
|
||||
- [tests] add `safe-publish-latest` to `prepublish`
|
||||
|
||||
5.0.1 / 2016-07-29
|
||||
==================
|
||||
- [patch] `no-unused-expressions`: flesh out options
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "eslint-config-airbnb-base",
|
||||
"version": "5.0.1",
|
||||
"version": "5.0.2",
|
||||
"description": "Airbnb's base JS ESLint config, following our styleguide",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"tests-only": "babel-tape-runner ./test/test-*.js",
|
||||
"prepublish": "(in-install || eslint-find-rules --unused) && (not-in-publish || npm test)",
|
||||
"prepublish": "(in-install || eslint-find-rules --unused) && (not-in-publish || npm test) && safe-publish-latest",
|
||||
"pretest": "npm run --silent lint",
|
||||
"test": "npm run --silent tests-only",
|
||||
"travis": "npm run --silent test"
|
||||
@@ -47,15 +47,16 @@
|
||||
"devDependencies": {
|
||||
"babel-preset-airbnb": "^2.0.0",
|
||||
"babel-tape-runner": "^2.0.1",
|
||||
"eslint": "^3.2.0",
|
||||
"eslint-find-rules": "^1.11.1",
|
||||
"eslint-plugin-import": "^1.12.0",
|
||||
"eslint": "^3.3.0",
|
||||
"eslint-find-rules": "^1.13.0",
|
||||
"eslint-plugin-import": "^1.13.0",
|
||||
"in-publish": "^2.0.0",
|
||||
"safe-publish-latest": "^1.0.1",
|
||||
"tape": "^4.6.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^3.2.0",
|
||||
"eslint-plugin-import": "^1.12.0"
|
||||
"eslint": "^3.3.0",
|
||||
"eslint-plugin-import": "^1.13.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
|
||||
@@ -89,6 +89,10 @@ module.exports = {
|
||||
// disallow the use of leading or trailing decimal points in numeric literals
|
||||
'no-floating-decimal': 2,
|
||||
|
||||
// disallow reassignments of native objects or read-only globals
|
||||
// http://eslint.org/docs/rules/no-global-assign
|
||||
'no-global-assign': [2, { exceptions: [] }],
|
||||
|
||||
// disallow implicit type conversions
|
||||
// http://eslint.org/docs/rules/no-implicit-coercion
|
||||
'no-implicit-coercion': [0, {
|
||||
@@ -136,7 +140,8 @@ module.exports = {
|
||||
'no-multi-str': 2,
|
||||
|
||||
// disallow reassignments of native objects
|
||||
'no-native-reassign': 2,
|
||||
// TODO: deprecated in favor of no-global-assign
|
||||
'no-native-reassign': 0,
|
||||
|
||||
// disallow use of new operator when not part of the assignment or comparison
|
||||
'no-new': 2,
|
||||
|
||||
@@ -64,7 +64,8 @@ module.exports = {
|
||||
'no-irregular-whitespace': 2,
|
||||
|
||||
// disallow negation of the left operand of an in expression
|
||||
'no-negated-in-lhs': 2,
|
||||
// TODO: deprecated in favor of no-unsafe-negation
|
||||
'no-negated-in-lhs': 0,
|
||||
|
||||
// disallow the use of object properties of the global object (Math and JSON) as functions
|
||||
'no-obj-calls': 2,
|
||||
@@ -79,6 +80,11 @@ module.exports = {
|
||||
// disallow sparse arrays
|
||||
'no-sparse-arrays': 2,
|
||||
|
||||
// Disallow template literal placeholder syntax in regular strings
|
||||
// http://eslint.org/docs/rules/no-template-curly-in-string
|
||||
// TODO: enable, semver-major
|
||||
'no-template-curly-in-string': 0,
|
||||
|
||||
// Avoid code that looks like two expressions but is actually one
|
||||
// http://eslint.org/docs/rules/no-unexpected-multiline
|
||||
'no-unexpected-multiline': 2,
|
||||
@@ -90,6 +96,10 @@ module.exports = {
|
||||
// http://eslint.org/docs/rules/no-unsafe-finally
|
||||
'no-unsafe-finally': 2,
|
||||
|
||||
// disallow negating the left operand of relational operators
|
||||
// http://eslint.org/docs/rules/no-unsafe-negation
|
||||
'no-unsafe-negation': 2,
|
||||
|
||||
// disallow comparisons with the value NaN
|
||||
'use-isnan': 2,
|
||||
|
||||
|
||||
@@ -28,6 +28,11 @@ module.exports = {
|
||||
// enforce newline at the end of file, with no multiple empty lines
|
||||
'eol-last': 2,
|
||||
|
||||
// enforce spacing between functions and their invocations
|
||||
// http://eslint.org/docs/rules/func-call-spacing
|
||||
// TODO: enable, semver-minor
|
||||
'func-call-spacing': [0, 'never'],
|
||||
|
||||
// require function expressions to have a name
|
||||
'func-names': 1,
|
||||
|
||||
@@ -264,6 +269,9 @@ module.exports = {
|
||||
// enforce spacing before and after semicolons
|
||||
'semi-spacing': [2, { before: false, after: true }],
|
||||
|
||||
// requires object keys to be sorted
|
||||
'sort-keys': [0, 'asc', { caseSensitive: false, natural: true }],
|
||||
|
||||
// sort variables within the same declaration block
|
||||
'sort-vars': 0,
|
||||
|
||||
|
||||
@@ -1,3 +1,41 @@
|
||||
10.0.1 / 2016-08-12
|
||||
==================
|
||||
- [deps] update `eslint`, `eslint-find-rules`, `eslint-plugin-jsx-a11y`, `eslint-plugin-import`, `eslint-config-airbnb-base`
|
||||
|
||||
10.0.0 / 2016-08-01
|
||||
==================
|
||||
- [breaking] enable jsx-a11y rules:
|
||||
- `jsx-a11y/heading-has-content`
|
||||
- `jsx-a11y/html-has-lang`
|
||||
- `jsx-a11y/lang`
|
||||
- `jsx-a11y/no-marquee`
|
||||
- `jsx-a11y/scope`
|
||||
- `jsx-a11y/href-no-hash`
|
||||
- `jsx-a11y/label-has-for`
|
||||
- [breaking] enable aria rules:
|
||||
- `jsx-a11y/aria-props`
|
||||
- `jsx-a11y/aria-proptypes`
|
||||
- `jsx-a11y/aria-unsupported-elements`
|
||||
- `jsx-a11y/role-has-required-aria-props`
|
||||
- `jsx-a11y/role-supports-aria-props`
|
||||
- [breaking] enable react rules:
|
||||
- `react/jsx-filename-extension`
|
||||
- `react/jsx-no-comment-textnodes`
|
||||
- `react/jsx-no-target-blank`
|
||||
- `react/require-extension`
|
||||
- `react/no-render-return-value`
|
||||
- `react/no-find-dom-node`
|
||||
- `react/no-deprecated`
|
||||
- [deps] [breaking] update `eslint` to v3, `eslint-config-airbnb-base` to v5, `eslint-find-rules`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y` to v2, `eslint-plugin-react` to v6, `tape`. drop node < 4 support.
|
||||
- [deps] update `eslint-config-airbnb-base`, `eslint-plugin-react`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`, `babel-tape-runner`, add `babel-preset-airbnb`. ensure react is `>=` 0.13.0
|
||||
- [patch] loosen `jsx-pascal-case` rule to allow all caps component names
|
||||
- [tests] stop testing < node 4
|
||||
- [tests] use `in-publish` because coffeescript screwed up the prepublish script for everyone
|
||||
- [tests] Only run `eslint-find-rules` on prepublish, not in tests
|
||||
- [tests] Even though the base config may not be up to date in the main package, let’s `npm link` the base package into the main one for the sake of travis-ci tests
|
||||
- [docs] update the peer dep install command to dynamically look up the right version numbers when installing peer deps
|
||||
- add `safe-publish-latest` to `prepublish`
|
||||
|
||||
9.0.1 / 2016-05-08
|
||||
==================
|
||||
- [patch] update `eslint-config-airbnb-base` to v3.0.1
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "eslint-config-airbnb",
|
||||
"version": "9.0.1",
|
||||
"version": "10.0.1",
|
||||
"description": "Airbnb's ESLint config, following our styleguide",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"tests-only": "babel-tape-runner ./test/test-*.js",
|
||||
"prepublish": "(in-install || eslint-find-rules --unused) && (not-in-publish || npm test)",
|
||||
"prepublish": "(in-install || eslint-find-rules --unused) && (not-in-publish || npm test) && safe-publish-latest",
|
||||
"pretest": "npm run --silent lint",
|
||||
"test": "npm run --silent tests-only",
|
||||
"travis": "cd ../eslint-config-airbnb-base && npm install && npm link && cd - && npm link eslint-config-airbnb-base && npm run --silent test ; npm unlink eslint-config-airbnb-base >/dev/null &"
|
||||
@@ -45,24 +45,25 @@
|
||||
},
|
||||
"homepage": "https://github.com/airbnb/javascript",
|
||||
"dependencies": {
|
||||
"eslint-config-airbnb-base": "^5.0.1"
|
||||
"eslint-config-airbnb-base": "^5.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-preset-airbnb": "^2.0.0",
|
||||
"babel-tape-runner": "^2.0.1",
|
||||
"eslint": "^3.2.2",
|
||||
"eslint-find-rules": "^1.11.1",
|
||||
"eslint-plugin-import": "^1.12.0",
|
||||
"eslint-plugin-jsx-a11y": "^2.0.1",
|
||||
"eslint": "^3.3.0",
|
||||
"eslint-find-rules": "^1.13.0",
|
||||
"eslint-plugin-import": "^1.13.0",
|
||||
"eslint-plugin-jsx-a11y": "^2.1.0",
|
||||
"eslint-plugin-react": "^6.0.0",
|
||||
"in-publish": "^2.0.0",
|
||||
"react": ">= 0.13.0",
|
||||
"react": "> 0.13.0",
|
||||
"safe-publish-latest": "^1.0.1",
|
||||
"tape": "^4.6.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^3.2.2",
|
||||
"eslint-plugin-jsx-a11y": "^2.0.1",
|
||||
"eslint-plugin-import": "^1.12.0",
|
||||
"eslint": "^3.3.0",
|
||||
"eslint-plugin-jsx-a11y": "^2.1.0",
|
||||
"eslint-plugin-import": "^1.13.0",
|
||||
"eslint-plugin-react": "^6.0.0"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@@ -7,6 +7,11 @@ module.exports = {
|
||||
jsx: true
|
||||
},
|
||||
rules: {
|
||||
// Enforce that anchors have content
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-has-content.md
|
||||
// TODO: enable, semver-major
|
||||
'jsx-a11y/anchor-has-content': [0, ['']],
|
||||
|
||||
// Require ARIA roles to be valid and non-abstract
|
||||
// https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-role.md
|
||||
'jsx-a11y/aria-role': 2,
|
||||
|
||||
@@ -337,7 +337,7 @@
|
||||
|
||||
// good
|
||||
<Foo
|
||||
ref={(ref) => this.myRef = ref}
|
||||
ref={ref => { this.myRef = ref; }}
|
||||
/>
|
||||
```
|
||||
|
||||
@@ -575,5 +575,6 @@
|
||||
-  **Polish**: [pietraszekl/javascript](https://github.com/pietraszekl/javascript/tree/master/react)
|
||||
-  **Korean**: [apple77y/javascript](https://github.com/apple77y/javascript/tree/master/react)
|
||||
-  **Portuguese**: [ronal2do/javascript](https://github.com/ronal2do/airbnb-react-styleguide)
|
||||
-  **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide)
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
Reference in New Issue
Block a user