github 提交代码修正lint错误 使用 clang-format 格式化代码
在提交github代码时会自动lint检测。对c++代码,可以使用clang-format自动格式化,不符合格式的会自动调整。
在electron目录下,执行 npm run lint
Using clang-format on C++ Code
clang-format
is a tool to automatically format C/C++/Objective-C code, so that developers don't need to worry about style issues during code reviews.
It is highly recommended to format your changed C++ code before opening pull requests, which will save you and the reviewers' time.
You can install clang-format
and git-clang-format
via npm install -g clang-format
.
To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc
. It should work on macOS/Linux/Windows.
The workflow to format your changed code:
- Make codes changes in Electron repository.
- Run
git add your_changed_file.cc
. - Run
git-clang-format
, and you will probably see modifications inyour_changed_file.cc
, these modifications are generated fromclang-format
. - Run
git add your_changed_file.cc
, and commit your change. - Now the branch is ready to be opened as a pull request.
If you want to format the changed code on your latest git commit (HEAD), you can run git-clang-format HEAD~1
. See git-clang-format -h
for more details.
Editor Integration
You can also integrate clang-format
directly into your favorite editors. For further guidance on setting up editor integration, see these pages:
Testing编写测试代码
We aim to keep the code coverage of Electron high. We ask that all pull request not only pass all existing tests, but ideally also add new tests to cover changed code and new scenarios. Ensuring that we capture as many code paths and use cases of Electron as possible ensures that we all ship apps with fewer bugs.
This repository comes with linting rules for both JavaScript and C++ – as well as unit and integration tests. To learn more about Electron's coding style, please see the coding-style document.
Linting
To ensure that your JavaScript is in compliance with the Electron coding style, run npm run lint-js
, which will run standard
against both Electron itself as well as the unit tests. If you are using an editor with a plugin/addon system, you might want to use one of the manyStandardJS addons to be informed of coding style violations before you ever commit them.
To run standard
with parameters, run npm run lint-js --
followed by arguments you want passed to standard
.
To ensure that your C++ is in compliance with the Electron coding style, run npm run lint-cpp
, which runs a cpplint
script. We recommend that you use clang-format
and prepared a short tutorial.
There is not a lot of Python in this repository, but it too is governed by coding style rules. npm run lint-py
will check all Python, using pylint
to do so.
Unit Tests
If you are not using build-tools, ensure that that name you have configured for your local build of Electron is one of Testing
, Release
, Default
, Debug
, or you have set process.env.ELECTRON_OUT_DIR
. Without these set, Electron will fail to perform some pre-testing steps.
To run all unit tests, run npm run test
. The unit tests are an Electron app (surprise!) that can be found in the spec
folder. Note that it has its own package.json
and that its dependencies are therefore not defined in the top-level package.json
.
To run only specific tests matching a pattern, run npm run test -- -g=PATTERN
, replacing the PATTERN
with a regex that matches the tests you would like to run. As an example: If you want to run only IPC tests, you would run npm run test -- -g ipc
.
Testing on Windows 10 devices
Extra steps to run the unit test:
- Visual Studio 2019 must be installed.
- Node headers have to be compiled for your configuration.
ninja -C out\Testing third_party\electron_node:headers
- The electron.lib has to be copied as node.lib.
cd out\Testing mkdir gen\node_headers\Release copy electron.lib gen\node_headers\Release\node.lib
Missing fonts
Some Windows 10 devices do not ship with the Meiryo font installed, which may cause a font fallback test to fail. To install Meiryo:
- Push the Windows key and search for Manage optional features.
- Click Add a feature.
- Select Japanese Supplemental Fonts and click Install.
Pixel measurements
Some tests which rely on precise pixel measurements may not work correctly on devices with Hi-DPI screen settings due to floating point precision errors. To run these tests correctly, make sure the device is set to 100% scaling.
To configure display scaling:
- Push the Windows key and search for Display settings.
- Under Scale and layout, make sure that the device is set to 100%.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2018-10-16 通过jpa getResultList 获取查询到的内容
2015-10-16 jboss性能优化