Skip to content

Commit 989d2d8

Browse files
committed
Convert no-underscored-properties to TypeScript
Bug: chromium:397586315 Change-Id: Ie27d1c96b4b40ccdef26a5e8271937e522dc125b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6441162 Reviewed-by: Nikolay Vitkov <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]> Auto-Submit: Mathias Bynens <[email protected]>
1 parent 563f142 commit 989d2d8

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

scripts/eslint_rules/lib/no-underscored-properties.js renamed to scripts/eslint_rules/lib/no-underscored-properties.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
'use strict';
5+
import {createRule} from './tsUtils.ts';
66

77
function hasPublicMethodForUnderscoredProperty(node) {
88
const nodeName = node.key.name;
@@ -15,6 +15,7 @@ function hasPublicMethodForUnderscoredProperty(node) {
1515
});
1616
return hasMethodDeclaredWithNonUnderscoredName;
1717
}
18+
1819
function checkNodeForUnderscoredProperties(context, node, typeOfNode) {
1920
if (node.key.type !== 'Identifier') {
2021
return;
@@ -33,23 +34,25 @@ function checkNodeForUnderscoredProperties(context, node, typeOfNode) {
3334
context.report({
3435
node,
3536
data: {propName: nodeName, typeOfNode},
36-
message: 'Class {{typeOfNode}} {{propName}} should not begin with an underscore.'
37+
messageId: 'underscorePrefix',
3738
});
3839
}
39-
/**
40-
* @type {import('eslint').Rule.RuleModule}
41-
*/
42-
module.exports = {
40+
41+
export default createRule({
42+
name: 'no-underscored-properties',
4343
meta: {
4444
type: 'problem',
45-
4645
docs: {
4746
description: 'enforce that class properties and methods do not start with an underscore',
4847
category: 'Possible Errors',
4948
},
49+
messages: {
50+
underscorePrefix: 'Class {{typeOfNode}} {{propName}} should not begin with an underscore.',
51+
},
5052
fixable: 'code',
5153
schema: [] // no options
5254
},
55+
defaultOptions: [],
5356
create: function(context) {
5457
return {
5558
PropertyDefinition(node) {
@@ -64,4 +67,4 @@ module.exports = {
6467
}
6568
};
6669
}
67-
};
70+
});

scripts/eslint_rules/tests/no-underscored-properties.test.js renamed to scripts/eslint_rules/tests/no-underscored-properties.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright 2020 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';
5-
const rule = require('../lib/no-underscored-properties.js');
64

7-
const {RuleTester} = require('./utils/utils.js');
5+
import rule from '../lib/no-underscored-properties.ts';
6+
7+
import {RuleTester} from './utils/tsUtils.ts';
88

99
new RuleTester().run('no-underscored-properties', rule, {
1010
valid: [
@@ -53,7 +53,7 @@ new RuleTester().run('no-underscored-properties', rule, {
5353
private _foo: string = '';
5454
}`,
5555
errors: [
56-
{message: 'Class property _foo should not begin with an underscore.'},
56+
{messageId: 'underscorePrefix'},
5757
],
5858
},
5959
{
@@ -62,7 +62,7 @@ new RuleTester().run('no-underscored-properties', rule, {
6262
public _foo: string = '';
6363
}`,
6464
errors: [
65-
{message: 'Class property _foo should not begin with an underscore.'},
65+
{messageId: 'underscorePrefix'},
6666
],
6767
},
6868
{
@@ -71,7 +71,7 @@ new RuleTester().run('no-underscored-properties', rule, {
7171
_foo: string = '';
7272
}`,
7373
errors: [
74-
{message: 'Class property _foo should not begin with an underscore.'},
74+
{messageId: 'underscorePrefix'},
7575
],
7676
},
7777
{
@@ -81,7 +81,7 @@ new RuleTester().run('no-underscored-properties', rule, {
8181
}
8282
}`,
8383
errors: [
84-
{message: 'Class method _foo should not begin with an underscore.'},
84+
{messageId: 'underscorePrefix'},
8585
],
8686
},
8787
{
@@ -92,7 +92,7 @@ new RuleTester().run('no-underscored-properties', rule, {
9292
}
9393
}`,
9494
errors: [
95-
{message: 'Class method _foo should not begin with an underscore.'},
95+
{messageId: 'underscorePrefix'},
9696
],
9797
},
9898
],

0 commit comments

Comments
 (0)