Merge pull request #492 from arv/eslint

Add ESLint to js2
This commit is contained in:
Erik Arvidsson
2015-10-28 12:03:47 -04:00
6 changed files with 43 additions and 12 deletions

27
js2/.eslintrc Normal file
View File

@@ -0,0 +1,27 @@
{
"parser": "babel-eslint",
"rules": {
"camelcase": 2,
"eqeqeq": 2,
"indent": [2, 2],
"linebreak-style": [2, "unix"],
"no-new-wrappers": 2,
"no-var": 2,
"quotes": [2, "single"],
"radix": 2,
"semi": 2
},
"env": {
"es6": true,
"node": true,
"browser": true
},
"extends": "eslint:recommended",
"ecmaFeatures": {
"jsx": true,
"experimentalObjectRestSpread": true
},
"plugins": [
"react"
]
}

View File

@@ -7,13 +7,16 @@
},
"devDependencies": {
"babel": "^5.6.23",
"babel-eslint": "^4.1.3",
"chai": "^3.2.0",
"eslint": "^1.7.3",
"eslint-plugin-react": "^3.6.3",
"mocha": "^2.3.0"
},
"scripts": {
"start": "babel -w src/ -d dist/",
"build": "babel src/ -d dist/",
"pretest": "babel src/ -d dist/; flow",
"pretest": "eslint src/ && flow src/ && babel src/ -d dist/",
"test": "mocha --ui tdd dist/"
}
}

View File

@@ -19,7 +19,7 @@ suite('Chunk', () => {
let ref = Ref.parse('sha1-0000000000000000000000000000000000000001');
let c = new Chunk('abc', ref);
assert.strictEqual(c.data, 'abc');
assert.isTrue(c.ref.equals(Ref.parse('sha1-0000000000000000000000000000000000000001')))
assert.isTrue(c.ref.equals(Ref.parse('sha1-0000000000000000000000000000000000000001')));
assert.isFalse(c.isEmpty());
});

View File

@@ -28,8 +28,8 @@ class MemoryStore {
}
async get(ref: Ref): Promise<Chunk> {
var c = this._data[ref.toString()];
if (c == null) {
let c = this._data[ref.toString()];
if (!c) {
c = Chunk.emptyChunk;
}
@@ -37,7 +37,7 @@ class MemoryStore {
}
async has(ref: Ref): Promise<boolean> {
return this._data[ref.toString()] == null;
return this._data[ref.toString()] !== undefined;
}
put(c: Chunk) {

View File

@@ -11,6 +11,7 @@ const MemoryStore = require('./memory_store.js');
suite('MemoryStore', () => {
async function assertInputInStore(input: string, ref: Ref, ms: MemoryStore) {
assert.isTrue(await ms.has(ref));
let chunk = await ms.get(ref);
assert.isFalse(chunk.isEmpty());
assert.strictEqual(input, chunk.data);
@@ -25,8 +26,8 @@ suite('MemoryStore', () => {
// See http://www.di-mgt.com.au/sha_testvectors.html
assert.strictEqual('sha1-a9993e364706816aba3e25717850c26c9cd0d89d', c.ref.toString());
let oldRoot = await ms.getRoot()
let result = await ms.updateRoot(c.ref, oldRoot);
let oldRoot = await ms.getRoot();
await ms.updateRoot(c.ref, oldRoot);
await assertInputInStore(input, c.ref, ms);
// Re-writing the same data should be idempotent and should not result in a second put

View File

@@ -12,7 +12,7 @@ function uint8ArrayToHex(a: Uint8Array): string {
let hex = '';
for (let i = 0; i < a.length; i++) {
let v = a[i].toString(16);
if (v.length == 1) {
if (v.length === 1) {
hex += '0' + v;
} else {
hex += v;
@@ -26,7 +26,7 @@ function hexToUint8(s: string): Uint8Array {
let digest = new Uint8Array(sha1Size);
for (let i = 0; i < sha1Size; i++) {
let ch = s.substring(i*2, i*2 + 2);
digest[i] = parseInt(ch, 16)
digest[i] = parseInt(ch, 16);
}
return digest;
@@ -41,7 +41,7 @@ class Ref {
isEmpty(): boolean {
for (let i = 0; i < sha1Size; i++) {
if (this.digest[i] != 0) {
if (this.digest[i] !== 0) {
return false;
}
}
@@ -51,7 +51,7 @@ class Ref {
equals(other: Ref): boolean {
for (let i = 0; i < sha1Size; i++) {
if (this.digest[i] != other.digest[i]) {
if (this.digest[i] !== other.digest[i]) {
return false;
}
}
@@ -65,7 +65,7 @@ class Ref {
static parse(s: string): Ref {
let m = s.match(pattern);
if (m == null) {
if (!m) {
throw Error('Could not parse ref: ' + s);
}