Skip to content

搞英语 → 看世界

翻译英文优质信息和名人推特

Menu
  • 首页
  • 作者列表
  • 独立博客
  • 专业媒体
  • 名人推特
  • 邮件列表
  • 关于本站
Menu

GitHub Copilot 的代码刷

Posted on 2022-12-14

Github Next 现在在 GitHub Copilot 实验室中展示了一项新功能,允许您更改您编写的代码,使其更干净、更健壮并自动记录。

GitHub Copilot 令人难以置信,如果您检查作为Copilot Labs 扩展发布的预览中发生的事情,它只会变得更加惊人。

看一下这个:

应用于简单JavaScript的代码刷

让我们从检查字符串长度并在它为空时报告的基本 JavaScript 开始。一个明显的错误,因为我们使用单个 `=` 而不是类型安全的 `===`。这将始终将字符串报告为空。


如果(str.length = 0){
console.error('字符串为空');
}

使用“修复错误”画笔,这已得到纠正。


如果(str.length = 0){
console.error('字符串为空');
}

当字符串不为空时,使用“清洁”画笔还会添加报告。


如果(str.length = 0){
console.error('字符串为空');
} 别的 {
console.log('字符串不为空');
}

使用“列出步骤”画笔为步骤添加注释(当然,这是多余的,但它也适用于更复杂的代码)。


//检查字符串的长度
如果(str.length = 0){
// 如果长度为 0,打印 'String is empty'
console.error('字符串为空');
} 别的 {
// 如果长度不为 0,打印 'String is not empty'
console.log('字符串不为空');
}

使用 `Make robust` 添加错误报告而不是日志记录和额外检查以确保 `str` 确实是一个字符串而不是一个空数组。


功能测试(海峡){
如果(str.length = 0){
throw new Error('字符串为空');
} else if (typeof str !== 'string') {
throw new Error('这不是字符串');
} 别的 {
console.log('字符串不为空');
}

}

“添加类型”画笔正是这样做的。


/**
  • @param {字符串} 海峡
  • @returns {字符串}

*/
功能测试(海峡){
如果(str.length = 0){
throw new Error(‘字符串为空’);
} else if (typeof str ! ‘string’) {
throw new Error(‘这不是字符串’);
} 别的 {
console.log(‘字符串不为空’);
}

}

您还可以定义自定义画笔,并且还会有更多。

原文: https://christianheilmann.com/2022/12/13/code-brushes-for-github-copilot/

本站文章系自动翻译,站长会周期检查,如果有不当内容,请点此留言,非常感谢。
  • Abhinav
  • Abigail Pain
  • Adam Fortuna
  • Alberto Gallego
  • Alex Wlchan
  • Answer.AI
  • Arne Bahlo
  • Ben Carlson
  • Ben Kuhn
  • Bert Hubert
  • Bits about Money
  • Brian Krebs
  • ByteByteGo
  • Chip Huyen
  • Chips and Cheese
  • Christopher Butler
  • Colin Percival
  • Cool Infographics
  • Dan Sinker
  • David Walsh
  • Dmitry Dolzhenko
  • Dustin Curtis
  • eighty twenty
  • Elad Gil
  • Ellie Huxtable
  • Ethan Dalool
  • Ethan Marcotte
  • Exponential View
  • FAIL Blog
  • Founder Weekly
  • Geoffrey Huntley
  • Geoffrey Litt
  • Greg Mankiw
  • Henrique Dias
  • Hypercritical
  • IEEE Spectrum
  • Investment Talk
  • Jaz
  • Jeff Geerling
  • Jonas Hietala
  • Josh Comeau
  • Lenny Rachitsky
  • Liz Danzico
  • Lou Plummer
  • Luke Wroblewski
  • Matt Baer
  • Matt Stoller
  • Matthias Endler
  • Mert Bulan
  • Mostly metrics
  • News Letter
  • NextDraft
  • Non_Interactive
  • Not Boring
  • One Useful Thing
  • Phil Eaton
  • Product Market Fit
  • Readwise
  • ReedyBear
  • Robert Heaton
  • Rohit Patel
  • Ruben Schade
  • Sage Economics
  • Sam Altman
  • Sam Rose
  • selfh.st
  • Shtetl-Optimized
  • Simon schreibt
  • Slashdot
  • Small Good Things
  • Steve Blank
  • Taylor Troesh
  • Telegram Blog
  • The Macro Compass
  • The Pomp Letter
  • thesephist
  • Thinking Deep & Wide
  • Tim Kellogg
  • Understanding AI
  • Wes Kao
  • 英文媒体
  • 英文推特
  • 英文独立博客
©2025 搞英语 → 看世界 | Design: Newspaperly WordPress Theme