Skip to content

Commit 31675fa

Browse files
mathiasbynensDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
Convert prefer-assert-length-of to TypeScript
Bug: chromium:397586315 Change-Id: Iafeb4022039487fdc80197d5d11acd048e62a9af Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6441159 Commit-Queue: Nikolay Vitkov <nvitkov@chromium.org> Reviewed-by: Nikolay Vitkov <nvitkov@chromium.org> Commit-Queue: Mathias Bynens <mathias@chromium.org> Auto-Submit: Mathias Bynens <mathias@chromium.org>
1 parent 17962fd commit 31675fa

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

scripts/eslint_rules/lib/prefer-assert-length-of.js renamed to scripts/eslint_rules/lib/prefer-assert-length-of.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
// Copyright 2024 The Chromium Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
'use strict';
54

6-
/**
7-
* @fileoverview Prefer `assert.lengthOf` to check `length` of an array-like.
8-
*/
9-
10-
// ------------------------------------------------------------------------------
11-
// Rule Definition
12-
// ------------------------------------------------------------------------------
5+
import {createRule} from './tsUtils.ts';
136

147
const EQUALITY_ASSERTIONS = new Set(['deepEqual', 'deepStrictEqual', 'equal', 'strictEqual']);
158

16-
/** @type {import('eslint').Rule.RuleModule} */
17-
module.exports = {
9+
export default createRule({
10+
name: 'prefer-assert-length-of',
1811
meta: {
1912
type: 'suggestion',
20-
2113
docs: {
2214
description: 'Prefer `assert.lengthOf` to check `length` of an array-like.',
2315
category: 'Best Practices',
@@ -26,15 +18,14 @@ module.exports = {
2618
useAssertLengthOf: 'Use `assert.lengthOf` to check `length` of an array-like',
2719
},
2820
fixable: 'code',
29-
schema: [], // no options
21+
schema: [], // no options
3022
},
31-
create: function (context) {
23+
defaultOptions: [],
24+
create: function(context) {
3225
function isAssertEquality(calleeNode) {
33-
return calleeNode.type === 'MemberExpression' &&
34-
calleeNode.object.type === 'Identifier' &&
35-
calleeNode.object.name === 'assert' &&
36-
calleeNode.property.type === 'Identifier' &&
37-
EQUALITY_ASSERTIONS.has(calleeNode.property.name);
26+
return calleeNode.type === 'MemberExpression' && calleeNode.object.type === 'Identifier' &&
27+
calleeNode.object.name === 'assert' && calleeNode.property.type === 'Identifier' &&
28+
EQUALITY_ASSERTIONS.has(calleeNode.property.name);
3829
}
3930

4031
function isLengthProperty(argumentNode) {
@@ -43,8 +34,7 @@ module.exports = {
4334
}
4435

4536
function isNumberLiteral(argumentNode) {
46-
return argumentNode.type === 'Literal' &&
47-
typeof argumentNode.value === 'number';
37+
return argumentNode.type === 'Literal' && typeof argumentNode.value === 'number';
4838
}
4939

5040
function reportError(node) {
@@ -76,4 +66,4 @@ module.exports = {
7666
}
7767
};
7868
},
79-
};
69+
});

scripts/eslint_rules/tests/prefer-assert-length-of.test.js renamed to scripts/eslint_rules/tests/prefer-assert-length-of.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// Copyright 2024 The Chromium Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
'use strict';
54

6-
const rule = require('../lib/prefer-assert-length-of.js');
5+
import rule from '../lib/prefer-assert-length-of.ts';
76

8-
const {RuleTester} = require('./utils/utils.js');
7+
import {RuleTester} from './utils/tsUtils.ts';
98

109
new RuleTester().run('prefer-assert-length-of', rule, {
1110
valid: [

0 commit comments

Comments
 (0)