I am trying to create a script using grep and/or awk that answers the questions listed below (refer to the figures for visual reference)
Motivations: The reports generated by ESLint address each individual file and the potential violations for each file - but from what I understand I can't generate any statistics to help someone perform a secure code review on this.
Note: I used the ESLint config file for ScanJS to generate these text file reports but I want to make them easier to read.
Edit:
I formatted the rules so each of them looks like this:
accidental_assignment
instead of:
"scanjs-rules/accidental_assignment": 1
Then I ran this command:
while read l; do grep -i "${l//\"/}" results.txt; done < rules.txt
The nice part about this: it prints out each rule violation in alphabetical order, and identifers to help you look through the results.txt file.
Resulting image: link
Desired improvements: I still want it to print out the actual rule and then the count - as shown in Figure 3. Any suggestions?
You should be able to count lines containing searched string with this command :
cat results.txt | grep <searched> | wc -l
All together
for f in `sed -e 's/"\(.*\/\)\(.*\)\(".*\)/\1\2/' pattern.txt`;
do printf $f' - '; cat result.txt | grep $f | wc -l;
done
will print result like
scanjs-rules/accidental_assignment - 2
scanjs-rules/assign_to_hostname - 2
scanjs-rules/assign_to_href - 4
Where
$ cat pattern.txt
"scanjs-rules/accidental_assignment":1,
"scanjs-rules/assign_to_hostname":1,
"scanjs-rules/assign_to_href":1,
and result file sample:
$cat result.txt
This is dummy line
312:9 warrning from scanjs-rules/accidental_assignment
Another dummy line
Another dummy line
Another dummy line
312:9 warrning from scanjs-rules/assign_to_hostname
312:9 warrning from scanjs-rules/accidental_assignment
Another dummy line
312:9 warrning from scanjs-rules/assign_to_href
Another dummy line
312:9 warrning from unsafe scanjs-rules/assign_to_hostname
312:9 warrning from scanjs-rules/assign_to_href
312:9 warrning from scanjs-rules/assign_to_href
312:9 warrning from scanjs-rules/assign_to_href