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

Examples of correct and incorrect code #3594

Closed
inad9300 opened this issue Dec 19, 2017 · 6 comments
Closed

Examples of correct and incorrect code #3594

inad9300 opened this issue Dec 19, 2017 · 6 comments

Comments

@inad9300
Copy link

I find myself very often searching for examples online, since TSLint's docs are lacking them. For TSLint to be useful, one must know what its rules are about, and this is currently not provided by the documentation alone.

The ESLint team did a great job in this regard, and I think you should take inspiration from them, e.g. https://eslint.org/docs/rules/no-empty.

If this is not under consideration already, please consider it 🙂

@ajafff
Copy link
Contributor

ajafff commented Dec 19, 2017

Closing as a duplicate of #1329

For the time being the easiest way to understand a rule is to look at the tests.

@ajafff ajafff closed this as completed Dec 19, 2017
@inad9300
Copy link
Author

Thanks for the housekeeping efforts, and sorry for the duplicates.

@inad9300
Copy link
Author

Actually, can you guide me a bit on how to understand the tests? They are somewhat cryptic.

@ajafff
Copy link
Contributor

ajafff commented Dec 20, 2017

The test consist of different line types:

Code lines everything that is not listed below.

Message substitution (or template)
[name]: message are typically located at the bottom of the file. They define names that can be reused in error markup

Error Markup
~~~~~ [error message] the squiggles are located below a code line at the position the error is shown. The error message is either the real message or the name of a message substitution.
~nil means the error has a width of 0.
~~~ or ~nil without an error message indicate an error that continues on the next line.
[foo % ('a', 'b')] interpolates the strings a and b into the message substitution identified by foo. The substitution is done by node's util.format.

Example:

foo(b);
    ~ [err % ('a', 'b')]
eval('some code');
~~~~~~~~~~~~~~~~~ [Usage of 'eval' is forbidden.]

[err]: Use '%s' instead of '%s'.

The above means there is an error Use 'a' instead of 'b'. on the first line at the identifier b.
There's also an error on the eval() call. That message is not substituted.

@adidahiya
Copy link
Contributor

the testing markup is documented here: https://palantir.github.io/tslint/develop/testing-rules/

@inad9300
Copy link
Author

Thanks to both 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants