0

I want to write a script that takes a javascript file and iterate through it line by line and check for single-line code comments. If there are any then push it to array and return that array.

For Example:

const array=[1,2,3,4,5];
//This comment needs to be detected and pushed to a new array

I have searched a lot about it and work through the Eslint(JS linter) but there is not any rule for single-line-comment but do have a rule for block-comment.

Suleman Ahmad
  • 452
  • 1
  • 5
  • 14
  • you can read the whole file and as soon as you get two consecutive // you can start populating the array until you find \n character. try it and post your code here if you run into problems – Ali Tahir Sep 15 '20 at 12:27
  • 1
    you can also use regex: https://stackoverflow.com/questions/49178646/regex-for-single-line-comments – Ali Tahir Sep 15 '20 at 12:31
  • Ok. I am currently working on this specific task. Thanks for feedback! – Suleman Ahmad Sep 15 '20 at 12:31

0 Answers0