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");
}
let dict = new Dict<string, V>(opts);
for (const key in obj) {
dict.set(key, obj[key]);
}
const dict = new Dict<string, V>(opts);
_.each(obj, function (val: V, key: string) {
dict.set(key, val);
});
return dict;
}
@ -56,7 +57,7 @@ export class Dict<K, V> {
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) {
dict.set(key, true);
}
@ -67,14 +68,14 @@ export class Dict<K, V> {
private _munge(key: K): string | undefined {
if (key === undefined) {
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;
}
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 };
return dict;
}
@ -82,7 +83,7 @@ export class Dict<K, V> {
get(key: K): V | undefined {
const mapping = this._items[this._munge(key)];
if (mapping === undefined) {
return undefined;
return;
}
return mapping.v;
}
@ -122,7 +123,7 @@ export class Dict<K, V> {
items(): [K, V][] {
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 {

View File

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

View File

@ -8,7 +8,7 @@ const assets = require('./webpack.assets.json');
// Adds on css-hot-loader in dev mode
function getHotCSS(bundle:any[], isProd:boolean) {
if(isProd) {
if (isProd) {
return bundle;
}
return [
@ -18,7 +18,7 @@ function getHotCSS(bundle:any[], isProd:boolean) {
export default (env?: string) : webpack.Configuration => {
const production: boolean = env === "production";
let config: webpack.Configuration = {
const config: webpack.Configuration = {
mode: production ? "production" : "development",
context: resolve(__dirname, "../"),
entry: assets,
@ -29,8 +29,8 @@ export default (env?: string) : webpack.Configuration => {
test: /\.tsx?$/,
loader: 'ts-loader',
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.
// 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
test: /(\.min|min\.|zxcvbn)\.js/,
use: [ 'script-loader' ],
use: ['script-loader'],
},
// regular css files
{
@ -49,10 +49,10 @@ export default (env?: string) : webpack.Configuration => {
{
loader: 'css-loader',
options: {
sourceMap: true
sourceMap: true,
},
},
], production)
], production),
},
// sass / scss loader
{
@ -62,15 +62,15 @@ export default (env?: string) : webpack.Configuration => {
{
loader: 'css-loader',
options: {
sourceMap: true
}
sourceMap: true,
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
sourceMap: true,
},
},
], production),
},
// load fonts and files
@ -80,10 +80,10 @@ export default (env?: string) : webpack.Configuration => {
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'files/'
}
}]
}
outputPath: 'files/',
},
}],
},
],
},
output: {
@ -111,8 +111,8 @@ export default (env?: string) : webpack.Configuration => {
var importsOptions = [
{
path: "../static/third/spectrum/spectrum.js",
args: "this=>window"
}
args: "this=>window",
},
];
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/to-markdown/dist/to-markdown.js", name: 'toMarkdown' },
{ 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));
@ -149,17 +149,17 @@ export default (env?: string) : webpack.Configuration => {
// This is a special case in order to produce
// a static CSS file to be consumed by
// static/html/5xx.html
if(data.chunk.name === 'error-styles') {
if (data.chunk.name === 'error-styles') {
return 'error-styles.css';
}
return '[name].[contenthash].css';
},
chunkFilename: "[chunkhash].css"
})
chunkFilename: "[chunkhash].css",
}),
];
} else {
// 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.plugins = [
@ -171,15 +171,15 @@ export default (env?: string) : webpack.Configuration => {
// Extract CSS from files
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[chunkhash].css"
chunkFilename: "[chunkhash].css",
}),
];
config.devServer = {
clientLogLevel: "error",
stats: "errors-only",
watchOptions: {
poll: 100
}
poll: 100,
},
};
}
return config;