doyensec / electronegativity

Electronegativity is a tool to identify misconfigurations and security anti-patterns in Electron applications.
Apache License 2.0
972 stars 66 forks source link

Allow `eng-disable` comments to be placed above lines of code #93

Open mitchchn opened 3 years ago

mitchchn commented 3 years ago

Is your feature request related to a problem? Please describe.

eng-disable comments must be placed on the same line as the relevant code, e.g.:

contents.on("will-navigate", (ev) => { /* eng-disable LIMIT_NAVIGATION_GLOBAL_CHECK */
   ev.preventDefault();
});

This limitation poses a problem for Prettier and similar tools which autoformat code and comments based on line length and other criteria. For instance, Prettier will automatically re-format the above code like this:

contents.on("will-navigate", (ev) => {
   /* eng-disable LIMIT_NAVIGATION_GLOBAL_CHECK */
   ev.preventDefault();
});

Describe the solution you'd like

The ability to put the comment above the relevant line:

// eng-disable LIMIT_NAVIGATION_GLOBAL_CHECK
contents.on("will-navigate", (ev) => {
  ev.preventDefault();
}); 

This approach is compatible with Prettier and follows a convention used by other tools including TypeScript (// ts-ignore) and ESLint. It is resilient to future formatting changes. In my opinion, it is also more readable. :)

Describe alternatives you've considered

Sometimes code can be re-written to make Prettier happy:

contents.on("will-navigate", handlerCallback); /* eng-disable LIMIT_NAVIGATION_GLOBAL_CHECK */

But this is not always desirable or guaranteed to work due to line length restrictions.