typescript: Fix violations of existing eslint rules.

This commit is contained in:
Thomas Ip 2019-03-24 18:54:17 +08:00 committed by Tim Abbott
parent fa0a5ecb33
commit ea9a74fe24
3 changed files with 53 additions and 52 deletions

View File

@ -38,10 +38,11 @@ export class Dict<K, V> {
throw new TypeError("Cannot convert argument to Dict"); throw new TypeError("Cannot convert argument to Dict");
} }
let dict = new Dict<string, V>(opts); const dict = new Dict<string, V>(opts);
for (const key in obj) { _.each(obj, function (val: V, key: string) {
dict.set(key, obj[key]); dict.set(key, val);
} });
return dict; return dict;
} }
@ -56,7 +57,7 @@ export class Dict<K, V> {
throw new TypeError("Argument is not an array"); throw new TypeError("Argument is not an array");
} }
let dict = new Dict<K, V | true>(opts); const dict = new Dict<K, V | true>(opts);
for (const key of arr) { for (const key of arr) {
dict.set(key, true); dict.set(key, true);
} }
@ -67,14 +68,14 @@ export class Dict<K, V> {
private _munge(key: K): string | undefined { private _munge(key: K): string | undefined {
if (key === undefined) { if (key === undefined) {
blueslip.error("Tried to call a Dict method with an undefined key."); blueslip.error("Tried to call a Dict method with an undefined key.");
return undefined; return;
} }
let str_key = ':' + key.toString(); const str_key = ':' + key.toString();
return this._fold_case ? str_key.toLowerCase() : str_key; return this._fold_case ? str_key.toLowerCase() : str_key;
} }
clone(): Dict<K, V> { clone(): Dict<K, V> {
let dict = new Dict<K, V>({fold_case: this._fold_case}); const dict = new Dict<K, V>({fold_case: this._fold_case});
dict._items = { ...this._items }; dict._items = { ...this._items };
return dict; return dict;
} }
@ -82,7 +83,7 @@ export class Dict<K, V> {
get(key: K): V | undefined { get(key: K): V | undefined {
const mapping = this._items[this._munge(key)]; const mapping = this._items[this._munge(key)];
if (mapping === undefined) { if (mapping === undefined) {
return undefined; return;
} }
return mapping.v; return mapping.v;
} }
@ -122,7 +123,7 @@ export class Dict<K, V> {
items(): [K, V][] { items(): [K, V][] {
return _.map(_.values(this._items), return _.map(_.values(this._items),
(mapping: KeyValue<K, V>): [K, V] => [mapping.k, mapping.v]); (mapping: KeyValue<K, V>): [K, V] => [mapping.k, mapping.v]);
} }
num_items(): number { num_items(): number {

View File

@ -11,12 +11,12 @@ interface importLoaderOptions {
path: string; path: string;
args: string; args: string;
} }
function getImportLoaders( optionsArr:Array<importLoaderOptions> ) { function getImportLoaders(optionsArr:Array<importLoaderOptions>) {
let importsLoaders = []; const importsLoaders = [];
for(var loaderEntry of optionsArr) { for (var loaderEntry of optionsArr) {
importsLoaders.push({ importsLoaders.push({
test: require.resolve(loaderEntry.path), test: require.resolve(loaderEntry.path),
use: "imports-loader?" + loaderEntry.args use: "imports-loader?" + loaderEntry.args,
}); });
} }
return importsLoaders; return importsLoaders;
@ -38,21 +38,21 @@ interface exportLoaderOptions {
path: string; path: string;
name?: string | Array<string>; name?: string | Array<string>;
} }
function getExposeLoaders( optionsArr:Array<exportLoaderOptions> ) { function getExposeLoaders(optionsArr:Array<exportLoaderOptions>) {
let exposeLoaders = []; const exposeLoaders = [];
for(var loaderEntry of optionsArr) { for (var loaderEntry of optionsArr) {
let path = loaderEntry.path; const path = loaderEntry.path;
let name = ""; let name = "";
let useArr = []; const useArr = [];
// If no name is provided, infer it // If no name is provided, infer it
if(!loaderEntry.name) { if (!loaderEntry.name) {
name = basename(path, '.js'); name = basename(path, '.js');
useArr.push({loader: 'expose-loader', options: name}); useArr.push({loader: 'expose-loader', options: name});
} else { } else {
// If name is an array // If name is an array
if(Array.isArray(loaderEntry.name)) { if (Array.isArray(loaderEntry.name)) {
for(var exposeName of loaderEntry.name) { for (var exposeName of loaderEntry.name) {
useArr.push({loader: 'expose-loader', options: exposeName}) useArr.push({loader: 'expose-loader', options: exposeName});
} }
// If name is a string // If name is a string
} else { } else {
@ -61,12 +61,12 @@ function getExposeLoaders( optionsArr:Array<exportLoaderOptions> ) {
} }
exposeLoaders.push({ exposeLoaders.push({
test: require.resolve(path), test: require.resolve(path),
use: useArr use: useArr,
}); });
} }
return exposeLoaders; return exposeLoaders;
} }
export { export {
getExposeLoaders, getExposeLoaders,
getImportLoaders getImportLoaders,
} };

View File

@ -8,7 +8,7 @@ const assets = require('./webpack.assets.json');
// Adds on css-hot-loader in dev mode // Adds on css-hot-loader in dev mode
function getHotCSS(bundle:any[], isProd:boolean) { function getHotCSS(bundle:any[], isProd:boolean) {
if(isProd) { if (isProd) {
return bundle; return bundle;
} }
return [ return [
@ -18,7 +18,7 @@ function getHotCSS(bundle:any[], isProd:boolean) {
export default (env?: string) : webpack.Configuration => { export default (env?: string) : webpack.Configuration => {
const production: boolean = env === "production"; const production: boolean = env === "production";
let config: webpack.Configuration = { const config: webpack.Configuration = {
mode: production ? "production" : "development", mode: production ? "production" : "development",
context: resolve(__dirname, "../"), context: resolve(__dirname, "../"),
entry: assets, entry: assets,
@ -29,8 +29,8 @@ export default (env?: string) : webpack.Configuration => {
test: /\.tsx?$/, test: /\.tsx?$/,
loader: 'ts-loader', loader: 'ts-loader',
options: { options: {
configFile: require.resolve('../static/js/tsconfig.json') configFile: require.resolve('../static/js/tsconfig.json'),
} },
}, },
// Uses script-loader on minified files so we don't change global variables in them. // Uses script-loader on minified files so we don't change global variables in them.
// Also has the effect of making processing these files fast // Also has the effect of making processing these files fast
@ -39,7 +39,7 @@ export default (env?: string) : webpack.Configuration => {
{ {
// We dont want to match admin.js // We dont want to match admin.js
test: /(\.min|min\.|zxcvbn)\.js/, test: /(\.min|min\.|zxcvbn)\.js/,
use: [ 'script-loader' ], use: ['script-loader'],
}, },
// regular css files // regular css files
{ {
@ -49,10 +49,10 @@ export default (env?: string) : webpack.Configuration => {
{ {
loader: 'css-loader', loader: 'css-loader',
options: { options: {
sourceMap: true sourceMap: true,
}, },
}, },
], production) ], production),
}, },
// sass / scss loader // sass / scss loader
{ {
@ -62,15 +62,15 @@ export default (env?: string) : webpack.Configuration => {
{ {
loader: 'css-loader', loader: 'css-loader',
options: { options: {
sourceMap: true sourceMap: true,
} },
}, },
{ {
loader: 'sass-loader', loader: 'sass-loader',
options: { options: {
sourceMap: true sourceMap: true,
} },
} },
], production), ], production),
}, },
// load fonts and files // load fonts and files
@ -80,10 +80,10 @@ export default (env?: string) : webpack.Configuration => {
loader: 'file-loader', loader: 'file-loader',
options: { options: {
name: '[name].[ext]', name: '[name].[ext]',
outputPath: 'files/' outputPath: 'files/',
} },
}] }],
} },
], ],
}, },
output: { output: {
@ -111,8 +111,8 @@ export default (env?: string) : webpack.Configuration => {
var importsOptions = [ var importsOptions = [
{ {
path: "../static/third/spectrum/spectrum.js", path: "../static/third/spectrum/spectrum.js",
args: "this=>window" args: "this=>window",
} },
]; ];
config.module.rules.push(...getImportLoaders(importsOptions)); config.module.rules.push(...getImportLoaders(importsOptions));
@ -136,7 +136,7 @@ export default (env?: string) : webpack.Configuration => {
{ path: "../node_modules/handlebars/dist/handlebars.runtime.js", name: 'Handlebars' }, { path: "../node_modules/handlebars/dist/handlebars.runtime.js", name: 'Handlebars' },
{ path: "../node_modules/to-markdown/dist/to-markdown.js", name: 'toMarkdown' }, { path: "../node_modules/to-markdown/dist/to-markdown.js", name: 'toMarkdown' },
{ path: "../node_modules/sortablejs/Sortable.js"}, { path: "../node_modules/sortablejs/Sortable.js"},
{ path: "../node_modules/winchan/winchan.js", name: 'WinChan'} { path: "../node_modules/winchan/winchan.js", name: 'WinChan'},
]; ];
config.module.rules.push(...getExposeLoaders(exposeOptions)); config.module.rules.push(...getExposeLoaders(exposeOptions));
@ -149,17 +149,17 @@ export default (env?: string) : webpack.Configuration => {
// This is a special case in order to produce // This is a special case in order to produce
// a static CSS file to be consumed by // a static CSS file to be consumed by
// static/html/5xx.html // static/html/5xx.html
if(data.chunk.name === 'error-styles') { if (data.chunk.name === 'error-styles') {
return 'error-styles.css'; return 'error-styles.css';
} }
return '[name].[contenthash].css'; return '[name].[contenthash].css';
}, },
chunkFilename: "[chunkhash].css" chunkFilename: "[chunkhash].css",
}) }),
]; ];
} else { } else {
// Out JS debugging tools // Out JS debugging tools
config.entry['common'].push('./static/js/debug.js'); config.entry['common'].push('./static/js/debug.js'); // eslint-disable-line dot-notation
config.output.publicPath = '/webpack/'; config.output.publicPath = '/webpack/';
config.plugins = [ config.plugins = [
@ -171,15 +171,15 @@ export default (env?: string) : webpack.Configuration => {
// Extract CSS from files // Extract CSS from files
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: "[name].css", filename: "[name].css",
chunkFilename: "[chunkhash].css" chunkFilename: "[chunkhash].css",
}), }),
]; ];
config.devServer = { config.devServer = {
clientLogLevel: "error", clientLogLevel: "error",
stats: "errors-only", stats: "errors-only",
watchOptions: { watchOptions: {
poll: 100 poll: 100,
} },
}; };
} }
return config; return config;