Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
chore: partially fix eslint errors
  • Loading branch information
uetchy committed Dec 14, 2019
1 parent 1581f9e commit 6387595
Show file tree
Hide file tree
Showing 25 changed files with 138 additions and 107 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
@@ -0,0 +1 @@
module.exports = {};
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.vscode

# Created by https://www.gitignore.io/api/node
# Edit at https://www.gitignore.io/?templates=node
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -21,6 +21,7 @@
"version:up:dry": "lerna version --conventional-commits --changelog-preset=angular --no-git-tag-version --no-push --no-commit-hooks"
},
"devDependencies": {
"eslint": "^6.7.2",
"husky": "^3.1.0",
"lerna": "^3.19.0",
"npm-run-all": "^4.1.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/.eslintrc.js
Expand Up @@ -11,6 +11,7 @@ module.exports = {
},
globals: {
DEBUG: true,
globalThis: false,
},
extends: [
"eslint:recommended",
Expand Down Expand Up @@ -146,7 +147,7 @@ module.exports = {
// "block-spacing": "off",
// "brace-style": "off",
// "camelcase": "off",
"comma-dangle": "error",
"comma-dangle": ["error", "only-multiline"],
"comma-spacing": "error",
"comma-style": ["error", "last"],
// "computed-property-spacing": "off",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/package.json
Expand Up @@ -9,7 +9,7 @@
"clean": "shx rm -rf lib .cache",
"dev": "NODE_ENV=development webpack -w",
"format": "prettier --write \"{*.{js,md,json},{src,types,test,resources}/**/*.{ts,js,html}}\"",
"lint": "eslint --ext .ts src",
"lint": "eslint --ext .ts src -f codeframe",
"prepare": "./scripts/build-documents.sh",
"test": "karma start test/conf/karma-local.conf.js",
"test-sauce": "test -z \"$SAUCE_USERNAME\" || karma start test/conf/karma-sauce.conf.js",
Expand Down Expand Up @@ -46,6 +46,7 @@
"bugs": {
"url": "https://github.com/vivliostyle/vivliostyle/issues"
},
"types": "lib/vivliostyle.d.ts",
"files": [
"doc/supported-features.md",
"doc/supported-features.html",
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/ts/vivliostyle.ts
Expand Up @@ -16,10 +16,16 @@
*
*/

export { PageProgression, PageSide, ReadyState } from "./vivliostyle/constants";
export { registerHook, removeHook } from "./vivliostyle/plugin";
export { Profiler } from "./vivliostyle/profile";
export { Viewer, PageViewMode, ZoomType } from "./vivliostyle/viewer";
export { printHTML } from "./vivliostyle/print";

// leave 'export default' clause for backward compatibility
import { constants } from "./vivliostyle/constants";
import { plugin } from "./vivliostyle/plugin";
import { profile } from "./vivliostyle/profile";
import { viewer } from "./vivliostyle/viewer";
import { printHTML } from "./vivliostyle/print";

export default { constants, plugin, profile, viewer, printHTML };
2 changes: 1 addition & 1 deletion packages/core/src/ts/vivliostyle/break.ts
Expand Up @@ -159,4 +159,4 @@ export function startSideValueToBreakValue(
}
}

Plugin.plugin.registerHook("SIMPLE_PROPERTY", convertPageBreakAliases);
Plugin.registerHook("SIMPLE_PROPERTY", convertPageBreakAliases);
4 changes: 2 additions & 2 deletions packages/core/src/ts/vivliostyle/print.ts
@@ -1,7 +1,7 @@
// Johannes Wilm
// Vivliostyle Foundation

import { viewer } from "./viewer";
import { Viewer as CoreViewer } from "./viewer";
import viewportCss from "../../../resources/vivliostyle-viewport.css";
import viewportScreenCss from "../../../resources/vivliostyle-viewport-screen.css";

Expand Down Expand Up @@ -101,7 +101,7 @@ class VivliostylePrint {
type: "text/html",
}),
docURL = URL.createObjectURL(docBlob),
Viewer = new viewer.Viewer(
Viewer = new CoreViewer(
{
viewportElement: this.iframeWin.document.body
.firstElementChild as HTMLElement,
Expand Down
3 changes: 2 additions & 1 deletion packages/core/tsconfig-es5.json
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "es5"
"target": "es5",
"declaration": true
}
}
4 changes: 2 additions & 2 deletions packages/core/tsconfig.json
Expand Up @@ -14,11 +14,11 @@
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declaration": true /* Generates corresponding '.d.ts' file. */,
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true /* Generates corresponding '.map' file. */,
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
"outDir": "./lib" /* Redirect output structure to the directory. */,
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
Expand Down
1 change: 0 additions & 1 deletion packages/core/webpack.config.js
Expand Up @@ -51,7 +51,6 @@ const config = (outputFilename, tsConfigName) => ({
loader: "ts-loader",
options: {
configFile: tsConfigName,
transpileOnly: true,
experimentalWatchApi: false,
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/viewer/package.json
Expand Up @@ -11,7 +11,7 @@
"dev:webpack": "NODE_ENV=development webpack -w",
"format": "prettier --write \"{*.{js,md,json},{src,test}/**/*.{ts,js}}\"",
"lint": "run-p lint:*",
"lint:scripts": "eslint src/ts --ext .ts",
"lint:scripts": "eslint src/ts --ext .ts -f codeframe",
"lint:styles": "stylelint src/scss/{*.*,**/*.*}",
"serve": "gulp serve",
"setup-local-vivliostyle": "node scripts/setup-local-vivliostyle.js",
Expand All @@ -29,7 +29,7 @@
"@typescript-eslint/parser": "^2.3.2",
"browser-sync": "^2.26.7",
"circular-dependency-plugin": "^5.2.0",
"eslint": "^6.5.1",
"eslint": "^6.7.2",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^3.1.1",
Expand Down
14 changes: 7 additions & 7 deletions packages/viewer/src/ts/models/page-view-mode.ts
Expand Up @@ -17,7 +17,7 @@
* along with Vivliostyle UI. If not, see <http://www.gnu.org/licenses/>.
*/

import vivliostyle from "./vivliostyle";
import { PageViewMode as CorePageViewMode } from "@vivliostyle/core/lib/vivliostyle/viewer";

export class PageViewModeInstance {
toSpreadViewString() {
Expand All @@ -38,7 +38,7 @@ export class PageViewModeInstance {
throw new Error("Invalid PageViewMode");
}
}
toString() {
toString(): string {
switch (this) {
// FIXME: We want to stop disabling this rule to future
// eslint-disable-next-line @typescript-eslint/no-use-before-define
Expand All @@ -65,7 +65,7 @@ const PageViewMode = {
defaultMode() {
return this.AUTO_SPREAD;
},
fromSpreadViewString(str) {
fromSpreadViewString(str: string) {
switch (str) {
case "true":
return this.SPREAD;
Expand All @@ -76,13 +76,13 @@ const PageViewMode = {
return this.AUTO_SPREAD;
}
},
of(name) {
of(name: string) {
switch (name) {
case vivliostyle.viewer.PageViewMode.SPREAD:
case CorePageViewMode.SPREAD:
return this.SPREAD;
case vivliostyle.viewer.PageViewMode.SINGLE_PAGE:
case CorePageViewMode.SINGLE_PAGE:
return this.SINGLE_PAGE;
case vivliostyle.viewer.PageViewMode.AUTO_SPREAD:
case CorePageViewMode.AUTO_SPREAD:
return this.AUTO_SPREAD;
default:
throw new Error(`Invalid PageViewMode name: ${name}`);
Expand Down
22 changes: 19 additions & 3 deletions packages/viewer/src/ts/models/viewer-options.ts
Expand Up @@ -22,6 +22,22 @@ import ko, { Observable } from "knockout";
import urlParameters from "../stores/url-parameters";
import PageViewMode, { PageViewModeInstance } from "./page-view-mode";
import ZoomOptions, { FitToScreen } from "./zoom-options";
import { ViewerOptions as CoreViewerOptions } from "@vivliostyle/core/lib/vivliostyle/viewer";

type Modify<T, R> = Omit<T, keyof R> & R;
type Resolved<T> = T extends Observable<infer R> ? R : T;
type ResolvedObject<T> = {
[k in keyof T]: Resolved<T[k]>;
};
type ResolvedOptions =
| Modify<
ResolvedObject<Options>,
{
pageViewMode: string;
zoom: number;
}
>
| { fitToScreen: null | boolean };

type Options = {
renderAllPages: Observable<unknown>;
Expand Down Expand Up @@ -154,10 +170,10 @@ class ViewerOptions {
this.zoom(other.zoom());
}

toObject() {
toObject(): CoreViewerOptions {
return {
renderAllPages: this.renderAllPages(),
fontSize: this.fontSize(),
renderAllPages: this.renderAllPages() as boolean,
fontSize: Number(this.fontSize()),
pageViewMode: this.pageViewMode().toString(),
zoom: this.zoom().zoom,
fitToScreen: this.zoom().fitToScreen,
Expand Down
2 changes: 1 addition & 1 deletion packages/viewer/src/ts/models/vivliostyle.ts
Expand Up @@ -38,7 +38,7 @@ class VivliostyleImpl {
this.profile = null;
}

setInstance(vivliostyle: Vivliostyle) {
setInstance(vivliostyle: Vivliostyle): void {
this.viewer = vivliostyle.viewer;
this.constants = vivliostyle.constants;
this.profile = vivliostyle.profile;
Expand Down
34 changes: 16 additions & 18 deletions packages/viewer/src/ts/models/zoom-options.ts
Expand Up @@ -17,8 +17,7 @@
* along with Vivliostyle UI. If not, see <http://www.gnu.org/licenses/>.
*/

import { Viewer as VivliostyleViewer } from "@vivliostyle/core";
import vivliostyle from "./vivliostyle";
import { Viewer, ZoomType } from "@vivliostyle/core";

class ZoomOptions {
zoom: number;
Expand All @@ -29,33 +28,34 @@ class ZoomOptions {
get fitToScreen(): null | boolean {
return null;
}
getCurrentZoomFactor(_viewer?: VivliostyleViewer) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getCurrentZoomFactor(_viewer?: Viewer): number {
return 1;
}
toggleFitToScreen() {
toggleFitToScreen(): ZoomOptions {
return new ZoomOptions(1);
}
zoomIn(viewer: VivliostyleViewer) {
zoomIn(viewer: Viewer): FixedZoomFactor {
// FIXME: We want to stop disabling this rule to future
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return new FixedZoomFactor(this.getCurrentZoomFactor(viewer) * 1.25);
}
zoomOut(viewer: VivliostyleViewer) {
zoomOut(viewer: Viewer): FixedZoomFactor {
// FIXME: We want to stop disabling this rule to future
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return new FixedZoomFactor(this.getCurrentZoomFactor(viewer) * 0.8);
}
zoomToActualSize() {
zoomToActualSize(): FixedZoomFactor {
// FIXME: We want to stop disabling this rule to future
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return new FixedZoomFactor(1);
}
static createDefaultOptions() {
static createDefaultOptions(): FitToScreen {
// FIXME: We want to stop disabling this rule to future
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return new FitToScreen();
}
static createFromZoomFactor(zoom) {
static createFromZoomFactor(zoom): FixedZoomFactor {
// FIXME: We want to stop disabling this rule to future
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return new FixedZoomFactor(zoom);
Expand All @@ -66,28 +66,26 @@ export class FitToScreen extends ZoomOptions {
constructor() {
super(1);
}
get fitToScreen() {
get fitToScreen(): boolean {
return true;
}
toggleFitToScreen() {
toggleFitToScreen(): FixedZoomFactor {
// FIXME: We want to stop disabling this rule to future
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return new FixedZoomFactor(1);
}
getCurrentZoomFactor(viewer: VivliostyleViewer) {
return viewer.queryZoomFactor(
vivliostyle.viewer.ZoomType.FIT_INSIDE_VIEWPORT,
);
getCurrentZoomFactor(viewer: Viewer): number {
return viewer.queryZoomFactor(ZoomType.FIT_INSIDE_VIEWPORT);
}
}
class FixedZoomFactor extends ZoomOptions {
get fitToScreen() {
get fitToScreen(): boolean {
return false;
}
toggleFitToScreen() {
toggleFitToScreen(): FitToScreen {
return new FitToScreen();
}
getCurrentZoomFactor() {
getCurrentZoomFactor(): number {
return this.zoom;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/viewer/src/ts/utils/key-util.ts
Expand Up @@ -34,7 +34,7 @@ const Keys = {
};

// CAUTION: This function covers only part of common keys on a keyboard. Keys not covered by the implementation are identified as KeyboardEvent.key, KeyboardEvent.keyIdentifier, or "Unidentified".
function identifyKeyFromEvent(event) {
function identifyKeyFromEvent(event): typeof Keys[keyof typeof Keys] {
const key = event.key;
const keyIdentifier = event.keyIdentifier;
const location = event.location;
Expand Down
12 changes: 6 additions & 6 deletions packages/viewer/src/ts/utils/string-util.ts
Expand Up @@ -18,22 +18,22 @@
*/

export default {
escapeUnicodeChar(ch) {
escapeUnicodeChar(ch): string {
return `\\u${(0x10000 | ch.charCodeAt(0)).toString(16).substring(1)}`;
},
escapeUnicodeString(str) {
escapeUnicodeString(str): string {
return str.replace(/[^-a-zA-Z0-9_]/g, this.escapeUnicodeChar);
},
percentEncodeAmpersandAndUnencodedPercent(str) {
percentEncodeAmpersandAndUnencodedPercent(str): string {
return str.replace(/%(?![0-9A-Fa-f]{2})/g, "%25").replace(/&/g, "%26");
},
percentEncodeAmpersandAndPercent(str) {
percentEncodeAmpersandAndPercent(str): string {
return str.replace(/%/g, "%25").replace(/&/g, "%26");
},
percentDecodeAmpersandAndPercent(str) {
percentDecodeAmpersandAndPercent(str): string {
return str.replace(/%26/g, "&").replace(/%25/g, "%");
},
percentEncodeForDataURI(str) {
percentEncodeForDataURI(str): string {
return encodeURI(str)
.replace(/#/g, "%23")
.replace(/&/g, "%26");
Expand Down
2 changes: 1 addition & 1 deletion packages/viewer/src/ts/viewmodels/message-dialog.ts
Expand Up @@ -37,7 +37,7 @@ class MessageDialog {
this.visible = ko.pureComputed(() => queue().length > 0);
}

getDisplayMessage(errorInfo: ErrorInfo) {
getDisplayMessage(errorInfo: ErrorInfo): string {
const e = errorInfo.error;
let msg = e && (e.toString() || e.frameTrace || e.stack);
if (msg) {
Expand Down

0 comments on commit 6387595

Please sign in to comment.