Skip to content

Commit c1bd58c

Browse files
committed
Convert no-self-closing-custom-element-tagnames to TypeScript
Bug: chromium:397586315 Change-Id: I48e0e75009f042b29839318ba71c7b13bb5b133d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6441163 Auto-Submit: Mathias Bynens <[email protected]> Reviewed-by: Nikolay Vitkov <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent 989d2d8 commit c1bd58c

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
// Copyright 2021 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 {isLitHtmlTemplateCall} = require('./utils.js');
5+
import {createRule} from './tsUtils.ts';
6+
import {isLitHtmlTemplateCall} from './utils.js';
77

8-
/**
9-
* @type {import('eslint').Rule.RuleModule}
10-
*/
11-
module.exports = {
8+
export default createRule({
9+
name: 'no-self-closing-custom-element-tagnames',
1210
meta: {
1311
type: 'problem',
1412
docs: {
1513
description: 'Check for self closing custom element tag names in Lit templates.',
1614
category: 'Possible Errors',
1715
},
16+
messages: {
17+
requiredEndTag: 'Custom elements should not be self-closing.',
18+
},
1819
fixable: 'code',
1920
schema: [] // no options
2021
},
22+
defaultOptions: [],
2123
create: function(context) {
2224
return {
2325
TaggedTemplateExpression(node) {
@@ -31,10 +33,10 @@ module.exports = {
3133
if (text.match(/<@TEMPLATE_EXPRESSION\(\)([^>]*?)\/>/)) {
3234
context.report({
3335
node,
34-
message: 'Custom elements should not be self closing.',
36+
messageId: 'requiredEndTag',
3537
});
3638
}
3739
},
3840
};
3941
}
40-
};
42+
});

scripts/eslint_rules/tests/no-self-closing-custom-element-tagnames.test.js renamed to scripts/eslint_rules/tests/no-self-closing-custom-element-tagnames.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// Copyright 2021 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-self-closing-custom-element-tagnames.js');
64

7-
const {RuleTester} = require('./utils/utils.js');
5+
import rule from '../lib/no-self-closing-custom-element-tagnames.ts';
86

9-
const EXPECTED_ERROR_MESSAGE = 'Custom elements should not be self closing.';
7+
import {RuleTester} from './utils/tsUtils.ts';
108

119
new RuleTester().run('no-self-closing-custom-element-tagnames', rule, {
1210
valid: [
@@ -40,22 +38,22 @@ new RuleTester().run('no-self-closing-custom-element-tagnames', rule, {
4038
{
4139
code: 'Lit.html`<${DataGrid.litTagName} />`',
4240
filename: 'front_end/components/test.ts',
43-
errors: [{message: EXPECTED_ERROR_MESSAGE}],
41+
errors: [{messageId: 'requiredEndTag'}],
4442
},
4543
{
4644
code: 'Lit.html`<p><${DataGrid.litTagName} /></p>`',
4745
filename: 'front_end/components/test.ts',
48-
errors: [{message: EXPECTED_ERROR_MESSAGE}],
46+
errors: [{messageId: 'requiredEndTag'}],
4947
},
5048
{
5149
code: 'Lit.html`<${DataGrid1.litTagName}><${DataGrid2.litTagName} /></${DataGrid1.litTagName}>`',
5250
filename: 'front_end/components/test.ts',
53-
errors: [{message: EXPECTED_ERROR_MESSAGE}],
51+
errors: [{messageId: 'requiredEndTag'}],
5452
},
5553
{
5654
code: 'Lit.html`<${DataGrid.litTagName} .data=${{test: "Hello World"}}/>`',
5755
filename: 'front_end/components/test.ts',
58-
errors: [{message: EXPECTED_ERROR_MESSAGE}],
56+
errors: [{messageId: 'requiredEndTag'}],
5957
},
6058
],
6159
});

0 commit comments

Comments
 (0)