Skip to content

Commit b9c19dd

Browse files
committed
Implement deprecation notice
Render a deprecation notice for options that have been labeled with the JSDoc `@deprecated` tag.
1 parent cde1e11 commit b9c19dd

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
"build": "oddweb build ."
1010
},
1111
"dependencies": {
12-
"dox": "^0.5.3",
13-
"oddweb": "~0.0.4",
12+
"dox": "^0.6.1",
1413
"jshint": "latest",
14+
"marked": "^0.3.2",
15+
"oddweb": "~0.0.4",
1516
"sqwish": "0.2.x",
1617
"uglify-js": "2.4.x"
1718
},

plugins/options.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"use strict";
22
var fs = require("fs")
33
var dox = require("dox");
4+
var marked = require("marked");
45

56
var optionsSrc = __dirname + "/../res/jshint/src/options.js";
7+
var deprecationMsg = "<strong>Warning</strong> This option has been " +
8+
"deprecated and will be removed in the next major release of JSHint."
69

710
dox.setMarkedOptions({
811
breaks: false
@@ -38,12 +41,31 @@ function getCategory(annotation) {
3841
return name;
3942
}
4043

44+
function getDeprecationReason(annotation) {
45+
var tags = annotation.tags;
46+
var idx, length, tag;
47+
48+
if (!tags) {
49+
return null;
50+
}
51+
52+
for (idx = 0, length = tags.length; idx < length; ++idx) {
53+
tag = tags[idx];
54+
if (tag.type === 'deprecated') {
55+
return tag.string;
56+
}
57+
}
58+
59+
return null;
60+
}
61+
4162
options.annotations.map(function(annotation) {
4263
var name = annotation.code.split(":")[0];
4364
var option = options.parsed[name];
4465

4566
annotation.name = name.trim();
4667
annotation.category = getCategory(annotation);
68+
annotation.deprecationReason = getDeprecationReason(annotation);
4769

4870
return annotation;
4971
}).forEach(function(annotation) {
@@ -62,13 +84,26 @@ function table2html(annotations) {
6284

6385
return header + annotations.map(function(annotation) {
6486
var name = annotation.name;
87+
var description = '';
88+
89+
if (annotation.deprecationReason) {
90+
description += "<div class='deprecation-msg'>" + deprecationMsg + " " +
91+
// TODO: Remove this when the `dox` module is updated to also parse
92+
// annotations for Markdown.
93+
// See: "Parse tag strings with Markdown"
94+
// https://github.com/tj/dox/pull/139
95+
marked(annotation.deprecationReason) +
96+
"</div>";
97+
}
98+
99+
description += annotation.description.full;
65100

66101
return [
67102
"<tr>",
68103
"<td class='name' id='" + name + "'>",
69104
"<a href='#" + name + "'>" + name + "</a>",
70105
"</td>",
71-
"<td class='desc'>" + annotation.description.full + "</td>",
106+
"<td class='desc'>" + description + "</td>",
72107
"</tr>"
73108
].join("\n");
74109
}).join("\n") + footer;

res/docs.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,16 @@ a.anchor {
4949
.blog-list .link {
5050
padding-left: 20px;
5151
}
52+
53+
.deprecation-msg {
54+
margin-bottom: 1em;
55+
}
56+
57+
.deprecation-msg strong {
58+
font-weight: bold;
59+
}
60+
61+
.deprecation-msg p {
62+
display: inline;
63+
margin: 0;
64+
}

0 commit comments

Comments
 (0)