Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Ignore a line with a single comment #144

Closed
sheam opened this issue Jun 2, 2014 · 31 comments · Fixed by #1175
Closed

Ignore a line with a single comment #144

sheam opened this issue Jun 2, 2014 · 31 comments · Fixed by #1175

Comments

@sheam
Copy link

sheam commented Jun 2, 2014

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.

@ashwinr
Copy link
Contributor

ashwinr commented Jun 3, 2014

unfortunately, we don't have such a thing yet. you have to enable & disable the line explictly.

@sheam
Copy link
Author

sheam commented Jun 3, 2014

How do you disable a line?

@ashwinr
Copy link
Contributor

ashwinr commented Jun 3, 2014

https://github.com/palantir/tslint#tslint-rule-flags

@ashwinr ashwinr closed this as completed Jun 3, 2014
@allenhwkim
Copy link

For anyone here to find the a workaround solution

/* tslint:disable */ - Disable all rules for the rest of the file
/* tslint:enable */ - Enable all rules for the rest of the file

e.g.
/* tslint:disable */ window['foo']= window['bar']; /* tslint:enable */

@patsissons
Copy link
Contributor

has there been any investigation into implementing a feature similar as described above?

@adidahiya
Copy link
Contributor

@patsissons what feature exactly? It is currently possible to enable/disable a single line with two comments.

@patsissons
Copy link
Contributor

the feature would be less verbose line disabling. ESLint has multiple methods of doing single line rule disabes.

For example,

// eslint-disable-next-line rule-name
var x; // eslint-disable-line rule1 rule2

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).

@lijunle
Copy link
Contributor

lijunle commented Apr 18, 2016

This is noisy:

/* tslint:disable */ window['foo']= window['bar']; /* tslint:enable */

This is much better:

var x; // eslint-disable-line rule1 rule2

@justinmchase
Copy link

Or even just:

var x; // tslint:disable

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:

var x; // tslint:disable-line

@adidahiya adidahiya changed the title Ignore a line Ignore a line with a single comment Apr 27, 2016
@adidahiya adidahiya reopened this Apr 27, 2016
@adidahiya
Copy link
Contributor

accepting PRs for this. here's a recent somewhat related change that allowed // instead of /* comments for disabling (two comments are still required though): #1134

@patsissons
Copy link
Contributor

I will try and get to this tonight, if it's not too challenging hopefully a PR tonight too

@jkillian
Copy link
Contributor

👍 Let's follow closely to ESLint here:

someCode(); // tslint:disable-line

// tslint:disable-next-line
someCode();

and

someCode(); // tslint:disable-line:rule1 rule2

// tslint:disable-next-line:rule1
someCode();

@patsissons
Copy link
Contributor

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).

@jkillian
Copy link
Contributor

jkillian commented Apr 28, 2016

👍 Let's stick with the TSLint style for consistency

@patsissons
Copy link
Contributor

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 -line and -next-line variants into their equivalent fully expressed comment switches. This is done by tracking the line start position (for -line switches) and performing a look-ahead for end of the following line (for -next-line switches). These seems to work quite well and has minimal side effects since it is simply acting as an alias for the more verbose format.

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

@lijunle
Copy link
Contributor

lijunle commented Apr 28, 2016

Question about the implementation, does this work?

/**
 * this is a very long line and violate max-line-length. // tslint:disable-line:max-line-length
 */

@patsissons
Copy link
Contributor

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.

@lijunle
Copy link
Contributor

lijunle commented Apr 28, 2016

Thanks for clarification, got it.

@patsissons
Copy link
Contributor

@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.

@phil123456
Copy link

none of the above works
are you people talking about features proposition or already implemented ones ?
hard to follow

@adidahiya
Copy link
Contributor

@phil123456 https://github.com/palantir/tslint#rule-flags

// tslint:disable-next-line <optional rule identifier>
var foo = 123;

@jimmy-guo
Copy link

^Link has moved here: https://github.com/palantir/tslint/blob/master/docs/usage/rule-flags/index.md

@pbarranis
Copy link

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?

@justinmchase
Copy link

@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.

@samuela
Copy link
Contributor

samuela commented Sep 23, 2018

By the way, you can also do it on the same line:

console.log("poop"); // tslint:disable-line no-console

At least as of tslint@5.11.0.

@jajaperson
Copy link
Contributor

This doesn't work with rules like ordered-imports

@JNaeemGitonga
Copy link

JNaeemGitonga commented May 30, 2019

//@ts-ignore
https://palantir.github.io/tslint/rules/

@toniaf
Copy link

toniaf commented Jun 10, 2019

//@ts-ignore
https://palantir.github.io/tslint/rules/

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/
And I agree with the comment above that asked WHY doesnt this page mention the words "suppress" or "ignore" so it can be easily found when using Google?
FYI this page now says TSLint is being EOL this year : https://github.com/palantir/tslint#tslint-rule-flags

@rrsai
Copy link

rrsai commented May 11, 2020

Ah, tslint is eventually (not yet) getting merged in to eslint, so that's nice I suppose.

@lamualfa
Copy link

The point is, now tslint supports the ignore next line feature.

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/

@JoshuaKGoldberg
Copy link
Contributor

🤖 Beep boop! 👉 TSLint is deprecated 👈 and you should switch to typescript-eslint! 🤖

🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋

@palantir palantir locked and limited conversation to collaborators Sep 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.