-
Notifications
You must be signed in to change notification settings - Fork 888
Ignore a line with a single comment #144
Comments
unfortunately, we don't have such a thing yet. you have to enable & disable the line explictly. |
How do you disable a line? |
For anyone here to find the a workaround solution
e.g. |
has there been any investigation into implementing a feature similar as described above? |
@patsissons what feature exactly? It is currently possible to enable/disable a single line with two comments. |
the feature would be less verbose line disabling. For example,
The wrapping method is great as a redundancy for complex rule disables, but inline (or next-line) tends to leave the code less polluted (this is my opinion of course, but probably not that unreasonable). |
This is noisy: /* tslint:disable */ window['foo']= window['bar']; /* tslint:enable */ This is much better: var x; // eslint-disable-line rule1 rule2 |
Or even just:
The fact that it's a line comment would imply that it would only disable that one line just fine I think. Or at worst:
|
accepting PRs for this. here's a recent somewhat related change that allowed |
I will try and get to this tonight, if it's not too challenging hopefully a PR tonight too |
👍 Let's follow closely to ESLint here:
and
|
That's precisely what I would like to achieve 👍 though, just for clarity, ESLint does not use colons, their style is the following: // eslint-disable-next-line rule1, rule2
someCode(); I will assume that you would prefer we stick to the TSLint style that you included above (colons and no commas separating rules). |
👍 Let's stick with the TSLint style for consistency |
I have this working now and I am just going through some commit cleanup before i create the PR. The strategy was to covert the Just a note before I get my PR in order, due to the way the disabled interval code works, you won't be able to do something like this // tslint:disable-next-line:quotemark variable-name
var AAAaA = 'test' // tslint:enable-line variable-name I honestly never expect someone to do something like that, but I just wanted to note it here. You can still do standard nesting like this // tslint:disable
var AAAaA = 'test' // tslint:enable-line:quotemark
// tslint:enable-next-line:variable-name
var AAAaA = 'test'
// tslint:enable |
Question about the implementation, does this work? /**
* this is a very long line and violate max-line-length. // tslint:disable-line:max-line-length
*/ |
No, the switch comments are not parsed like that, they must be formatted correctly. I believe in your example, you would place the single line disable comment outside the multi-line comment and that ought to work as expected. |
Thanks for clarification, got it. |
@lijunle just revisiting your example, I think my explanation was actually somewhat incorrect. I don't think you could achieve your intended result with single line disables. I believe the parser would not be able to reach back to properly disable the whole multi-line comment. to disable a rule in a multi-line comment you would need to wrap the comment with a switch pair. |
none of the above works |
@phil123456 https://github.com/palantir/tslint#rule-flags // tslint:disable-next-line <optional rule identifier>
var foo = 123; |
^Link has moved here: https://github.com/palantir/tslint/blob/master/docs/usage/rule-flags/index.md |
Bloody hell. Neither the words "suppress" nor "ignore" appear in that documentation. I can't believe how much googling it took to lead me to this issue, read all the stuff above, only to find it's a supported, documented feature, but the appropriate keywords aren't in the docs so it's impossible to Google. Do you have to clone the whole repo and submit a PR for that, or is there a quicker way to suggest fixes to .md files? |
@pbarranis you can make a new ticket with that as a feature request. If they don't make the change then making a PR might be the next step. |
By the way, you can also do it on the same line: console.log("poop"); // tslint:disable-line no-console At least as of [email protected]. |
This doesn't work with rules like |
|
unfortunately this page only shows how to ban usage of this. It doesnt show how to use it properly or explain how much tsLint ignores when you use that. Dont know why it's not mentioned on this page which explains how to suppress rules https://palantir.github.io/tslint/usage/rule-flags/ |
Ah, tslint is eventually (not yet) getting merged in to eslint, so that's nice I suppose. |
The point is, now Example: // tslint:disable-next-line Or // tslint:disable-next-line:rule1 rule2 rule3 For more detail & example see https://palantir.github.io/tslint/usage/rule-flags/ |
🤖 Beep boop! 👉 TSLint is deprecated 👈 and you should switch to typescript-eslint! 🤖 🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋 |
Is there a way to ignore a single line, like in jshint?
I have tried // tslint ignore:line but that does not seem to work.
The text was updated successfully, but these errors were encountered: