Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit 7299d5e

Browse files
authored
Merge pull request #120 from runtimejs/code-style
Update everything to ES6 and adopt a code style
2 parents e5e1496 + a6241b0 commit 7299d5e

112 files changed

Lines changed: 4254 additions & 4101 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
js/deps/
2+
js/modules/inherits.js

.eslintrc

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
extends:
2+
- airbnb-base
3+
4+
globals:
5+
debug: true
6+
__SYSCALL: true
7+
runtime: true
8+
9+
env:
10+
es6: true
11+
node: true
12+
13+
rules:
14+
strict:
15+
- 2
16+
- 'global'
17+
max-len:
18+
- 1
19+
-
20+
code: 100
21+
tabWidth: 2
22+
ignoreComments: true
23+
ignoreUrls: true
24+
consistent-return: 0
25+
no-underscore-dangle: 0
26+
global-require: 0
27+
import/no-extraneous-dependencies: 0
28+
no-return-assign: 1
29+
new-cap: 1
30+
no-console: 0
31+
wrap-iife:
32+
- 2
33+
- 'inside'
34+
no-use-before-define:
35+
- 2
36+
-
37+
functions: false
38+
classes: true
39+
no-param-reassign:
40+
- 2
41+
-
42+
props: false
43+
44+
parserOptions:
45+
ecmaVersion: 6
46+
sourceType: 'script'
47+
ecmaFeatures:
48+
modules: false
49+
defaultParams: true
50+
classes: true
51+
arrowFunctions: true
52+
blockBindings: true
53+
forOf: true
54+
spread: true
55+
templateStrings: true

CONTRIBUTING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Contributing to runtime.js
2+
3+
First off, thanks for deciding to contribute! :+1:
4+
5+
## Got an issue?
6+
7+
* Make sure the issue isn't already reported by checking in [Issues](https://github.com/runtimejs/runtime/issues).
8+
* Include the version of the kernel and JavaScript library in the issue description.
9+
* Include a description of what happens and what the expected behavior is.
10+
11+
## Cool feature request?
12+
13+
* Make sure the feature isn't already requested by checking in [Issues](https://github.com/runtimejs/runtime/issues).
14+
* Include good reasons for why you think it should be added and why it'd be a good feature.
15+
* If possible, include resources (links, examples, etc.) for anyone planning to add the feature.
16+
17+
## Something to improve, add, or fix?
18+
19+
### Kernel change (C++)
20+
21+
Make sure that:
22+
* the kernel is compilable by running `scons` (more information [here](https://github.com/runtimejs/runtime/wiki/Build)).
23+
* the system can still boot up normally.
24+
* the new/fixed/changed feature/bug works (of course, :smile:).
25+
26+
### Library change (JavaScript)
27+
28+
Make sure that:
29+
* you run `npm run lint` at the root of repository (you'll also need to have installed dependencies beforehand with `npm install`) and get rid of any lint before commiting.
30+
* the system can still boot up normally.
31+
* the new/fixed/changed feature/bug works.
32+
* the code is written in as much ES6 as possible and it conforms to the style guide found [here](https://github.com/airbnb/javascript) (with a [few exceptions](docs/code-style-exceptions.md)).

docs/code-style-exceptions.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Code Style Exceptions
2+
3+
The JavaScript code adheres to the style guide found [here](https://github.com/airbnb/javascript), but with some exceptions:
4+
5+
## No ES6 Modules
6+
7+
V8 support for native ES6 modules is under development, so for now use `require` like you would in Node.
8+
All other ES6 features (classes, destructuring, default parameters, etc.) can be used freely.
9+
10+
## Using `for-of` and `for-in`
11+
12+
You're free to use `for-of` and `for-in` as necessary, however it's better to use `for (let value of object)` for values and `for (let key of Object.keys(object))` for keys.
13+
You can still use `for-in`, just be sure you know [the catch](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#Iterating_over_own_properties_only) when using it.
14+
15+
## Using 'dangling' underscores
16+
17+
You *can* use 'dangling' underscores to denote a private member on an object or class.
18+
Some APIs were written before this style was adopted which use underscores for private members and probably won't be changed for compatibility.
19+
However, for any new APIs, it'd be preferred to use a [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) instead, like:
20+
21+
```js
22+
const somePrivateVarName = Symbol('somePrivateVarName');
23+
24+
class Demo {
25+
constructor() {
26+
this[somePrivateVarName] = 'my value';
27+
}
28+
getMyPrivateVar() {
29+
return this[somePrivateVarName];
30+
}
31+
}
32+
```
33+
34+
## Using `get` and `set`
35+
36+
You can (and should) use ES6 `get` and `set` in new APIs, it's already used in various runtime.js APIs.
37+
38+
## Assigning to functions parameters
39+
40+
You cannot reassign *functions parameters*, but you can assign to *properties of* function parameters.
41+
```js
42+
// yes
43+
const demo = (myObject) => {
44+
myObject.someProperty = 'my value';
45+
// ...
46+
}
47+
48+
// no
49+
const demo = (myObject) => {
50+
myObject = {
51+
someProperty: 'my value'
52+
};
53+
// ...
54+
}
55+
```
56+
57+
## Wrapping an IIFE
58+
59+
The invocation should be *outside* the parentheses, not inside.
60+
61+
```js
62+
// yes
63+
(function() {
64+
// ...
65+
})();
66+
67+
// no
68+
(function() {
69+
70+
}());
71+
```

js/.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

js/.eslintrc

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)