Add @ts-check to JS files without it, address resulting issues.

This commit is contained in:
David Anson 2019-10-30 20:37:06 -07:00
parent eacfa6142b
commit 37307d0764
7 changed files with 237 additions and 117 deletions

View file

@ -1,3 +1,5 @@
// @ts-check
"use strict"; "use strict";
const markdownlint = require("../lib/markdownlint"); const markdownlint = require("../lib/markdownlint");

View file

@ -1,3 +1,5 @@
// @ts-check
"use strict"; "use strict";
const gulp = require("gulp"); const gulp = require("gulp");

View file

@ -1,3 +1,5 @@
// @ts-check
"use strict"; "use strict";
const markdownlint = require("../lib/markdownlint"); const markdownlint = require("../lib/markdownlint");

View file

@ -1,3 +1,5 @@
// @ts-check
"use strict"; "use strict";
const fs = require("fs"); const fs = require("fs");
@ -359,6 +361,7 @@ rules.forEach(function forRule(rule) {
break; break;
} }
if (custom) { if (custom) {
// @ts-ignore
scheme.type = [ "boolean", "object" ]; scheme.type = [ "boolean", "object" ];
scheme.additionalProperties = false; scheme.additionalProperties = false;
} }

5
test/jsconfig.json Normal file
View file

@ -0,0 +1,5 @@
{
"compilerOptions": {
"resolveJsonModule": true
}
}

View file

@ -1,3 +1,5 @@
// @ts-check
"use strict"; "use strict";
const fs = require("fs"); const fs = require("fs");

View file

@ -1,3 +1,5 @@
// @ts-check
"use strict"; "use strict";
const fs = require("fs"); const fs = require("fs");
@ -1378,6 +1380,7 @@ module.exports.missingFilesAndStrings = function missingFilesAndStrings(test) {
module.exports.missingCallback = function missingCallback(test) { module.exports.missingCallback = function missingCallback(test) {
test.expect(0); test.expect(0);
// @ts-ignore
markdownlint(); markdownlint();
test.done(); test.done();
}; };
@ -1389,6 +1392,7 @@ module.exports.badFile = function badFile(test) {
}, function callback(err, result) { }, function callback(err, result) {
test.ok(err, "Did not get an error for bad file."); test.ok(err, "Did not get an error for bad file.");
test.ok(err instanceof Error, "Error not instance of Error."); test.ok(err instanceof Error, "Error not instance of Error.");
// @ts-ignore
test.equal(err.code, "ENOENT", "Error code for bad file not ENOENT."); test.equal(err.code, "ENOENT", "Error code for bad file not ENOENT.");
test.ok(!result, "Got result for bad file."); test.ok(!result, "Got result for bad file.");
test.done(); test.done();
@ -1586,12 +1590,18 @@ module.exports.doc = function doc(test) {
module.exports.validateConfigSchema = function validateConfigSchema(test) { module.exports.validateConfigSchema = function validateConfigSchema(test) {
const jsonFileRe = /\.json$/i; const jsonFileRe = /\.json$/i;
const resultsFileRe = /\.results\.json$/i; const resultsFileRe = /\.results\.json$/i;
const jsConfigFileRe = /^jsconfig\.json$/i;
const testDirectory = __dirname; const testDirectory = __dirname;
const testFiles = fs.readdirSync(testDirectory); const testFiles = fs.readdirSync(testDirectory);
testFiles.filter(function filterFile(file) { testFiles.filter(function filterFile(file) {
return jsonFileRe.test(file) && !resultsFileRe.test(file); return jsonFileRe.test(file) &&
!resultsFileRe.test(file) &&
!jsConfigFileRe.test(file);
}).forEach(function forFile(file) { }).forEach(function forFile(file) {
const data = fs.readFileSync(path.join(testDirectory, file)); const data = fs.readFileSync(
path.join(testDirectory, file),
helpers.utf8Encoding
);
test.ok( test.ok(
tv4.validate(JSON.parse(data), configSchema), tv4.validate(JSON.parse(data), configSchema),
file + "\n" + JSON.stringify(tv4.error, null, 2)); file + "\n" + JSON.stringify(tv4.error, null, 2));
@ -1873,94 +1883,94 @@ module.exports.forEachInlineCodeSpan = function forEachInlineCodeSpan(test) {
test.expect(99); test.expect(99);
const testCases = const testCases =
[ [
[ {
"`code`", "input": "`code`",
[ [ "code", 0, 1, 1 ] ] "expecteds": [ [ "code", 0, 1, 1 ] ]
], },
[ {
"text `code` text", "input": "text `code` text",
[ [ "code", 0, 6, 1 ] ] "expecteds": [ [ "code", 0, 6, 1 ] ]
], },
[ {
"text `code` text `edoc`", "input": "text `code` text `edoc`",
[ "expecteds": [
[ "code", 0, 6, 1 ], [ "code", 0, 6, 1 ],
[ "edoc", 0, 18, 1 ] [ "edoc", 0, 18, 1 ]
] ]
], },
[ {
"text `code` text `edoc` text", "input": "text `code` text `edoc` text",
[ "expecteds": [
[ "code", 0, 6, 1 ], [ "code", 0, 6, 1 ],
[ "edoc", 0, 18, 1 ] [ "edoc", 0, 18, 1 ]
] ]
], },
[ {
"text ``code`code`` text", "input": "text ``code`code`` text",
[ [ "code`code", 0, 7, 2 ] ] "expecteds": [ [ "code`code", 0, 7, 2 ] ]
], },
[ {
"`code `` code`", "input": "`code `` code`",
[ [ "code `` code", 0, 1, 1 ] ] "expecteds": [ [ "code `` code", 0, 1, 1 ] ]
], },
[ {
"`code\\`text`", "input": "`code\\`text`",
[ [ "code\\", 0, 1, 1 ] ] "expecteds": [ [ "code\\", 0, 1, 1 ] ]
], },
[ {
"``\ncode\n``", "input": "``\ncode\n``",
[ [ "\ncode\n", 0, 2, 2 ] ] "expecteds": [ [ "\ncode\n", 0, 2, 2 ] ]
], },
[ {
"text\n`code`\ntext", "input": "text\n`code`\ntext",
[ [ "code", 1, 1, 1 ] ] "expecteds": [ [ "code", 1, 1, 1 ] ]
], },
[ {
"text\ntext\n`code`\ntext\n`edoc`\ntext", "input": "text\ntext\n`code`\ntext\n`edoc`\ntext",
[ "expecteds": [
[ "code", 2, 1, 1 ], [ "code", 2, 1, 1 ],
[ "edoc", 4, 1, 1 ] [ "edoc", 4, 1, 1 ]
] ]
], },
[ {
"text `code\nedoc` text", "input": "text `code\nedoc` text",
[ [ "code\nedoc", 0, 6, 1 ] ] "expecteds": [ [ "code\nedoc", 0, 6, 1 ] ]
], },
[ {
"> text `code` text", "input": "> text `code` text",
[ [ "code", 0, 8, 1 ] ] "expecteds": [ [ "code", 0, 8, 1 ] ]
], },
[ {
"> text\n> `code`\n> text", "input": "> text\n> `code`\n> text",
[ [ "code", 1, 3, 1 ] ] "expecteds": [ [ "code", 1, 3, 1 ] ]
], },
[ {
"> text\n> `code\n> edoc`\n> text", "input": "> text\n> `code\n> edoc`\n> text",
[ [ "code\n> edoc", 1, 3, 1 ] ] "expecteds": [ [ "code\n> edoc", 1, 3, 1 ] ]
], },
[ {
"```text``", "input": "```text``",
[] "expecteds": []
], },
[ {
"text `text text", "input": "text `text text",
[] "expecteds": []
], },
[ {
"`text``code``", "input": "`text``code``",
[ [ "code", 0, 7, 2 ] ] "expecteds": [ [ "code", 0, 7, 2 ] ]
], },
[ {
"text \\` text `code`", "input": "text \\` text `code`",
[ [ "code", 0, 14, 1 ] ] "expecteds": [ [ "code", 0, 14, 1 ] ]
], },
[ {
"text\\\n`code`", "input": "text\\\n`code`",
[ [ "code", 1, 1, 1 ] ] "expecteds": [ [ "code", 1, 1, 1 ] ]
] }
]; ];
testCases.forEach((testCase) => { testCases.forEach((testCase) => {
const [ input, expecteds ] = testCase; const { input, expecteds } = testCase;
helpers.forEachInlineCodeSpan(input, (code, line, column, ticks) => { helpers.forEachInlineCodeSpan(input, (code, line, column, ticks) => {
const [ expectedCode, expectedLine, expectedColumn, expectedTicks ] = const [ expectedCode, expectedLine, expectedColumn, expectedTicks ] =
expecteds.shift(); expecteds.shift();
@ -3164,14 +3174,31 @@ module.exports.customRulesNpmPackage = function customRulesNpmPackage(test) {
module.exports.customRulesBadProperty = function customRulesBadProperty(test) { module.exports.customRulesBadProperty = function customRulesBadProperty(test) {
test.expect(92); test.expect(92);
[ [
[ "names", [ null, "string", [], [ null ], [ "" ], [ "string", 10 ] ] ], {
[ "description", [ null, 10, "", [] ] ], "propertyName": "names",
[ "information", [ 10, [], "string", "https://example.com" ] ], "propertyValues":
[ "tags", [ null, "string", [], [ null ], [ "" ], [ "string", 10 ] ] ], [ null, "string", [], [ null ], [ "" ], [ "string", 10 ] ]
[ "function", [ null, "string", [] ] ] },
].forEach(function forProperty(property) { {
const propertyName = property[0]; "propertyName": "description",
property[1].forEach(function forPropertyValue(propertyValue) { "propertyValues": [ null, 10, "", [] ]
},
{
"propertyName": "information",
"propertyValues": [ 10, [], "string", "https://example.com" ]
},
{
"propertyName": "tags",
"propertyValues":
[ null, "string", [], [ null ], [ "" ], [ "string", 10 ] ]
},
{
"propertyName": "function",
"propertyValues": [ null, "string", [] ]
}
].forEach(function forTestCase(testCase) {
const { propertyName, propertyValues } = testCase;
propertyValues.forEach(function forPropertyValue(propertyValue) {
const badRule = { ...customRules.anyBlockquote }; const badRule = { ...customRules.anyBlockquote };
badRule[propertyName] = propertyValue; badRule[propertyName] = propertyValue;
const options = { const options = {
@ -3385,17 +3412,53 @@ module.exports.customRulesOnErrorNull = function customRulesOnErrorNull(test) {
module.exports.customRulesOnErrorBad = function customRulesOnErrorBad(test) { module.exports.customRulesOnErrorBad = function customRulesOnErrorBad(test) {
test.expect(84); test.expect(84);
[ [
[ "lineNumber", null, [ null, "string" ] ], {
[ "detail", null, [ 10, [] ] ], "propertyName": "lineNumber",
[ "context", null, [ 10, [] ] ], "subPropertyName": null,
[ "range", null, [ 10, [], [ 10 ], [ 10, null ], [ 10, 11, 12 ] ] ], "propertyValues": [ null, "string" ]
[ "fixInfo", null, [ 10, "string" ] ], },
[ "fixInfo", "lineNumber", [ null, "string" ] ], {
[ "fixInfo", "editColumn", [ null, "string" ] ], "propertyName": "detail",
[ "fixInfo", "deleteCount", [ null, "string" ] ], "subPropertyName": null,
[ "fixInfo", "insertText", [ 10, [] ] ] "propertyValues": [ 10, [] ]
].forEach(function forProperty(property) { },
const [ propertyName, subPropertyName, propertyValues ] = property; {
"propertyName": "context",
"subPropertyName": null,
"propertyValues": [ 10, [] ]
},
{
"propertyName": "range",
"subPropertyName": null,
"propertyValues": [ 10, [], [ 10 ], [ 10, null ], [ 10, 11, 12 ] ]
},
{
"propertyName": "fixInfo",
"subPropertyName": null,
"propertyValues": [ 10, "string" ]
},
{
"propertyName": "fixInfo",
"subPropertyName": "lineNumber",
"propertyValues": [ null, "string" ]
},
{
"propertyName": "fixInfo",
"subPropertyName": "editColumn",
"propertyValues": [ null, "string" ]
},
{
"propertyName": "fixInfo",
"subPropertyName": "deleteCount",
"propertyValues": [ null, "string" ]
},
{
"propertyName": "fixInfo",
"subPropertyName": "insertText",
"propertyValues": [ 10, [] ]
}
].forEach(function forTestCase(testCase) {
const { propertyName, subPropertyName, propertyValues } = testCase;
propertyValues.forEach(function forPropertyValue(propertyValue) { propertyValues.forEach(function forPropertyValue(propertyValue) {
const badObject = { const badObject = {
"lineNumber": 1 "lineNumber": 1
@ -3443,13 +3506,33 @@ module.exports.customRulesOnErrorInvalid =
function customRulesOnErrorInvalid(test) { function customRulesOnErrorInvalid(test) {
test.expect(68); test.expect(68);
[ [
[ "lineNumber", null, [ -1, 0, 3, 4 ] ], {
[ "range", null, [ [ 0, 1 ], [ 1, 0 ], [ 5, 1 ], [ 1, 5 ], [ 4, 2 ] ] ], "propertyName": "lineNumber",
[ "fixInfo", "lineNumber", [ -1, 0, 3, 4 ] ], "subPropertyName": null,
[ "fixInfo", "editColumn", [ 0, 6 ] ], "propertyValues": [ -1, 0, 3, 4 ]
[ "fixInfo", "deleteCount", [ -2, 5 ] ] },
].forEach(function forProperty(property) { {
const [ propertyName, subPropertyName, propertyValues ] = property; "propertyName": "range",
"subPropertyName": null,
"propertyValues": [ [ 0, 1 ], [ 1, 0 ], [ 5, 1 ], [ 1, 5 ], [ 4, 2 ] ]
},
{
"propertyName": "fixInfo",
"subPropertyName": "lineNumber",
"propertyValues": [ -1, 0, 3, 4 ]
},
{
"propertyName": "fixInfo",
"subPropertyName": "editColumn",
"propertyValues": [ 0, 6 ]
},
{
"propertyName": "fixInfo",
"subPropertyName": "deleteCount",
"propertyValues": [ -2, 5 ]
}
].forEach(function forTestCase(testCase) {
const { propertyName, subPropertyName, propertyValues } = testCase;
propertyValues.forEach(function forPropertyValue(propertyValue) { propertyValues.forEach(function forPropertyValue(propertyValue) {
const badObject = { const badObject = {
"lineNumber": 1 "lineNumber": 1
@ -3497,18 +3580,39 @@ module.exports.customRulesOnErrorValid =
function customRulesOnErrorValid(test) { function customRulesOnErrorValid(test) {
test.expect(24); test.expect(24);
[ [
[ "lineNumber", null, [ 1, 2 ] ], {
[ "range", null, [ [ 1, 1 ], [ 1, 4 ], [ 2, 2 ], [ 3, 2 ], [ 4, 1 ] ] ], "propertyName": "lineNumber",
[ "fixInfo", "lineNumber", [ 1, 2 ] ], "subPropertyName": null,
[ "fixInfo", "editColumn", [ 1, 2, 4, 5 ] ], "propertyValues": [ 1, 2 ]
[ "fixInfo", "deleteCount", [ -1, 0, 1, 4 ] ], },
[ {
"fixInfo", "propertyName": "range",
"insertText", "subPropertyName": null,
[ "", "1", "123456", "\n", "\nText", "Text\n", "\nText\n" ] "propertyValues": [ [ 1, 1 ], [ 1, 4 ], [ 2, 2 ], [ 3, 2 ], [ 4, 1 ] ]
] },
].forEach(function forProperty(property) { {
const [ propertyName, subPropertyName, propertyValues ] = property; "propertyName": "fixInfo",
"subPropertyName": "lineNumber",
"propertyValues": [ 1, 2 ]
},
{
"propertyName": "fixInfo",
"subPropertyName": "editColumn",
"propertyValues": [ 1, 2, 4, 5 ]
},
{
"propertyName": "fixInfo",
"subPropertyName": "deleteCount",
"propertyValues": [ -1, 0, 1, 4 ]
},
{
"propertyName": "fixInfo",
"subPropertyName": "insertText",
"propertyValues":
[ "", "1", "123456", "\n", "\nText", "Text\n", "\nText\n" ]
}
].forEach(function forTestCase(testCase) {
const { propertyName, subPropertyName, propertyValues } = testCase;
propertyValues.forEach(function forPropertyValue(propertyValue) { propertyValues.forEach(function forPropertyValue(propertyValue) {
const goodObject = { const goodObject = {
"lineNumber": 1 "lineNumber": 1