From 24218bda051253bf2627e521281eefbe021467e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=A3=E9=87=8C=E5=A5=BD=E8=84=8F=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5?= <453491931@qq.com> Date: Tue, 3 May 2022 21:53:13 +0800 Subject: [PATCH] chore(docs/test): fix code style, remove commented code and replace `var` to `const` (#1874) --- babel.config.js | 40 +++++++++++++------------- docs/en/I18n.md | 2 +- docs/es-es/I18n.md | 2 +- docs/ja/I18n.md | 2 +- docs/ko/I18n.md | 2 +- docs/pt-br/I18n.md | 2 +- docs/zh-cn/I18n.md | 2 +- karma.sauce.conf.js | 11 ++++--- test/plugin/preParsePostFormat.test.js | 23 +++------------ 9 files changed, 35 insertions(+), 51 deletions(-) diff --git a/babel.config.js b/babel.config.js index a0291dac6..2531938f6 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,20 +1,20 @@ -module.exports = { - "env": { - "test": { - "presets": [ - "@babel/preset-env" - ] - }, - "build": { - "presets": [ - [ - "@babel/preset-env", - { - "modules": false, - "loose": true - } - ] - ] - } - } -}; \ No newline at end of file +module.exports = { + env: { + test: { + presets: [ + '@babel/preset-env' + ] + }, + build: { + presets: [ + [ + '@babel/preset-env', + { + modules: false, + loose: true + } + ] + ] + } + } +} diff --git a/docs/en/I18n.md b/docs/en/I18n.md index a4e684411..98ba94380 100644 --- a/docs/en/I18n.md +++ b/docs/en/I18n.md @@ -90,7 +90,7 @@ dayjs() .locale('zh-cn') .format() // get locale object - var customLocale = window.dayjs_locale_zh_cn // zh-cn -> zh_cn + const customLocale = window.dayjs_locale_zh_cn // zh-cn -> zh_cn ``` diff --git a/docs/es-es/I18n.md b/docs/es-es/I18n.md index fa13e4890..7cf29e378 100644 --- a/docs/es-es/I18n.md +++ b/docs/es-es/I18n.md @@ -94,7 +94,7 @@ dayjs() .locale('zh-cn') .format() // get locale object - var customLocale = window.dayjs_locale_zh_cn // zh-cn -> zh_cn + const customLocale = window.dayjs_locale_zh_cn // zh-cn -> zh_cn ``` diff --git a/docs/ja/I18n.md b/docs/ja/I18n.md index 161db83aa..b7f4612cb 100644 --- a/docs/ja/I18n.md +++ b/docs/ja/I18n.md @@ -90,7 +90,7 @@ dayjs() .locale('zh-cn') .format() // ロケールオブジェクトを取得 - var customLocale = window.dayjs_locale_zh_cn // zh-cn -> zh_cn + const customLocale = window.dayjs_locale_zh_cn // zh-cn -> zh_cn ``` diff --git a/docs/ko/I18n.md b/docs/ko/I18n.md index d053504ac..e4f208937 100644 --- a/docs/ko/I18n.md +++ b/docs/ko/I18n.md @@ -90,7 +90,7 @@ dayjs() .locale('zh-cn') .format() // get locale object - var customLocale = window.dayjs_locale_zh_cn // zh-cn -> zh_cn + const customLocale = window.dayjs_locale_zh_cn // zh-cn -> zh_cn ``` diff --git a/docs/pt-br/I18n.md b/docs/pt-br/I18n.md index e2d8e24d1..4c12a08cc 100644 --- a/docs/pt-br/I18n.md +++ b/docs/pt-br/I18n.md @@ -90,7 +90,7 @@ dayjs() .locale('pt-br') .format() // obtém o objeto de localidade - var customLocale = window.dayjs_locale_zh_cn // pt-br -> pt-br + const customLocale = window.dayjs_locale_zh_cn // pt-br -> pt-br ``` diff --git a/docs/zh-cn/I18n.md b/docs/zh-cn/I18n.md index 5c6de06be..bbafe6225 100644 --- a/docs/zh-cn/I18n.md +++ b/docs/zh-cn/I18n.md @@ -90,7 +90,7 @@ dayjs() .locale('zh-cn') .format() // 获取语言配置对象 - var customLocale = window.dayjs_locale_zh_cn // zh-cn -> zh_cn + const customLocale = window.dayjs_locale_zh_cn // zh-cn -> zh_cn ``` diff --git a/karma.sauce.conf.js b/karma.sauce.conf.js index 4d05721ce..5549d7a29 100644 --- a/karma.sauce.conf.js +++ b/karma.sauce.conf.js @@ -1,6 +1,5 @@ module.exports = function (config) { - - var batches = [ + const batches = [ { sl_chrome_26: { base: 'SauceLabs', @@ -75,9 +74,9 @@ module.exports = function (config) { browserName: 'android' } } - ]; + ] - var batch = batches[process.argv[4] || 0] + const batch = batches[process.argv[4] || 0] config.set({ basePath: '', frameworks: ['jasmine'], @@ -97,5 +96,5 @@ module.exports = function (config) { customLaunchers: batch, browsers: Object.keys(batch), singleRun: true - }); -}; + }) +} diff --git a/test/plugin/preParsePostFormat.test.js b/test/plugin/preParsePostFormat.test.js index 685ac8d1d..d3ea11f85 100755 --- a/test/plugin/preParsePostFormat.test.js +++ b/test/plugin/preParsePostFormat.test.js @@ -1,5 +1,4 @@ import MockDate from 'mockdate' -// import moment from 'moment' import dayjs from '../../src' import preParsePostFormat from '../../src/plugin/preParsePostFormat' import localeData from '../../src/plugin/localeData' @@ -51,36 +50,22 @@ const localeCustomizations = { ...en, preparse(string) { if (typeof string !== 'string') { - // console.error('preparse - Expected string, got', { - // string - // }) throw new Error(`preparse - Expected string, got ${typeof string}`) } try { - const res = string.replace(/[!@#$%^&*()]/g, match => numberMap[match]) - // console.log('Called custom preparse', { string, res }) - return res + return string.replace(/[!@#$%^&*()]/g, match => numberMap[match]) } catch (error) { - const errorMsg = `Unexpected error during preparse of '${string}' - ${error}` - // console.error(errorMsg) - throw new Error(errorMsg) + throw new Error(`Unexpected error during preparse of '${string}' - ${error}`) } }, postformat(string) { if (typeof string !== 'string') { - // console.error('postformat - Expected string, got', { - // string - // }) throw new Error(`postformat - Expected string, got ${typeof string}`) } try { - const res = string.replace(/\d/g, match => symbolMap[match]) - // console.log('Called custom postformat', { string, res }) - return res + return string.replace(/\d/g, match => symbolMap[match]) } catch (error) { - const errorMsg = `Unexpected error during postFormat of '${string}' - ${error}` - // console.error(errorMsg) - throw new Error(errorMsg) + throw new Error(`Unexpected error during postFormat of '${string}' - ${error}`) } } }