[转帖]Code brushes for GitHub Copilot

code,brushes,for,github,copilot · 浏览次数 : 0

小编点评

## Code Brushes for GitHub Copilot The article provides an introduction to code brushes for GitHub Copilot labs and how they can help improve the quality of your code. **Key takeaways:** * **Code cleaner:** The new feature allows you to change code to make it cleaner, more robust, and document it automatically. * **Improved code:** Using brushes like "Fix bugs," "Clean," "List steps," and "Make robust," you can improve the quality of your code by catching errors and adding comments. * **Custom brushes:** You can define custom brushes to achieve specific code formatting or quality checks. * **Benefits:** This feature can significantly improve the quality and maintainability of your code. **Additional points:** * The article mentions the "Add types" brush, but it's not mentioned in the main text. * The article focuses on JavaScript code, but the functionality can be applied to other programming languages. **Overall, the article provides a good overview of the new code brushes feature and how they can help improve your code's quality.**

正文

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

 

Tuesday, December 13th, 2022 at 4:45 pm

Github Next now showed a new feature in GitHub Copilot labs that allows you to change code you write to make it cleaner, more robust and document it automatically.

GitHub Copilot is incredible, and if you check what’s happening in the preview released as the Copilot Labs extension it will only get more amazing.

Check this out:

Code brushes applied to a simple JavaScript

Let’s start with a basic JavaScript that checks a string length and reports when it is empty. One with an obvious mistake, as we use a single `=` instead of the type safe `===`. This will always report the string as empty.

 

if (str.length = 0) {
    console.error('String is empty');
}

 

Using the `Fix bugs` brush, this is rectified.

 

if (str.length === 0) {
    console.error('String is empty');
}

 

Using the `Clean` brush also adds reporting when the string is not empty.

 

if (str.length === 0) {
    console.error('String is empty');
} else {
    console.log('String is not empty');
}

 

Using the `List steps` brush adds comments for step (sure, this is redundant, but it also works for much more complex code).

 

// check the length of the string
if (str.length === 0) {
    // if length is 0, print 'String is empty' 
    console.error('String is empty');
} else {
    // if length is not 0, print 'String is not empty'
    console.log('String is not empty');
}

 

Using `Make robust` adds error reporting instead of logging and an extra check to make sure that `str` is really a String and not an empty Array.

 

function test(str) {
    if (str.length === 0) {
        throw new Error('String is empty');
    } else if (typeof str !== 'string') {
        throw new Error('It is not a string');
    } else {
        console.log('String is not empty');
    }
}

 

The `Add types` brush does exactly that.

 

/**
 * @param {string} str
 * @returns {string}
 */
function test(str) {
    if (str.length === 0) {
        throw new Error('String is empty');
    } else if (typeof str !== 'string') {
        throw new Error('It is not a string');
    } else {
        console.log('String is not empty');
    }
}

 

You can also define custom brushes and there are more to come.

Share on Twitter

与[转帖]Code brushes for GitHub Copilot相似的内容:

[转帖]Code brushes for GitHub Copilot

https://christianheilmann.com/2022/12/13/code-brushes-for-github-copilot/ Tuesday, December 13th, 2022 at 4:45 pm Github Next now showed a new feature

[转帖]Code Cache满导致应用性能降低

https://juejin.cn/post/6844903601786060808 0 问题描述 一个应用在运行一段时间后,随着访问量不断增加,突然处理能力下降。但是从流量,jstack,gc上看基本正常。感觉好像突然从 “健康状态” 进入了 “虚弱状态”。 1 排查问题 在JVM日志里,可以发现

[转帖]Code Cache满导致应用性能降低

https://juejin.cn/post/6844903601786060808 0 问题描述 一个应用在运行一段时间后,随着访问量不断增加,突然处理能力下降。但是从流量,jstack,gc上看基本正常。感觉好像突然从 “健康状态” 进入了 “虚弱状态”。 1 排查问题 在JVM日志里,可以发现

[转帖]聊聊jvm的Code Cache

https://www.jianshu.com/p/b064274536ed 本文主要研究一下jvm的Code Cache Code Cache JVM生成的native code存放的内存空间称之为Code Cache;JIT编译、JNI等都会编译代码到native code,其中JIT生成的na

[转帖]聊聊jvm的Code Cache

https://juejin.cn/post/6844903809932591112 序 本文主要研究一下jvm的Code Cache Code Cache JVM生成的native code存放的内存空间称之为Code Cache;JIT编译、JNI等都会编译代码到native code,其中JI

[转帖]JVM 调优之 Reserved Code Cache Size

https://www.modb.pro/db/251381 01 现象 社区小伙伴最近在为 Kylin 4 开发 Soft Affinity + Local Cache 的性能测试过程中,遇到了压测场景下查询响应时间不稳定问题, RT 随着时间变化较大,现象如下: 同样的 SQL (只是参数不同)

[转帖]nacos修改密码

https://www.cnblogs.com/cherish-code/p/14765862.html nacos修改默认的用户名密码 修改配置文件, vim nacos/conf/application.properties 在配置文件加入如下: spring.datasource.platfo

[转帖]RZ 归零编码

中文全称:归零编码 英文全称:Return Zero Code 简称:RZ 在数字电路中,组成一连串信息的基元就是0和1,无论是在CPU、DSP、MCU甚至是个数字计数器中,数字电路在其中能够处理的信息也只有0和1,而对于任何外界的信息,计算机都能通过两个量来描述,那就是0和1。而对于数字通信来说,

[转帖]TiFlash DeltaTree 存储引擎设计及实现分析 - Part 1

https://tidb.net/book/book-rush/features/tiflash-code/tiflash-deltatree TiFlash 是 TiDB 的分析引擎,是 TiDB HTAP 形态的关键组件。TiFlash 源码阅读系列文章将从源码层面介绍 TiFlash 的内部实

[转帖]NRZ 不归零编码

NRZ(不归零编码) 历史版本 2 NRZ 编码(Non-return-to-zero Code),也叫不归零编码。是我们最常见的一种编码,即正电平表示1,低电平表示0。 中文全称 不归零编码 英文全称 Non Return Zero Code 简称 NRZ NRZ 编码(Non-return-to