-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix eslint #378
fix eslint #378
Conversation
--task=20210826
--task=20210827
--story=20210826
--story=20210826
--story=20210826
@@ -31,12 +31,12 @@ export default class Commander { | |||
if (Object.prototype.toString.call(name) !== '[object String]') { | |||
return; | |||
} | |||
name = name.toLowerCase(); | |||
const invisibleCommand = this.invisibleStore[name]; | |||
const newName = name.toLowerCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
叫 finalName
比较好
if (!optionItemConfig.name) { | ||
optionItemConfig.name = option; | ||
} | ||
|
||
optionDescritionItem = optionItemConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该浅拷贝一份
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该是深拷贝吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
浅就行
const commandConfig = commandsConfig[command]; | ||
registerDevkitCommand(command, commandConfig, directoryPath, ctx); | ||
} | ||
const commandsConfigKey = Object.keys(commandsConfig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用 Object.entries
@@ -39,15 +34,16 @@ export default class Hook { | |||
this.emit(EVENT_DONE); | |||
}); | |||
break; | |||
default: | |||
default: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要加大括号吧?
const listeners = this.listeners[type]; | ||
if (!listeners) { | ||
return; | ||
} | ||
this.listeners[type].forEach((listener: any) => { | ||
listener.apply(null, args); | ||
listener.apply(...args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null 不能去除,逻辑改变了;args 也不能展开,第二个参数就是个数组
async _write(data: any, enc: any, callback: any) { | ||
const level = data.level; | ||
const loggerName = data.name || (logger.name && logger.name.split('/').pop()) || PLUGE_NAME; | ||
async newWrite(data: any, enc: any, callback: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不以下划线开头就可以了吧?没必要加个 new
const { hasTimer } = process.env; | ||
let KYE_FILE = {}; | ||
let KYE_FILE: any = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
给 object
类型比较好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
给object会报错
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
定义一个 AnyObject
console.log('send success'); | ||
} | ||
} | ||
async function report(logObj?: any) { | ||
let readData = fs.readFileSync(LOGGER_LOG_PATH, 'utf-8'); | ||
let readData: any = fs.readFileSync(LOGGER_LOG_PATH, 'utf-8'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里显然是 string 类型
str += prop + ' = ' + config[prop] + '\n'; | ||
} | ||
const configKey = Object.keys(config); | ||
configKey.forEach((item: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key 和 value 都需要用时直接用 Object.entries 遍历
const desc = store[name].desc || ''; | ||
const arr: any = []; | ||
const storeKey = Object.keys(store); | ||
storeKey.forEach((item: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.entries
const data = res.data || {}; | ||
return data.data && data.data[0]; | ||
return (data.data && data.data.length > 0 && data.data[0]) || []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改变了原逻辑,data.data?.[0]
即可
@@ -64,12 +63,11 @@ async function getRepoInfo(ctx: any, packageName: string) { | |||
// encodeURIComponent("github.com/tencent/feflow.git") | |||
function getGitRepoName(repoUrl: string): string | undefined { | |||
const ret = /^((http:\/\/|https:\/\/)(.*?@)?|git@)/.exec(repoUrl); | |||
let newRepoUrl: String = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
初始值应为 repoUrl;String 类型应用小写
} | ||
ctx.logger.info(`[${dep}] has installed the latest version: ${hasInstallDep[depName]}`); | ||
return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
原逻辑没有返回空数组
}; | ||
|
||
module.exports.installPlugin = installPlugin; | ||
module.exports.updateUniversalPlugin = updateUniversalPlugin; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确定没有模块使用?
// for (const obj in source) { | ||
// target[obj] = source[obj]; | ||
// } | ||
const newTarget = JSON.parse(JSON.stringify(target)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
浅拷贝即可
// target[obj] = source[obj]; | ||
// } | ||
const newTarget = JSON.parse(JSON.stringify(target)); | ||
const sourceValue = Object.keys(source); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.entries
} | ||
return target; | ||
const extend = function (target: any, source: any) { | ||
// for (const obj in source) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释掉的代码直接删除
const pkg = require('../../../package.json'); | ||
const { getPkgInfo, updateUniversalPlugin } = require('../native/install'); | ||
const version = pkg.version; | ||
// import { getPkgInfo, updateUniversalPlugin } from '../native/install'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除
interface ErrorInstance { | ||
name: string; | ||
message: string; | ||
stack: string; | ||
} | ||
|
||
const pkg = require('../../../package.json'); | ||
const { getPkgInfo } = require('../native/install'); | ||
const version = pkg.version; | ||
// import { getPkgInfo } from '../native/install'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除
}); | ||
logger.debug('tnpm plugins update infomation', plugins); | ||
if (plugins.length) { | ||
const newPlugins = plugins.filter((plugin: any) => plugin?.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
叫 pluginsWithName 比较语义化
--task=20210827
--story=20210826
--story=20210826
--story=20210826
--story=20210826
--story=20210826
--story=20210826
--story=20210826
}: { | ||
logger: any; | ||
universalPkg: UniversalPkg; | ||
universalModules: string; | ||
} = ctx; | ||
const serverUrl = ctx.config?.serverUrl; | ||
|
||
installPluginStr = installPluginStr.trim(); | ||
const newInstallPluginStr = installPluginStr.trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finalInstallPluginStr
} | ||
return target; | ||
const extend = function (target: any, source: any) { | ||
const newTarget = target; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
浅拷贝一下否则没有意义
…ow into refactor/20210826_fix_eslint
for (const k in oInstalled) { | ||
const version = oInstalled[k]; | ||
Object.entries(oInstalled).forEach(([key, value]) => { | ||
const version:any = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应为 string 类型
@@ -5,11 +5,11 @@ export function toInstalled(oInstalled: any): Map<string, string> { | |||
if (!oInstalled) { | |||
return installed; | |||
} | |||
for (const k in oInstalled) { | |||
const version = oInstalled[k]; | |||
Object.entries(oInstalled).forEach(([key, value]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key 和 value 应该尽量语义化,例如 value 在最初的代码里已经明确定义为 version 了。其他类似情况不再赘述。
--story=20210826
@@ -9,11 +9,11 @@ function loadModuleList(ctx: any) { | |||
const packagePath = ctx.rootPkg; | |||
const pluginDir = path.join(ctx.root, 'node_modules'); | |||
const extend = function (target: any, source: any) { | |||
const newTarget = target; | |||
const targetOpey = { ...target }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opey 是什么意思?叫 newTarget targetCopy 都可以
--story=20210826
--story=20210826
--task=20210923
--story=20210826
--story=20210826
return result; | ||
}; | ||
|
||
export const getGitStatus = (): boolean => { | ||
const command = isWin ? 'where git' : 'which git'; | ||
const hasGitCommand = exec(command); | ||
const hasGitDir = fs.existsSync(path.join(cwd, '.git')); | ||
return hasGitCommand && hasGitDir; | ||
return Boolean(hasGitCommand && hasGitDir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要 包多一层 Boolean
packages/feflow-report/src/index.ts
Outdated
@@ -10,7 +10,7 @@ class Report { | |||
ctx: ReportContext; | |||
cmd: string; | |||
args: object; | |||
commandSource: string; | |||
commandSource: string | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commandSource?: string 即可
packages/feflow-report/src/index.ts
Outdated
@@ -21,58 +21,19 @@ class Report { | |||
|
|||
constructor(feflowContext: ReportContext, cmd?: string, args?: any) { | |||
this.ctx = feflowContext; | |||
this.cmd = cmd; | |||
this.cmd = cmd!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmd 可能 undefined
packages/feflow-report/src/report.ts
Outdated
@@ -28,7 +18,7 @@ function getReportBody(cmd, params): any { | |||
.load('command_source', commandSource) | |||
.load('user_name', userName) | |||
.load('params', params) | |||
.load('err_message', getKeyFormFile(cachePath, 'errMsg')) | |||
.load('err_message', getKeyFormFile(cachePath!, 'errMsg')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要强制断言存在,实在不会改先 ts-ignore,我后面统一优化
--story=20210826
packages/feflow-report/src/index.ts
Outdated
@@ -21,58 +21,19 @@ class Report { | |||
|
|||
constructor(feflowContext: ReportContext, cmd?: string, args?: any) { | |||
this.ctx = feflowContext; | |||
this.cmd = cmd; | |||
this.cmd = cmd || ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
让 cmd?: string
--story=20210826
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.