Forbid developper to disable any TSLint rule
Asked Answered
C

1

6

I'm leading a team working on Angular2+/Typescript project and I just want to know if there is a way to disallow disabling any TSLint rules.

We are using VSCode and my team's developpers trend to disable rules for to many line:

enter image description here

After clicking on "Disable rule 'typeof-compare' for this line", TSLint add a comments above the line that disables the rule for this line.

enter image description here

Cappella answered 8/1, 2018 at 8:39 Comment(5)
You need to think of all the way people disable these rules ? If through the config, maybe find a way to lock that file and prevent modifications ?Masbate
@Masbate I've updated the question to show the way they disable the rules for some line of the codeCappella
you already got an answer. it's the only reasonable way. Check linting on deployment / build where your devs have no access to.Donothingism
I submitted tslint - Issue #3675 for a rule to enforce a policy around rule disabling. I'm not looking to disallow all disabling, but to limit it to certain forms.Emissivity
@RyanGustafson ThanksCappella
O
12

You cannot force or prevent people from disabling any rules in their environment. At the end, it's their environment and they should have sufficient freedom to do things.

What you can do is to enforce your tsLint rules at CI level or commit level. Make sure your source code pass any coding style you specified.

UPDATE: Regarding your need, code review or pair programming would be the only way to prevent this.

You may be tempted to ask tsLint to provide an option to ignore these disable commits, but they are there for a reason.

There are cases you do want to use these comments as the TypeScript compiler or tsLint are just tools, they cannot fully understand the context of your code, so there are legit cases that these comments make sense.

Try to use TypeScript, tsLint, and any other tools as a TOOL. They are meant to help you and your team in developing quality software, not trying to restrict, prohibit, or punish people. :)

(Note that I include TypeScript as a tool, that is the best approach IMO towards using TypeScript)

Oculus answered 8/1, 2018 at 8:45 Comment(6)
I already enforce TSLint rule at CI level but the rule is just diabled by the comment added by developper in source code, above the line concerned by the rule so when Linting at CI level, those lines passes the rule checksCappella
@Cappella maybe a bit ugly, but you could just remove the comments before linting, especially easy cause they all start with // tslint:Donothingism
@lexith Do you know a tools that can be used to do that at CI level ?Cappella
@Cappella depends on your current setup what the easiest way would be. First of all, i would talk to my devs that disabling lint rules manually is forbidden. That would be the easiest way. ;) If you have to be sure, than you could maybe use a gulp task that does it for you -> gulp-strip-comments would be one package i just found: npmjs.com/package/gulp-strip-commentsDonothingism
@lexith Thank you!Cappella
actually, that belongs to a code review, if you don't allow any rule breaking, then how are you gonna tackle when you do need to disable certain rule in some usecase? We have tons of // tslint:disable-next-line:no-submodule-imports, but we still use that rule, and everything gets heavily reviewed before merging :)Mclaughlin

© 2022 - 2024 — McMap. All rights reserved.