Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Narazaka committed Jan 14, 2018
1 parent 87c3a7d commit ef08559
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
23 changes: 16 additions & 7 deletions lib/shiorif.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {EventEmitter} from "events";
import {ShioriConverter} from "shiori_converter";
import {ShioriTransaction} from "shiori_transaction";
import { EventEmitter } from "events";
import { ShioriConverter } from "shiori_converter";
import { ShioriTransaction } from "shiori_transaction";
import * as ShioriJK from "shiorijk";
import {Shiori} from "shioriloader";
import { Shiori } from "shioriloader";

/** The convenient SHIORI Shared Library Interface */
export class Shiorif extends EventEmitter {
Expand All @@ -14,8 +14,9 @@ export class Shiorif extends EventEmitter {
static referencesFromArray(headersArray: string[]) {
const headers: {[name: string]: string} = {};
headersArray.forEach((header, index) => {
if (header != null) headers[`Reference${index}`] = header;
if (header != null) headers[`Reference${index}`] = header; // tslint:disable-line no-null-keyword
});

return headers;
}

Expand Down Expand Up @@ -93,9 +94,11 @@ export class Shiorif extends EventEmitter {
*/
load(dirpath: string) {
this.emit("load", dirpath);

return this.shiori.load(dirpath).then((status) => {
this.emit("loaded", status);
if (!status) throw new Shiorif.StatusError();

return status;
});
}
Expand All @@ -118,18 +121,20 @@ export class Shiorif extends EventEmitter {
? transaction.request.to(this.autoConvertRequestVersion)
: transaction.request;
for (const name in this.defaultHeaders) {
if (useRequest.headers.header[name] == null) {
if (useRequest.headers.header[name] == null) { // tslint:disable-line no-null-keyword
useRequest.headers.header[name] = this.defaultHeaders[name];
}
}
if (this.autoAdjustToResponseCharset && this._lastResponseCharset) {
useRequest.headers.header["Charset"] = this._lastResponseCharset;
}

return this.shiori.request(useRequest.toString())
.then((response) => {
transaction.setResponse(this._responseParser.parse(response));
this._lastResponseCharset = transaction.response.headers.header["Charset"];
this.emit("response", transaction);

return transaction;
});
}
Expand All @@ -148,8 +153,9 @@ export class Shiorif extends EventEmitter {
version: "3.0",
method,
},
headers: Object.assign({ID: id}, headers instanceof Array ? Shiorif.referencesFromArray(headers) : headers),
headers: {ID: id, ...(headers instanceof Array ? Shiorif.referencesFromArray(headers) : headers)},
});

return this.request(request, convert);
}

Expand All @@ -168,6 +174,7 @@ export class Shiorif extends EventEmitter {
},
headers: headers instanceof Array ? Shiorif.referencesFromArray(headers) : headers,
});

return this.request(request, convert);
}

Expand Down Expand Up @@ -211,9 +218,11 @@ export class Shiorif extends EventEmitter {
*/
unload() {
this.emit("unload");

return this.shiori.unload().then((status) => {
this.emit("unloaded", status);
if (!status) throw new Shiorif.StatusError();

return status;
});
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
"doc": "typedoc --mode file --out doc --readme Readme.md --disableOutputCheck --excludeNotExported lib && cd doc && git status && cd .."
},
"dependencies": {
"shiori_converter": "^2.0.1",
"shiori_transaction": "^2.0.3",
"shiorijk": "^1.0.1"
"shiorijk": "^1.0.1",
"shioriloader": "^2.0.1"
},
"devDependencies": {
"@types/mocha": "^2.2.46",
Expand All @@ -58,7 +60,6 @@
"mocha": "^4.1.0",
"nyc": "^11.4.1",
"power-assert": "^1.4.4",
"shioriloader": "^2.0.0",
"shx": "^0.2.2",
"ts-loader": "^3.2.0",
"tslint": "^5.9.1",
Expand Down
11 changes: 6 additions & 5 deletions test/basic.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/// <reference types="mocha" />
// tslint:disable no-implicit-dependencies
import * as assert from "power-assert";
import {Shiori} from "shioriloader";
import {Shiorif} from "../lib/shiorif";
import { Shiori } from "shioriloader";
import { Shiorif } from "../lib/shiorif";

class TestShiori implements Shiori {
load(_: string) {
load(_: string) { // tslint:disable-line prefer-function-over-method
return Promise.resolve(1);
}

unload() {
unload() { // tslint:disable-line prefer-function-over-method
return Promise.resolve(1);
}

request(_: string) {
request(_: string) { // tslint:disable-line prefer-function-over-method
return Promise.resolve("");
}
}
Expand Down
26 changes: 17 additions & 9 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
{
"extends": [
"tslint:recommended"
"tslint:all"
],
"rules": {
"member-access": [
false
],
"interface-name": [
false
],
"typedef": false,
"member-access": false,
"interface-name": false,
"no-namespace": false,
"curly": false,
"variable-name": [true, "allow-leading-underscore"],
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore"],
"no-string-literal": false,
"object-literal-sort-keys": false,
"max-classes-per-file": [
false
]
],
"member-ordering": false,
"newline-per-chained-call": false,
"triple-equals": [
true,
"allow-null-check"
],
"completed-docs": false,
"strict-type-predicates": false,
"strict-boolean-expressions": false,
"no-unsafe-any": false,
"promise-function-async": false
}
}

0 comments on commit ef08559

Please sign in to comment.