已合并
bind-this-method #1122
raifmirzaerten创建于 2025年9月29日
bind-this-method #1122
已合并
Pull Request已成功合入, 合并人@openharmony_ci
(感谢 raifmirzaerten 的贡献)openharmony_ci
2025年9月29日 评论:
2025年9月29日 评论:
感谢提交 Pull Requests!
Thanks for submitting a pull request.


2025年9月29日 添加了label:dco检查成功
test/unittest/sample/ThisBindCheck/ets/LocalAndClassSimilar.ts
已过期
@@ -0,0 +24,4 @@
24+ private someProp: A = new A();
25+
26+ public someMethod(someProp: A) {
27+ console.log(`Some important message with prop -> ${this.someProp.getSomething}` +
what will happed if someProp is defined in this someMethod rather than from param?


2025年10月10日 推送 1 个提交:fc33e413-numeric rule field check
2025年10月10日 强制推送 1 个提交:2d612f89-numeric rule field check
2025年10月10日 修改标题为 “[WIP]bind-this-method”,原标题为“[WIP]numeric rule field check”
src/checker/migration/ThisBindCheck.ts
已过期
@@ -147,2 +151,3 @@
147151 }
148- } else {
152+ } else if (user instanceof ArkAssignStmt) {
153+ if(user.getRightOp() instanceof ArkPtrInvokeExpr) {
not quite understand about this check. why it's unsafe if the rightOp is ArkPtrInvokeExpr?


2025年10月10日 强制推送 1 个提交:b9248158-bind this rule impl
test/unittest/code/ThisBindCheck.test.ts
已过期
@@ -95,12 +95,10 @@ describe('ThisBindTest', () => {
9595
9696 test('ThisBindTest_008', () => {
9797 const detectFile: string = path.join(realPath, 'ets', 'GlobalThis.ets');
98- const expectReportList = ['25%16%'];
why there is no issue here?


src/checker/migration/ThisBindCheck.ts
@@ -39,30 +40,30 @@
40+import {ArkPtrInvokeExpr} from "arkanalyzer/lib";
3941
4042const logger = Logger.getLogger(LOG_MODULE_TYPE.HOMECHECK, 'ThisBindCheck');
4143
@@ -106,6 +108,7 @@ export class ThisBindCheck implements BaseChecker {
106108 const isBuilder = method.hasBuilderDecorator();
107109 const isLocalBuilder = method.hasDecorator('LocalBuilder');
108110 const leftOp = stmt.getLeftOp();
111+
109112 if (i + 1 >= stmts.length || !this.hasBindThis(leftOp, stmts[i + 1])) {
110113 if (!this.isSafeUse(leftOp)) {
111114 this.addIssueReport(stmt, isBuilder, isLocalBuilder, base, scene);
@@ -132,12 +135,13 @@ export class ThisBindCheck implements BaseChecker {
132135
133136 private isSafeUse(v: Value): boolean {
134137 if (!(v instanceof Local)) {
138+
135139 return false;
136140 }
137141
138142 const users = v.getUsedStmts();
139143 if (users.length === 0) {
140- return false;
144+ return true;
141145 }
142146 for (const user of users) {
143147 if (user instanceof ArkIfStmt) {
@@ -145,7 +149,9 @@ export class ThisBindCheck implements BaseChecker {
145149 if (v !== cond.getOp1() && v !== cond.getOp2()) {
146150 return false;
147151 }
How can we distinguish the cases for:
- function pointer with called.
- function pointer without called.


2025年10月10日 强制推送 1 个提交:1e566073-bind this rule impl
2025年10月10日 强制推送 1 个提交:dba6c880-bind this rule impl
2025年10月10日 强制推送 1 个提交:6196525d-bind this rule impl
test/unittest/code/ThisBindCheck.test.ts
@@ -135,3 +127,3 @@
135127 const detectFileReport = checkEntry.fileChecks.find((fileCheck) => fileCheck.arkFile.getFilePath() === detectFile);
136128 assert.isDefined(detectFileReport, 'The file path is error.');
137- assert.equal(detectFileReport?.issues.length, expectReportList.length, 'The number of reported line is different from the expected number of line.');
129+ assert.equal(detectFileReport?.issues.length, 0,'The number of reported line should be 0.');
It should still report issue in all these files which are used to report. Avoid to remove the issue.
If necessary, you need to update the corresponding sample code to ensure the issue report as before.


src/checker/migration/ThisBindCheck.ts
@@ -76,3 +78,3 @@
7678 public check = (targetMtd: ArkMethod): void => {
7779 const file = targetMtd.getDeclaringArkFile();
78- if (file.getName().includes('.test.ets')) {
80+ if (file.getName().includes('.test.ets') || file.getName().includes('.ts') || file.getName().includes('.js')) {
please using targetMtd.getLanguage() !== Language.ARKTS1_2 to do the check.
the file could also be with .ets but not marked as arkts1.2 which no need to check as well as C++ files.


2025年10月13日 强制推送 1 个提交:0b9347d6-bind this rule impl
2025年10月17日 取消了草稿状态
2025年10月20日 通过审查
xudan16
2025年10月20日 评论:
2025年10月20日 评论:
FORCE_VERIFY


2025年10月20日 通过测试
openharmony_ci
2025年10月20日 评论:
2025年10月20日 评论:
添加 测试通过 成功!


2025年10月20日 合入了pull request,合并节点 SHA:bc5527693d8646cf3134c668596a13a2d0bb9740
一、内容说明(相关的Issue)
二、建议测试周期和提测地址
建议测试完成时间:xxxx.xx.xx
投产上线时间:xxxx.xx.xx
提测地址:CI环境/压测环境
测试账号:
三、变更内容
3.1 关联PR列表
3.2 数据库和部署说明
bundle exec xxx RAILS_ENV = production;没有写 "无"3.4 其他技术优化内容(做了什么,变更了什么)
3.5 废弃通知(什么字段、方法弃用?)
3.6 后向不兼容变更(是否有无法向后兼容的变更?)
四、研发自测点(自测哪些?冒烟用例全部自测?)
自测测试结论:
五、测试关注点(需要提醒QA重点关注的、可能会忽略的地方)
检查点:
接口测试:
性能测试:
并发测试:
其他: