Skip to content

Commit 84b8647

Browse files
mathiasbynensDevtools-frontend LUCI CQ
authored andcommitted
Convert prefer-assert-is-ok to TypeScript
Bug: chromium:397586315 Change-Id: I2720845c34287bfbc0c3af6d0312765cf112246c Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6441158 Auto-Submit: Mathias Bynens <[email protected]> Reviewed-by: Nikolay Vitkov <[email protected]> Commit-Queue: Mathias Bynens <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent 554c05b commit 84b8647

File tree

2 files changed

+15
-31
lines changed

2 files changed

+15
-31
lines changed
Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
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.isOk` and `assert.isNotOk` over `assert.ok`
8-
* and `assert.notOk`.
9-
*
10-
* For consistency with the other `assert.isXXX` checks, we standardize on
11-
* `assert.isOk` and `assert.isNotOk`. We still also allow plain `assert`.
12-
*/
5+
import {createRule} from './tsUtils.ts';
136

14-
// ------------------------------------------------------------------------------
15-
// Rule Definition
16-
// ------------------------------------------------------------------------------
17-
18-
/** @type {import('eslint').Rule.RuleModule} */
19-
module.exports = {
7+
export default createRule({
8+
name: 'prefer-assert-is-ok',
209
meta: {
2110
type: 'suggestion',
22-
2311
docs: {
2412
description: 'Prefer `assert.isOk` and `assert.isNotOk` over `assert.ok` and `assert.notOk`.',
2513
category: 'Best Practices',
@@ -29,23 +17,20 @@ module.exports = {
2917
useAssertIsNotOk: 'Use `assert.isNotOk(e)` or `assert(!e)` instead of `assert.notOk(e)`',
3018
},
3119
fixable: 'code',
32-
schema: [], // no options
20+
schema: [], // no options
3321
},
34-
create: function (context) {
22+
defaultOptions: [],
23+
create: function(context) {
3524
function isAssertOk(calleeNode) {
36-
return calleeNode.type === 'MemberExpression' &&
37-
calleeNode.object.type === 'Identifier' &&
38-
calleeNode.object.name === 'assert' &&
39-
calleeNode.property.type === 'Identifier' &&
40-
calleeNode.property.name === 'ok';
25+
return calleeNode.type === 'MemberExpression' && calleeNode.object.type === 'Identifier' &&
26+
calleeNode.object.name === 'assert' && calleeNode.property.type === 'Identifier' &&
27+
calleeNode.property.name === 'ok';
4128
}
4229

4330
function isAssertNotOk(calleeNode) {
44-
return calleeNode.type === 'MemberExpression' &&
45-
calleeNode.object.type === 'Identifier' &&
46-
calleeNode.object.name === 'assert' &&
47-
calleeNode.property.type === 'Identifier' &&
48-
calleeNode.property.name === 'notOk';
31+
return calleeNode.type === 'MemberExpression' && calleeNode.object.type === 'Identifier' &&
32+
calleeNode.object.name === 'assert' && calleeNode.property.type === 'Identifier' &&
33+
calleeNode.property.name === 'notOk';
4934
}
5035

5136
function reportError(node, calleeText, messageId) {
@@ -68,4 +53,4 @@ module.exports = {
6853
}
6954
};
7055
},
71-
};
56+
});

scripts/eslint_rules/tests/prefer-assert-is-ok.test.js renamed to scripts/eslint_rules/tests/prefer-assert-is-ok.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-is-ok.js');
5+
import rule from '../lib/prefer-assert-is-ok.ts';
76

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

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

0 commit comments

Comments
 (0)