license import * as Lint from "tslint" ; import { isJsxExpression } from "tsutils/typeguard/3.0" ; import * as ts from "typescript" ; export class Rule extends Lint . Rules . AbstractRule { public static metadata : Lint . IRuleMetadata = { ruleName : "jsx-no-multiline-js" , description : "Checks for multiline JS expressions inside JSX expressions" , descriptionDetails : "This helps reduce mental overhead when parsing JSX syntax" , options : null , optionsDescription : "" , optionExamples : [ "true" ] , type : "style" , typescriptOnly : false , } ; public static FAILURE_STRING = "Multiline JS expressions inside JSX are forbidden" ; public apply ( sourceFile ) { return this . applyWithFunction ( sourceFile , walk ) ; } } function walk ( ctx ) { return ts . forEachChild ( ctx . sourceFile , function cb ( node ) : void { if ( isJsxExpression ( node ) ) { if ( node . getText ( ) . indexOf ( "\n" ) > - 1 ) { ctx . addFailureAt ( node . getStart ( ) , node . getWidth ( ) , Rule . FAILURE_STRING ) ; } } return ts . forEachChild ( node , cb ) ; } ) ; }