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+ } ) ;
0 commit comments