Skip to content

Commit

Permalink
Update with badges
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Chen committed Mar 3, 2017
1 parent 98bfa1a commit 31c757f
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 14 deletions.
5 changes: 2 additions & 3 deletions _data/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
{
"ruleName": "completed-docs",
"description": "Enforces documentation for important items be filled out.",
"optionsDescription": "\n `true` to enable for [\"classes\", \"functions\", \"methods\", \"properties\"],\n or an array with each item in one of two formats:\n\n* `string` to enable for that type\n* `object` keying types to when their documentation is required:\n * `\"methods\"` and `\"properties may specify:\n * `\"privacies\":\n * `\"all\"`\n * `\"private\"`\n * `\"protected\"`\n * `\"public\"`\n * `\"locations:\n * `\"all\"`\n * `\"instance\"`\n * `\"static\"`\n * All other types may specify `\"visibilities\"`:\n * `\"all\"`\n * `\"exported\"`\n * `\"internal\"`\n\nTypes that may be enabled are:\n\n * `\"classes\"`\n * `\"enums\"`\n * `\"functions\"`\n * `\"interfaces\"`\n * `\"methods\"`\n * `\"namespaces\"`\n * `\"properties\"`\n * `\"types\"`\n * `\"variables\"`",
"optionsDescription": "\n`true` to enable for [\"classes\", \"functions\", \"methods\", \"properties\"],\nor an array with each item in one of two formats:\n\n* `string` to enable for that type\n* `object` keying types to when their documentation is required:\n * `\"methods\"` and `\"properties may specify:\n * `\"privacies\":\n * `\"all\"`\n * `\"private\"`\n * `\"protected\"`\n * `\"public\"`\n * `\"locations:\n * `\"all\"`\n * `\"instance\"`\n * `\"static\"`\n * All other types may specify `\"visibilities\"`:\n * `\"all\"`\n * `\"exported\"`\n * `\"internal\"`\n\nTypes that may be enabled are:\n\n * `\"classes\"`\n * `\"enums\"`\n * `\"functions\"`\n * `\"interfaces\"`\n * `\"methods\"`\n * `\"namespaces\"`\n * `\"properties\"`\n * `\"types\"`\n * `\"variables\"`",
"options": {
"type": "array",
"items": {
Expand Down Expand Up @@ -1378,8 +1378,7 @@
},
{
"ruleName": "no-unused-variable",
"deprecationMessage": "Use the tsc compiler options --noUnusedParameters and --noUnusedLocals instead.",
"description": "Disallows unused imports, variables, functions and private class members.",
"description": "Disallows unused imports, variables, functions and\n private class members. Similar to tsc's --noUnusedParameters and --noUnusedLocals\n options, but does not interrupt code compilation.",
"hasFix": true,
"optionsDescription": "\nThree optional arguments may be optionally provided:\n\n* `\"check-parameters\"` disallows unused function and constructor parameters.\n * NOTE: this option is experimental and does not work with classes\n that use abstract method declarations, among other things.\n* `\"react\"` relaxes the rule for a namespace import named `React`\n(from either the module `\"react\"` or `\"react/addons\"`).\nAny JSX expression in the file will be treated as a usage of `React`\n(because it expands to `React.createElement `).\n* `{\"ignore-pattern\": \"pattern\"}` where pattern is a case-sensitive regexp.\nVariable names that match the pattern will be ignored.",
"options": {
Expand Down
19 changes: 17 additions & 2 deletions _includes/rule_list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<ul>
<ul class="rules-list">
{% assign rules = site.data.rules | where: "type",include.ruleType | sort: "name" %}
{% for rule in rules %}
<li><a href="{{rule.ruleName}}">{{rule.ruleName}}</a> - {{rule.description | markdownify | remove:"<p>" | remove: "</p>"}}</li>
<li>
<a href="{{rule.ruleName}}">
<div class="rule-features">
{% if rule.typescriptOnly %}
<span class="feature feature-sm feature-ts-only" title="This rule cannot be run against JavaScript files">TS Only</span>
{% endif %}
{% if rule.hasFix %}
<span class="feature feature-sm feature-fixer" title="This rule has the ability to auto-fix violations">Has Fixer</span>
{% endif %}
{% if rule.requiresTypeInfo %}
<span class="feature feature-sm feature-requires-type-info" title="This rule requires type information to run">Requires Type Info</span>
{% endif %}
</div>
<strong>{{rule.ruleName}}</strong> - {{rule.description | markdownify | remove:"<p>" | remove: "</p>"}}
</a>
</li>
{% endfor %}
</ul>
18 changes: 14 additions & 4 deletions _layouts/rule.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@
<h5>Rationale</h5>
{{page.rationale | markdownify}}
{% endif %}
{% if page.requiresTypeInfo %}
<strong>Note:</strong>
<a href="https://github.com/palantir/tslint#type-checking">This rule requires type info to run</a>
{% endif %}

{% if page.typescriptOnly or page.hasFix or page.requiresTypeInfo %}
<h5>Notes: </h5>
<div class="rule-features">
{% if page.typescriptOnly %}
<span class="feature feature-ts-only" title="This rule cannot be run against JavaScript files">TS Only</span>
{% endif %}
{% if page.hasFix %}
<span class="feature feature-fixer" title="This rule has the ability to auto-fix violations">Has Fixer</span>
{% endif %}
{% if page.requiresTypeInfo %}
<a class="feature feature-requires-type-info" href="https://github.com/palantir/tslint#type-checking" title="This rule requires type information to run. Click to learn more.">Requires Type Info</a>
{% endif %}
</div>
{% endif %}

<h3>Config</h3>
{{page.optionsDescription | markdownify}}
Expand Down
103 changes: 103 additions & 0 deletions _sass/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,106 @@ figcaption {
}
}
}


/**
* Rules & Feature Badges
*/
.rules-list {
list-style: none;
margin: 0 !important; //need to override the `main-content ul` selector

> li {
&:nth-child(odd) {
a {
background-color: rgba(0, 0, 0, .03);
}
}

a {
display: block;
border-left: 3px solid transparent;
text-decoration: none;
padding: .75rem;

&:hover {
background-color: rgba(0, 0, 0,.075);
border-left-color: #159957;
}
}
}
}

.rule-features {
//This is the container for a list of feature badges
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}

.feature {
//This is the setup for the a feature badge
display: inline-block;
margin-right: 2px;
padding: 2px 4px;
font-weight: 700;
line-height: 1;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
border: 1px solid transparent;
border-radius: .25rem;
cursor: help;

&:before {
//This is the setup for the icon that appears inside the badge
display: inline-block;
margin-right: 2px;
}

&.feature-sm {
//This class is added to make the feature badge smaller. This is used on the rules list
padding: 1px 3px;
font-size: 75%;
}

&.feature-ts-only {
//This feature badge is added to rules that are "TypeScript Only"
background-color: #FCF8E3;
border-color: #FAF2CC;
color: #8A6D3B;

&:before {
content: "\1F4C4"; //"page facing up" icon - http://www.fileformat.info/info/unicode/char/1F4C4/index.htm
}
}

&.feature-fixer {
//This feature badge is added to rules that have an auto-fixer
background-color: #DFF0D8;
border-color: #D0E9C6;
color: #3C763D;

&:before {
content: "\1f527"; //"wrench" icon - http://www.fileformat.info/info/unicode/char/1f527/index.htm
}
}

&.feature-requires-type-info {
//This feature badge is added to rules that require type information
background-color: #F2DEDE;
border-color: #EBCCCC;
color: #A94442;

&:before {
content: "\2139"; //"information source" icon - http://www.fileformat.info/info/unicode/char/2139/index.htm
//Surround it with a blue circle
border-radius: 50%;
background: #0078D7;
color: #FFF;
width: 1em;
}
}
}
2 changes: 1 addition & 1 deletion develop/custom-rules/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Some examples:
`node.getStart()` scans the source to skip all the leading trivia. Although barely noticeable, this operation is not for free.
If you need the start position of a node more than once per function, consider caching it.
`node.getWidth()` is most of the time used together with `node.getStart()` to get the node's span. Internally it uses `node.getStart() - node.getEnd()` which effectively doubles the calls to `node.getStart()`. Consider using `node.getEnd()` instead and calculate the width yourself if necessary.
`node.getWidth()` is most of the time used together with `node.getStart()` to get the node's span. Internally it uses `node.getEnd() - node.getStart()` which effectively doubles the calls to `node.getStart()`. Consider using `node.getEnd()` instead and calculate the width yourself if necessary.
`node.getText()` calculates the start of the node and returns a substring until the end of the token.
Most of the time this not needed, because this substring is already contained in the node.
Expand Down
4 changes: 2 additions & 2 deletions rules/completed-docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
description: Enforces documentation for important items be filled out.
optionsDescription: |-

`true` to enable for ["classes", "functions", "methods", "properties"],
or an array with each item in one of two formats:
`true` to enable for ["classes", "functions", "methods", "properties"],
or an array with each item in one of two formats:

* `string` to enable for that type
* `object` keying types to when their documentation is required:
Expand Down
6 changes: 4 additions & 2 deletions rules/no-unused-variable/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
ruleName: no-unused-variable
deprecationMessage: Use the tsc compiler options --noUnusedParameters and --noUnusedLocals instead.
description: 'Disallows unused imports, variables, functions and private class members.'
description: |-
Disallows unused imports, variables, functions and
private class members. Similar to tsc's --noUnusedParameters and --noUnusedLocals
options, but does not interrupt code compilation.
hasFix: true
optionsDescription: |-

Expand Down

0 comments on commit 31c757f

Please sign in to comment.