diff --git a/conversejs/.eslintrc.json b/conversejs/.eslintrc.json index 4ad2d1a6..bd9288c4 100644 --- a/conversejs/.eslintrc.json +++ b/conversejs/.eslintrc.json @@ -1,23 +1,40 @@ { - "root": true, - "env": { - "browser": true, - "es6": true - }, - "extends": [ - "standard" + "root": true, + "env": { + "browser": true, + "es6": true + }, + "extends": [ + "standard-with-typescript" + ], + "globals": {}, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 2018, + "project": [ + "./conversejs/tsconfig.json" + ] + }, + "plugins": [ + "@typescript-eslint" + ], + "ignorePatterns": [], + "rules": { + "@typescript-eslint/no-unused-vars": [2, {"argsIgnorePattern": "^_"}], + "@typescript-eslint/no-floating-promises": "error", + "@typescript-eslint/no-misused-promises": "error", + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/strict-boolean-expressions": "off", + "@typescript-eslint/return-await": [2, "in-try-catch"], // FIXME: correct? + "@typescript-eslint/no-invalid-void-type": "off", + "@typescript-eslint/triple-slash-reference": "off", + "max-len": [ + "error", + { + "code": 120, + "comments": 120 + } ], - "globals": {}, - "plugins": [], - "ignorePatterns": [], - "rules": { - "max-len": [ - "error", - { - "code": 120, - "comments": 120 - } - ], - "no-unused-vars": [2, {"argsIgnorePattern": "^_"}] - } + "no-unused-vars": "off" +} } diff --git a/conversejs/builtin.js b/conversejs/builtin.ts similarity index 86% rename from conversejs/builtin.js rename to conversejs/builtin.ts index ee92bf40..bb72de3c 100644 --- a/conversejs/builtin.js +++ b/conversejs/builtin.ts @@ -1,4 +1,12 @@ -function inIframe () { +// eslint-disable-next-line @typescript-eslint/no-unused-vars +interface Window { + converse: { + initialize: (args: any) => void + } + initConverse: (args: any) => void +} + +function inIframe (): boolean { try { return window.self !== window.top } catch (e) { diff --git a/conversejs/tsconfig.json b/conversejs/tsconfig.json new file mode 100644 index 00000000..21014bdc --- /dev/null +++ b/conversejs/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "es6", + "target": "es5", + "allowJs": true, + "sourceMap": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "alwaysStrict": true, // should already be true because of strict:true + "noImplicitAny": true, // should already be true because of strict:true + "noImplicitThis": true, // should already be true because of strict:true + "noImplicitReturns": true, + "strictBindCallApply": true, // should already be true because of strict:true + "noUnusedLocals": true, + "outDir": "../dist/client", + "paths": { + "shared/*": ["../shared/*"] + } + }, + "include": [ + "./**/*", + "../shared/**/*" + ], + "exclude": [] +} diff --git a/webpack.config.js b/webpack.config.js index a07c45e7..1362d4a9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -42,8 +42,16 @@ let config = clientFiles.map(f => ({ })) config.push({ - entry: "./conversejs/builtin.js", + entry: "./conversejs/builtin.ts", devtool: process.env.NODE_ENV === 'dev' ? 'eval-source-map' : false, + module: { + rules: [ + { + test: /\.tsx?$/, + use: 'ts-loader' + } + ] + }, output: { path: path.resolve(__dirname, "./dist/client/static"), filename: "./builtin.js"