SonarJS icon indicating copy to clipboard operation
SonarJS copied to clipboard

armor parser poc

Open saberduck opened this issue 9 months ago • 1 comments

To run, first build

in the root npm run bf

in its/plugin/plugins/eslint-custom-rules-plugin mvn install

Then you can execute com.sonar.javascript.it.plugin.EslintCustomRulesTest

In the output you should see that ArmorConsumer is invoked for each JS file

ArmorConsumer: src/dir/file.ts
ArmorConsumer: src/dir/Person.js

and then ArmorSensor is executed and prints stringified AST

13:54:35.649 INFO: Sensor Armor Sensor [javascript]
[{"type":"1","body":"2","comments":"3","range":"4","sourceType":"5","tokens":"6","loc":"7","parent":null},"Program",["8"],["9"],[56,63],"module",["10","11","12","13"],{"start":"14","end":"15"},{"type":"16","expression":"17","range":"18","loc":"19","parent":"0"},{"type":"20","value":"21","range":"22","loc":"23"},{"type":"24","value":"25","range":"26","loc":"27"},{"type":"28","value":"29","range":"30","loc":"31"},{"type":"28","value":"32","range":"33","loc":"34"},{"type":"28","value":"35","range":"36","loc":"37"},{"line":4,"column":0},{"line":5,"column":0},"ExpressionStatement",{"type":"38","callee":"39","arguments":"40","optional":false,"range":"41","loc":"42","parent":"8"},[56,62],{"start":"43","end":"44"},"Line"," eslint based custom rule reports on CallExpression",[2,55],{"start":"45","end":"46"},"Identifier","foo",[56,59],{"start":"47","end":"48"},"Punctuator","(",[59,60],{"start":"49","end":"50"},")",[60,61],{"start":"51","end":"52"},";",[61,62],{"start":"53","end":"54"},"CallExpression",{"type":"24","decorators":"55","name":"25","optional":false,"range":"56","loc":"57","parent":"17"},[],[56,61],{"start":"58","end":"59"},{"line":4,"column":0},{"line":4,"column":6},{"line":3,"column":0},{"line":3,"column":53},{"line":4,"column":0},{"line":4,"column":3},{"line":4,"column":3},{"line":4,"column":4},{"line":4,"column":4},{"line":4,"column":5},{"line":4,"column":5},{"line":4,"column":6},[],[56,59],{"start":"60","end":"61"},{"line":4,"column":0},{"line":4,"column":5},{"line":4,"column":0},{"line":4,"column":3}]
[{"type":"1","body":"2","comments":"3","range":"4","sourceType":"5","tokens":"6","loc":"7","parent":null},"Program",["8","9","10","11","12"],["13","14","15","16","17"],[24,366],"module",["18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80"],{"start":"81","end":"82"},{"type":"83","declarations":"84","declare":false,"kind":"85","range":"86","loc":"87","parent":"0"},{"type":"83","declarations":"88","declare":false,"kind":"85","range":"89","loc":"90","parent":"0"},{"type":"91","left":"92","right":"93","body":"94","range":"95","loc":"96","parent":"0"},{"type":"97","test":"98","body":"99","range":"100","loc":"101","parent":"0"},{"type":"102","expression":"103","range":"104","loc":"105","parent":"0"},{"type":"106","value":"107","range":"108","loc":"109"},{"type":"106","value":"110","range":"111","loc":"112"},{"type":"113","value":"114","range":"115","loc":"116"},{"type":"106","value":"117","range":"118","loc":"119"},{"type":"113","value":"120","range":"121","loc":"122"},{"type":"123","value":"85","range":"124","loc":"125"},{"type":"126","value":"127","range":"128","loc":"129"},{"type":"130","value":"131","range":"132","loc":"133"},{"type":"123","value":"134","range":"135","loc":"136"},{"type":"130","value":"137","range":"138","loc":"139"},{"type":"126","value":"140","range":"141","loc":"142"},{"type":"130","value":"143","range":"144","loc":"145"},{"type":"126","value":"146","range":"147","loc":"148"},{"type":"130","value":"143","range":"149","loc":"150"},{"type":"126","value":"151","range":"152","loc":"153"},{"type":"130","value":"154","range":"155","loc":"156"},{"type":"130","value":"157","range":"158","loc":"159"},{"type":"123","value":"160","range":"161","loc":"162"},{"type":"130","value":"163","range":"164","loc":"165"},{"type":"126","value":"140","range":"166","loc":"167"},{"type":"130","value":"131","range":"168","loc":"169"},{"type":"126","value":"140","range":"170","loc":"171"},{"type":"130","value":"172","range":"173","loc":"174"},{"type":"123","value":"160","range":"175","loc":"176"},{"type":"130","value":"163","range":"177","loc":"178"},{"type":"126","value":"151","range":"179","loc":"180"},{"type":"130","value":"131","range":"181","loc":"182"},{"type":"126","value":"151","range":"183","loc":"184"},{"type":"130","value":"172","range":"185","loc":"186"},{"type":"123","value":"160","range":"187","loc":"188"},{"type":"130","value":"163","range":"189","loc":"190"},{"type":"126","value":"146","range":"191","loc":"192"},{"type":"130","value":"131","range":"193","loc":"194"},{"type":"126","value":"146","range":"195","loc":"196"},{"type":"130","value":"172","range":"197","loc":"198"},{"type":"130","value":"199","range":"200","loc":"201"},{"type":"130","value":"172","range":"202","loc":"203"},{"type":"123","value":"85","range":"204","loc":"205"},{"type":"126","value":"206","range":"207","loc":"208"},{"type":"130","value":"131","range":"209","loc":"210"},{"type":"130","value":"211","range":"212","loc":"213"},{"type":"214","value":"215","range":"216","loc":"217"},{"type":"130","value":"143","range":"218","loc":"219"},{"type":"214","value":"220","range":"221","loc":"222"},{"type":"130","value":"143","range":"223","loc":"224"},{"type":"214","value":"225","range":"226","loc":"227"},{"type":"130","value":"228","range":"229","loc":"230"},{"type":"130","value":"172","range":"231","loc":"232"},{"type":"123","value":"233","range":"234","loc":"235"},{"type":"130","value":"137","range":"236","loc":"237"},{"type":"126","value":"238","range":"239","loc":"240"},{"type":"123","value":"241","range":"242","loc":"243"},{"type":"126","value":"206","range":"244","loc":"245"},{"type":"130","value":"154","range":"246","loc":"247"},{"type":"130","value":"157","range":"248","loc":"249"},{"type":"130","value":"199","range":"250","loc":"251"},{"type":"123","value":"252","range":"253","loc":"254"},{"type":"130","value":"137","range":"255","loc":"256"},{"type":"126","value":"257","range":"258","loc":"259"},{"type":"130","value":"260","range":"261","loc":"262"},{"type":"214","value":"263","range":"264","loc":"265"},{"type":"130","value":"154","range":"266","loc":"267"},{"type":"130","value":"157","range":"268","loc":"269"},{"type":"130","value":"199","range":"270","loc":"271"},{"type":"126","value":"272","range":"273","loc":"274"},{"type":"130","value":"137","range":"275","loc":"276"},{"type":"130","value":"154","range":"277","loc":"278"},{"type":"130","value":"172","range":"279","loc":"280"},{"line":2,"column":0},{"line":22,"column":0},"VariableDeclaration",["281"],"var",[24,138],{"start":"282","end":"283"},["284"],[172,196],{"start":"285","end":"286"},"ForInStatement",{"type":"126","decorators":"287","name":"238","optional":false,"range":"288","loc":"289","parent":"10"},{"type":"126","decorators":"290","name":"206","optional":false,"range":"291","loc":"292","parent":"10"},{"type":"293","body":"294","range":"295","loc":"296","parent":"10"},[198,243],{"start":"297","end":"298"},"WhileStatement",{"type":"299","operator":"260","left":"300","right":"301","range":"302","loc":"303","parent":"11"},{"type":"293","body":"304","range":"305","loc":"306","parent":"11"},[286,303],{"start":"307","end":"308"},"ExpressionStatement",{"type":"309","callee":"310","arguments":"311","optional":false,"range":"312","loc":"313","parent":"12"},[359,365],{"start":"314","end":"315"},"Block","* BaseTreeVisitor *",[0,23],{"start":"316","end":"317"},"* SubscriptionBaseVisitor *",[140,171],{"start":"318","end":"319"},"Line"," do something;",[225,241],{"start":"320","end":"321"},"*\n * SubscriptionBaseVisitorCheck2\n ",[245,285],{"start":"322","end":"323"}," eslint based custom rule reports on CallExpression",[305,358],{"start":"324","end":"325"},"Keyword",[24,27],{"start":"326","end":"327"},"Identifier","Person",[28,34],{"start":"328","end":"329"},"Punctuator","=",[35,36],{"start":"330","end":"331"},"function",[37,45],{"start":"332","end":"333"},"(",[46,47],{"start":"334","end":"335"},"first",[47,52],{"start":"336","end":"337"},",",[52,53],{"start":"338","end":"339"},"last",[54,58],{"start":"340","end":"341"},[58,59],{"start":"342","end":"343"},"middle",[60,66],{"start":"344","end":"345"},")",[66,67],{"start":"346","end":"347"},"{",[68,69],{"start":"348","end":"349"},"this",[72,76],{"start":"350","end":"351"},".",[76,77],{"start":"352","end":"353"},[77,82],{"start":"354","end":"355"},[83,84],{"start":"356","end":"357"},[85,90],{"start":"358","end":"359"},";",[90,91],{"start":"360","end":"361"},[94,98],{"start":"362","end":"363"},[98,99],{"start":"364","end":"365"},[99,105],{"start":"366","end":"367"},[106,107],{"start":"368","end":"369"},[108,114],{"start":"370","end":"371"},[114,115],{"start":"372","end":"373"},[118,122],{"start":"374","end":"375"},[122,123],{"start":"376","end":"377"},[123,127],{"start":"378","end":"379"},[128,129],{"start":"380","end":"381"},[130,134],{"start":"382","end":"383"},[134,135],{"start":"384","end":"385"},"}",[136,137],{"start":"386","end":"387"},[137,138],{"start":"388","end":"389"},[172,175],{"start":"390","end":"391"},"myArray",[176,183],{"start":"392","end":"393"},[184,185],{"start":"394","end":"395"},"[",[186,187],{"start":"396","end":"397"},"Numeric","1",[187,188],{"start":"398","end":"399"},[188,189],{"start":"400","end":"401"},"2",[190,191],{"start":"402","end":"403"},[191,192],{"start":"404","end":"405"},"3",[193,194],{"start":"406","end":"407"},"]",[194,195],{"start":"408","end":"409"},[195,196],{"start":"410","end":"411"},"for",[198,201],{"start":"412","end":"413"},[202,203],{"start":"414","end":"415"},"props",[203,208],{"start":"416","end":"417"},"in",[209,211],{"start":"418","end":"419"},[212,219],{"start":"420","end":"421"},[219,220],{"start":"422","end":"423"},[221,222],{"start":"424","end":"425"},[242,243],{"start":"426","end":"427"},"while",[286,291],{"start":"428","end":"429"},[292,293],{"start":"430","end":"431"},"i",[293,294],{"start":"432","end":"433"},">",[295,296],{"start":"434","end":"435"},"10",[297,299],{"start":"436","end":"437"},[299,300],{"start":"438","end":"439"},[301,302],{"start":"440","end":"441"},[302,303],{"start":"442","end":"443"},"foo",[359,362],{"start":"444","end":"445"},[362,363],{"start":"446","end":"447"},[363,364],{"start":"448","end":"449"},[364,365],{"start":"450","end":"451"},{"type":"452","definite":false,"id":"453","init":"454","range":"455","loc":"456","parent":"8"},{"line":2,"column":0},{"line":6,"column":2},{"type":"452","definite":false,"id":"457","init":"458","range":"459","loc":"460","parent":"9"},{"line":9,"column":0},{"line":9,"column":24},[],[203,208],{"start":"461","end":"462"},[],[212,219],{"start":"463","end":"464"},"BlockStatement",[],[221,243],{"start":"465","end":"466"},{"line":11,"column":0},{"line":13,"column":1},"BinaryExpression",{"type":"126","decorators":"467","name":"257","optional":false,"range":"468","loc":"469","parent":"98"},{"type":"470","value":10,"raw":"263","range":"471","loc":"472","parent":"98"},[293,299],{"start":"473","end":"474"},[],[301,303],{"start":"475","end":"476"},{"line":18,"column":0},{"line":18,"column":17},"CallExpression",{"type":"126","decorators":"477","name":"272","optional":false,"range":"478","loc":"479","parent":"103"},[],[359,364],{"start":"480","end":"481"},{"line":21,"column":0},{"line":21,"column":6},{"line":1,"column":0},{"line":1,"column":23},{"line":8,"column":0},{"line":8,"column":31},{"line":12,"column":2},{"line":12,"column":18},{"line":15,"column":0},{"line":17,"column":3},{"line":20,"column":0},{"line":20,"column":53},{"line":2,"column":0},{"line":2,"column":3},{"line":2,"column":4},{"line":2,"column":10},{"line":2,"column":11},{"line":2,"column":12},{"line":2,"column":13},{"line":2,"column":21},{"line":2,"column":22},{"line":2,"column":23},{"line":2,"column":23},{"line":2,"column":28},{"line":2,"column":28},{"line":2,"column":29},{"line":2,"column":30},{"line":2,"column":34},{"line":2,"column":34},{"line":2,"column":35},{"line":2,"column":36},{"line":2,"column":42},{"line":2,"column":42},{"line":2,"column":43},{"line":2,"column":44},{"line":2,"column":45},{"line":3,"column":2},{"line":3,"column":6},{"line":3,"column":6},{"line":3,"column":7},{"line":3,"column":7},{"line":3,"column":12},{"line":3,"column":13},{"line":3,"column":14},{"line":3,"column":15},{"line":3,"column":20},{"line":3,"column":20},{"line":3,"column":21},{"line":4,"column":2},{"line":4,"column":6},{"line":4,"column":6},{"line":4,"column":7},{"line":4,"column":7},{"line":4,"column":13},{"line":4,"column":14},{"line":4,"column":15},{"line":4,"column":16},{"line":4,"column":22},{"line":4,"column":22},{"line":4,"column":23},{"line":5,"column":2},{"line":5,"column":6},{"line":5,"column":6},{"line":5,"column":7},{"line":5,"column":7},{"line":5,"column":11},{"line":5,"column":12},{"line":5,"column":13},{"line":5,"column":14},{"line":5,"column":18},{"line":5,"column":18},{"line":5,"column":19},{"line":6,"column":0},{"line":6,"column":1},{"line":6,"column":1},{"line":6,"column":2},{"line":9,"column":0},{"line":9,"column":3},{"line":9,"column":4},{"line":9,"column":11},{"line":9,"column":12},{"line":9,"column":13},{"line":9,"column":14},{"line":9,"column":15},{"line":9,"column":15},{"line":9,"column":16},{"line":9,"column":16},{"line":9,"column":17},{"line":9,"column":18},{"line":9,"column":19},{"line":9,"column":19},{"line":9,"column":20},{"line":9,"column":21},{"line":9,"column":22},{"line":9,"column":22},{"line":9,"column":23},{"line":9,"column":23},{"line":9,"column":24},{"line":11,"column":0},{"line":11,"column":3},{"line":11,"column":4},{"line":11,"column":5},{"line":11,"column":5},{"line":11,"column":10},{"line":11,"column":11},{"line":11,"column":13},{"line":11,"column":14},{"line":11,"column":21},{"line":11,"column":21},{"line":11,"column":22},{"line":11,"column":23},{"line":11,"column":24},{"line":13,"column":0},{"line":13,"column":1},{"line":18,"column":0},{"line":18,"column":5},{"line":18,"column":6},{"line":18,"column":7},{"line":18,"column":7},{"line":18,"column":8},{"line":18,"column":9},{"line":18,"column":10},{"line":18,"column":11},{"line":18,"column":13},{"line":18,"column":13},{"line":18,"column":14},{"line":18,"column":15},{"line":18,"column":16},{"line":18,"column":16},{"line":18,"column":17},{"line":21,"column":0},{"line":21,"column":3},{"line":21,"column":3},{"line":21,"column":4},{"line":21,"column":4},{"line":21,"column":5},{"line":21,"column":5},{"line":21,"column":6},"VariableDeclarator",{"type":"126","decorators":"482","name":"127","optional":false,"range":"483","loc":"484","parent":"281"},{"type":"485","async":false,"body":"486","declare":false,"expression":false,"generator":false,"id":null,"params":"487","range":"488","loc":"489","parent":"281"},[28,137],{"start":"490","end":"491"},{"type":"126","decorators":"492","name":"206","optional":false,"range":"493","loc":"494","parent":"284"},{"type":"495","elements":"496","range":"497","loc":"498","parent":"284"},[176,195],{"start":"499","end":"500"},{"line":11,"column":5},{"line":11,"column":10},{"line":11,"column":14},{"line":11,"column":21},{"line":11,"column":23},{"line":13,"column":1},[],[293,294],{"start":"501","end":"502"},"Literal",[297,299],{"start":"503","end":"504"},{"line":18,"column":7},{"line":18,"column":13},{"line":18,"column":15},{"line":18,"column":17},[],[359,362],{"start":"505","end":"506"},{"line":21,"column":0},{"line":21,"column":5},[],[28,34],{"start":"507","end":"508"},"FunctionExpression",{"type":"293","body":"509","range":"510","loc":"511","parent":"454"},["512","513","514"],[37,137],{"start":"515","end":"516"},{"line":2,"column":4},{"line":6,"column":1},[],[176,183],{"start":"517","end":"518"},"ArrayExpression",["519","520","521"],[186,195],{"start":"522","end":"523"},{"line":9,"column":4},{"line":9,"column":23},{"line":18,"column":7},{"line":18,"column":8},{"line":18,"column":11},{"line":18,"column":13},{"line":21,"column":0},{"line":21,"column":3},{"line":2,"column":4},{"line":2,"column":10},["524","525","526"],[68,137],{"start":"527","end":"528"},{"type":"126","decorators":"529","name":"140","optional":false,"range":"530","loc":"531","parent":"454"},{"type":"126","decorators":"532","name":"146","optional":false,"range":"533","loc":"534","parent":"454"},{"type":"126","decorators":"535","name":"151","optional":false,"range":"536","loc":"537","parent":"454"},{"line":2,"column":13},{"line":6,"column":1},{"line":9,"column":4},{"line":9,"column":11},{"type":"470","value":1,"raw":"215","range":"538","loc":"539","parent":"458"},{"type":"470","value":2,"raw":"220","range":"540","loc":"541","parent":"458"},{"type":"470","value":3,"raw":"225","range":"542","loc":"543","parent":"458"},{"line":9,"column":14},{"line":9,"column":23},{"type":"102","expression":"544","range":"545","loc":"546","parent":"486"},{"type":"102","expression":"547","range":"548","loc":"549","parent":"486"},{"type":"102","expression":"550","range":"551","loc":"552","parent":"486"},{"line":2,"column":44},{"line":6,"column":1},[],[47,52],{"start":"553","end":"554"},[],[54,58],{"start":"555","end":"556"},[],[60,66],{"start":"557","end":"558"},[187,188],{"start":"559","end":"560"},[190,191],{"start":"561","end":"562"},[193,194],{"start":"563","end":"564"},{"type":"565","operator":"131","left":"566","right":"567","range":"568","loc":"569","parent":"524"},[72,91],{"start":"570","end":"571"},{"type":"565","operator":"131","left":"572","right":"573","range":"574","loc":"575","parent":"525"},[94,115],{"start":"576","end":"577"},{"type":"565","operator":"131","left":"578","right":"579","range":"580","loc":"581","parent":"526"},[118,135],{"start":"582","end":"583"},{"line":2,"column":23},{"line":2,"column":28},{"line":2,"column":30},{"line":2,"column":34},{"line":2,"column":36},{"line":2,"column":42},{"line":9,"column":15},{"line":9,"column":16},{"line":9,"column":18},{"line":9,"column":19},{"line":9,"column":21},{"line":9,"column":22},"AssignmentExpression",{"type":"584","object":"585","property":"586","computed":false,"optional":false,"range":"587","loc":"588","parent":"544"},{"type":"126","decorators":"589","name":"140","optional":false,"range":"590","loc":"591","parent":"544"},[72,90],{"start":"592","end":"593"},{"line":3,"column":2},{"line":3,"column":21},{"type":"584","object":"594","property":"595","computed":false,"optional":false,"range":"596","loc":"597","parent":"547"},{"type":"126","decorators":"598","name":"151","optional":false,"range":"599","loc":"600","parent":"547"},[94,114],{"start":"601","end":"602"},{"line":4,"column":2},{"line":4,"column":23},{"type":"584","object":"603","property":"604","computed":false,"optional":false,"range":"605","loc":"606","parent":"550"},{"type":"126","decorators":"607","name":"146","optional":false,"range":"608","loc":"609","parent":"550"},[118,134],{"start":"610","end":"611"},{"line":5,"column":2},{"line":5,"column":19},"MemberExpression",{"type":"612","range":"613","loc":"614","parent":"566"},{"type":"126","decorators":"615","name":"140","optional":false,"range":"616","loc":"617","parent":"566"},[72,82],{"start":"618","end":"619"},[],[85,90],{"start":"620","end":"621"},{"line":3,"column":2},{"line":3,"column":20},{"type":"612","range":"622","loc":"623","parent":"572"},{"type":"126","decorators":"624","name":"151","optional":false,"range":"625","loc":"626","parent":"572"},[94,105],{"start":"627","end":"628"},[],[108,114],{"start":"629","end":"630"},{"line":4,"column":2},{"line":4,"column":22},{"type":"612","range":"631","loc":"632","parent":"578"},{"type":"126","decorators":"633","name":"146","optional":false,"range":"634","loc":"635","parent":"578"},[118,127],{"start":"636","end":"637"},[],[130,134],{"start":"638","end":"639"},{"line":5,"column":2},{"line":5,"column":18},"ThisExpression",[72,76],{"start":"640","end":"641"},[],[77,82],{"start":"642","end":"643"},{"line":3,"column":2},{"line":3,"column":12},{"line":3,"column":15},{"line":3,"column":20},[94,98],{"start":"644","end":"645"},[],[99,105],{"start":"646","end":"647"},{"line":4,"column":2},{"line":4,"column":13},{"line":4,"column":16},{"line":4,"column":22},[118,122],{"start":"648","end":"649"},[],[123,127],{"start":"650","end":"651"},{"line":5,"column":2},{"line":5,"column":11},{"line":5,"column":14},{"line":5,"column":18},{"line":3,"column":2},{"line":3,"column":6},{"line":3,"column":7},{"line":3,"column":12},{"line":4,"column":2},{"line":4,"column":6},{"line":4,"column":7},{"line":4,"column":13},{"line":5,"column":2},{"line":5,"column":6},{"line":5,"column":7},{"line":5,"column":11}]
13:54:35.649 INFO: Sensor Armor Sensor [javascript] (done) | time=0ms

saberduck avatar May 14 '24 10:05 saberduck