Skip to content

Commit 2c00f81

Browse files
danilsomsikovDevtools-frontend LUCI CQ
authored andcommitted
Convert no-lit-render-outside-of-view to TypeScript
Bug: 397586315 Change-Id: I74701e6c0390344cf673ae5caf900d568acfa012 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6429284 Commit-Queue: Danil Somsikov <[email protected]> Auto-Submit: Danil Somsikov <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]> Reviewed-by: Nikolay Vitkov <[email protected]>
1 parent f3af0b1 commit 2c00f81

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

scripts/eslint_rules/lib/no-lit-render-outside-of-view.js renamed to scripts/eslint_rules/lib/no-lit-render-outside-of-view.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,28 @@
55
* @fileoverview Rule to identify Lit render calls that are not inside of a
66
* view function.
77
*/
8-
'use strict';
8+
import type {Rule} from 'eslint';
9+
import type {ArrowFunctionExpression, FunctionDeclaration, FunctionExpression} from 'estree';
910

10-
const {isLitHtmlRenderCall} = require('./utils.js');
11+
import {createRule} from './tsUtils.ts';
12+
import {isLitHtmlRenderCall} from './utils.js';
13+
type Node = Rule.Node;
1114

12-
/**
13-
* @type {import('eslint').Rule.RuleModule}
14-
*/
15-
module.exports = {
15+
export default createRule({
16+
name: 'no-lit-render-outside-of-view',
1617
meta: {
1718
type: 'problem',
1819
docs: {
1920
description: 'Lit render calls should be inside of a view function',
2021
category: 'Possible Errors',
2122
},
2223
messages: {
23-
litRenderShouldBeInsideOfView:
24-
'Lit render calls should be inside of a view function',
24+
litRenderShouldBeInsideOfView: 'Lit render calls should be inside of a view function',
2525
},
26-
schema: [], // no options
26+
schema: [], // no options
2727
},
28-
create : function(context) {
28+
defaultOptions: [],
29+
create: function(context) {
2930
return {
3031
CallExpression(node) {
3132
if (!isLitHtmlRenderCall(node)) {
@@ -38,8 +39,9 @@ module.exports = {
3839
});
3940
return;
4041
}
41-
let functionNode = node.parent;
42-
while (functionNode && !['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression'].includes(functionNode.type)) {
42+
let functionNode = node.parent as Node | undefined;
43+
while (functionNode &&
44+
!['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression'].includes(functionNode.type)) {
4345
functionNode = functionNode.parent;
4446
}
4547
if (!functionNode) {
@@ -49,11 +51,11 @@ module.exports = {
4951
});
5052
return;
5153
}
52-
/** @typedef {import('estree').FunctionDeclaration|import('estree').FunctionExpression|import('estree').ArrowFunctionExpression} FunctionLike */
53-
const paramNames = /** @type {FunctionLike} */(functionNode).params.filter(p => p.type === 'Identifier').map(param => param.name);
54+
type FunctionLike = FunctionDeclaration|FunctionExpression|ArrowFunctionExpression;
55+
const paramNames =
56+
(functionNode as FunctionLike).params.filter(p => p.type === 'Identifier').map(param => param.name);
5457
if (paramNames.length !== 3 || !paramNames[0].toLowerCase().endsWith('input') ||
55-
!paramNames[1].toLowerCase().endsWith('output') ||
56-
!paramNames[2].toLowerCase().endsWith('target')) {
58+
!paramNames[1].toLowerCase().endsWith('output') || !paramNames[2].toLowerCase().endsWith('target')) {
5759
context.report({
5860
node,
5961
messageId: 'litRenderShouldBeInsideOfView',
@@ -88,4 +90,4 @@ module.exports = {
8890
},
8991
};
9092
}
91-
};
93+
});

scripts/eslint_rules/tests/no-lit-render-outside-of-view.test.js renamed to scripts/eslint_rules/tests/no-lit-render-outside-of-view.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Copyright 2025 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-lit-render-outside-of-view.js');
4+
import rule from '../lib/no-lit-render-outside-of-view.ts';
65

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

98
new RuleTester().run('no-lit-render-outside-of-view', rule, {
109
valid: [

0 commit comments

Comments
 (0)