Skip to content

Commit b121583

Browse files
committed
JS: explain camel case & ES6 rules (#39)
1 parent 353d24d commit b121583

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

javascript/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ This repo contains an `eslintrc.js` file that should be included (as
66
`.eslintrc.js`) in each project. Periodically, a repo's `.eslintrc.js` file
77
should be synced with the one here.
88

9+
### Variable and Function Names
10+
11+
Names of variables and functions should be CamelCased. This may not be
12+
practical to enforce automatically with ESLint on all projects, since code
13+
interacting with APIs will frequently need to snake\_case object properties for
14+
API queries and such. In those cases, only use snake\_case when interacting
15+
directly with the API, either querying or handling a response. If an API
16+
response is being transformed into a model-like object, key names should change
17+
to CamelCase at that boundary. E.g.:
18+
19+
```
20+
api.getModel("id").then(function(data) {
21+
var model = new Model();
22+
model.keyName = data.key_name;
23+
return model;
24+
});
25+
```
26+
927
### JQuery
1028

1129
- Prefer `return false` over `event.preventDefault()` when you don't need the
@@ -24,3 +42,18 @@ should be synced with the one here.
2442
return false;
2543
});
2644
```
45+
46+
### ECMAScript 6
47+
48+
There is an additional set of ESLint rules we use for ES6 code: these are in
49+
`eslintrc-es6.js`, and can be included into the main `.eslintrc.js` file in ES6
50+
projects with an `"extends"` directive.
51+
52+
The rules there are mostly self explanatory, with one perhaps requiring an
53+
explanatory note: `=>` functions are preferred over the `var self = this;`
54+
pattern, but not in all cases, as there are good reasons *not* to use `=>`
55+
sometimes. The `consistent-this` rule makes it feasible to flag these
56+
non-preferred usages without causing false positives on other cases, though
57+
this isn't the strictly intended purpose of the rule. This does not mean that
58+
`=>` should not be used in any other cases, only that whether to use it or not
59+
in other cases is a judgment call.

javascript/eslintrc-es6.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
"rules": {
3+
"consistent-this": [2, "prefer-fat-arrow-over-reassigning-this"],
4+
"no-const-assign": 2,
5+
"no-var": 2,
6+
"prefer-const": 2,
7+
"prefer-spread": 2,
8+
"prefer-template": 2
9+
}
10+
};

0 commit comments

Comments
 (0)