1

Occasionally in our codebase we need to use an //eslint-disable to bypass a styleguide rule on a line. I would like to somehow automatically add a comment on each new instance of that in PRs, requiring the developer to explain why they bypassed the styleguide.

I've found this question referencing how to create a comment programmatically, but what I'm not sure how to do is identify the new code and parse it for a certain piece of text, then add comments on those particular lines where the text was found.

SaintWacko
  • 854
  • 3
  • 14
  • 35

1 Answers1

0

This is one of the approaches to ingest scripts & achieve what you want, wherein Expected outcome is: On every pull request, a pre build validation pipeline kicks off & adds comments on the PR.

Create a script (powershell/python/bash) with following logic:

  1. Find file names in the given branch which contains //eslint-disable
  2. In the files above (1.), get the location/line number of //eslint-disable
  3. Foreach file.LineNumber (wrote like that just for representation): add comment on file.LineNumber using Pull Request Threads API. See line parameter

Create a pipeline containing above script & add that pipeline as build validation or if you have an existing build validation process, add these scripts as tasks in that pipeline.

Hope this helps :)

progrover
  • 51
  • 3