2019-10-30 20:37:06 -07:00
// @ts-check
2015-02-23 23:39:20 -08:00
"use strict" ;
2018-04-27 22:05:34 -07:00
const fs = require ( "fs" ) ;
const path = require ( "path" ) ;
const md = require ( "markdown-it" ) ( ) ;
2019-01-19 12:52:13 -08:00
const pluginInline = require ( "markdown-it-for-inline" ) ;
const pluginSub = require ( "markdown-it-sub" ) ;
const pluginSup = require ( "markdown-it-sup" ) ;
2020-10-16 20:59:04 -07:00
const pluginTexMath = require ( "markdown-it-texmath" ) ;
2020-01-08 22:13:51 -08:00
const tape = require ( "tape" ) ;
2020-02-15 11:22:16 -08:00
require ( "tape-player" ) ;
2018-04-27 22:05:34 -07:00
const tv4 = require ( "tv4" ) ;
2019-01-15 21:56:38 -08:00
const packageJson = require ( "../package.json" ) ;
2018-04-27 22:05:34 -07:00
const markdownlint = require ( "../lib/markdownlint" ) ;
const rules = require ( "../lib/rules" ) ;
2018-07-20 22:31:41 -07:00
const customRules = require ( "./rules/rules.js" ) ;
2018-04-27 22:05:34 -07:00
const defaultConfig = require ( "./markdownlint-test-default-config.json" ) ;
const configSchema = require ( "../schema/markdownlint-config-schema.json" ) ;
2019-01-15 21:56:38 -08:00
const homepage = packageJson . homepage ;
const version = packageJson . version ;
2015-02-27 22:06:54 -08:00
2020-10-16 20:59:04 -07:00
const pluginTexMathOptions = {
"engine" : {
"renderToString" : ( ) => ""
}
} ;
2020-09-06 20:34:10 -07:00
const deprecatedRuleNames = new Set ( [ "MD002" , "MD006" ] ) ;
2020-09-15 21:48:00 -07:00
const configSchemaStrict = {
... configSchema ,
"additionalProperties" : false
} ;
2019-07-08 13:10:08 -05:00
2020-09-13 12:58:09 -07:00
tape ( "simpleAsync" , ( test ) => {
test . plan ( 2 ) ;
const options = {
"strings" : {
"content" : "# Heading"
}
} ;
const expected = "content: 1: MD047/single-trailing-newline " +
"Files should end with a single newline character" ;
markdownlint ( options , ( err , actual ) => {
test . ifError ( err ) ;
test . equal ( actual . toString ( ) , expected , "Unexpected results." ) ;
test . end ( ) ;
} ) ;
} ) ;
tape ( "simpleSync" , ( test ) => {
test . plan ( 1 ) ;
const options = {
"strings" : {
"content" : "# Heading"
}
} ;
const expected = "content: 1: MD047/single-trailing-newline " +
"Files should end with a single newline character" ;
const actual = markdownlint . sync ( options ) . toString ( ) ;
test . equal ( actual , expected , "Unexpected results." ) ;
test . end ( ) ;
} ) ;
tape ( "simplePromise" , ( test ) => {
test . plan ( 1 ) ;
const options = {
"strings" : {
"content" : "# Heading"
}
} ;
const expected = "content: 1: MD047/single-trailing-newline " +
"Files should end with a single newline character" ;
markdownlint . promises . markdownlint ( options ) . then ( ( actual ) => {
test . equal ( actual . toString ( ) , expected , "Unexpected results." ) ;
test . end ( ) ;
} ) ;
} ) ;
2020-09-06 16:31:26 -07:00
tape ( "projectFilesNoInlineConfig" , ( test ) => {
2020-01-08 22:13:51 -08:00
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2018-06-24 20:01:44 -07:00
"files" : [
"README.md" ,
2019-04-13 11:18:57 -07:00
"CONTRIBUTING.md" ,
2020-09-06 16:31:26 -07:00
"doc/CustomRules.md" ,
2019-04-13 11:18:57 -07:00
"helpers/README.md"
2018-06-24 20:01:44 -07:00
] ,
2017-05-21 22:58:10 -07:00
"noInlineConfig" : true ,
"config" : {
2020-09-06 16:31:26 -07:00
"line-length" : { "line_length" : 150 } ,
"no-duplicate-heading" : false
2017-05-21 22:58:10 -07:00
}
2015-03-12 23:42:06 -07:00
} ;
markdownlint ( options , function callback ( err , actual ) {
test . ifError ( err ) ;
2018-06-24 20:01:44 -07:00
const expected = {
"README.md" : [ ] ,
2019-04-13 11:18:57 -07:00
"CONTRIBUTING.md" : [ ] ,
2020-09-06 16:31:26 -07:00
"doc/CustomRules.md" : [ ] ,
2019-04-13 11:18:57 -07:00
"helpers/README.md" : [ ]
2018-06-24 20:01:44 -07:00
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actual , expected , "Issue(s) with project files." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-12 23:42:06 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-12 23:42:06 -07:00
2020-09-06 16:31:26 -07:00
tape ( "projectFilesInlineConfig" , ( test ) => {
test . plan ( 2 ) ;
const options = {
"files" : [ "doc/Rules.md" ] ,
"config" : {
"line-length" : { "line_length" : 150 } ,
"no-inline-html" : false
}
} ;
markdownlint ( options , function callback ( err , actual ) {
test . ifError ( err ) ;
const expected = {
"doc/Rules.md" : [ ]
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actual , expected , "Issue(s) with project files." ) ;
test . end ( ) ;
} ) ;
} ) ;
2020-01-08 22:13:51 -08:00
tape ( "stringInputLineEndings" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-04-29 18:46:52 -07:00
"strings" : {
2019-04-05 12:36:12 +02:00
"cr" : "One\rTwo\r#Three\n" ,
"lf" : "One\nTwo\n#Three\n" ,
"crlf" : "One\r\nTwo\r\n#Three\n" ,
2019-09-14 13:53:35 -07:00
"mixed" : "One\rTwo\n#Three\n"
2015-07-20 22:06:48 -07:00
} ,
2017-07-05 21:53:21 -07:00
"config" : defaultConfig ,
"resultVersion" : 0
2015-04-29 18:46:52 -07:00
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2015-05-02 17:41:41 -07:00
"cr" : { "MD018" : [ 3 ] } ,
2015-04-29 18:46:52 -07:00
"lf" : { "MD018" : [ 3 ] } ,
"crlf" : { "MD018" : [ 3 ] } ,
2019-09-14 13:53:35 -07:00
"mixed" : { "MD018" : [ 3 ] }
2015-04-29 18:46:52 -07:00
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-04-29 18:46:52 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-04-29 18:46:52 -07:00
2020-01-08 22:13:51 -08:00
tape ( "inputOnlyNewline" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-07-22 23:17:08 -07:00
"strings" : {
"cr" : "\r" ,
"lf" : "\n" ,
"crlf" : "\r\n"
} ,
"config" : {
"default" : false
}
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2017-07-05 21:53:21 -07:00
"cr" : [ ] ,
"lf" : [ ] ,
"crlf" : [ ]
2015-07-22 23:17:08 -07:00
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-07-22 23:17:08 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-07-22 23:17:08 -07:00
2020-01-08 22:13:51 -08:00
tape ( "defaultTrue" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-03-16 23:25:06 -07:00
"files" : [
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" ,
"./test/first_heading_bad_atx.md"
2015-03-16 23:25:06 -07:00
] ,
"config" : {
"default" : true
2017-07-05 21:53:21 -07:00
} ,
"resultVersion" : 0
2015-03-16 23:25:06 -07:00
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" : {
2015-03-16 23:25:06 -07:00
"MD018" : [ 1 ] ,
2015-07-20 22:06:48 -07:00
"MD019" : [ 3 , 5 ] ,
"MD041" : [ 1 ]
2015-03-16 23:25:06 -07:00
} ,
2018-03-19 23:39:42 +01:00
"./test/first_heading_bad_atx.md" : {
2015-07-20 22:06:48 -07:00
"MD041" : [ 1 ]
2015-03-16 23:25:06 -07:00
}
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-16 23:25:06 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-16 23:25:06 -07:00
2020-01-08 22:13:51 -08:00
tape ( "defaultFalse" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-03-16 23:25:06 -07:00
"files" : [
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" ,
"./test/first_heading_bad_atx.md"
2015-03-16 23:25:06 -07:00
] ,
"config" : {
"default" : false
2017-07-05 21:53:21 -07:00
} ,
"resultVersion" : 0
2015-03-16 23:25:06 -07:00
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" : { } ,
"./test/first_heading_bad_atx.md" : { }
2015-03-16 23:25:06 -07:00
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-16 23:25:06 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-16 23:25:06 -07:00
2020-01-08 22:13:51 -08:00
tape ( "defaultUndefined" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-03-18 22:45:51 -07:00
"files" : [
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" ,
"./test/first_heading_bad_atx.md"
2015-03-18 22:45:51 -07:00
] ,
2017-07-05 21:53:21 -07:00
"config" : { } ,
"resultVersion" : 0
2015-03-18 22:45:51 -07:00
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" : {
2015-03-18 22:45:51 -07:00
"MD018" : [ 1 ] ,
2015-07-20 22:06:48 -07:00
"MD019" : [ 3 , 5 ] ,
"MD041" : [ 1 ]
2015-03-18 22:45:51 -07:00
} ,
2018-03-19 23:39:42 +01:00
"./test/first_heading_bad_atx.md" : {
2015-07-20 22:06:48 -07:00
"MD041" : [ 1 ]
2015-03-18 22:45:51 -07:00
}
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-18 22:45:51 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-18 22:45:51 -07:00
2020-01-08 22:13:51 -08:00
tape ( "disableRules" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-03-16 23:25:06 -07:00
"files" : [
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" ,
"./test/first_heading_bad_atx.md"
2015-03-16 23:25:06 -07:00
] ,
"config" : {
"MD002" : false ,
"default" : true ,
2015-07-20 22:06:48 -07:00
"MD019" : false ,
2016-01-12 21:29:17 -08:00
"first-line-h1" : false
2017-07-05 21:53:21 -07:00
} ,
"resultVersion" : 0
2015-03-16 23:25:06 -07:00
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" : {
2015-03-16 23:25:06 -07:00
"MD018" : [ 1 ]
} ,
2018-03-19 23:39:42 +01:00
"./test/first_heading_bad_atx.md" : { }
2015-03-16 23:25:06 -07:00
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-16 23:25:06 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-16 23:25:06 -07:00
2020-01-08 22:13:51 -08:00
tape ( "enableRules" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-03-16 23:25:06 -07:00
"files" : [
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" ,
"./test/first_heading_bad_atx.md"
2015-03-16 23:25:06 -07:00
] ,
"config" : {
"MD002" : true ,
"default" : false ,
2016-01-12 21:29:17 -08:00
"no-multiple-space-atx" : true
2017-07-05 21:53:21 -07:00
} ,
"resultVersion" : 0
2015-03-16 23:25:06 -07:00
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" : {
2015-03-16 23:25:06 -07:00
"MD002" : [ 3 ] ,
"MD019" : [ 3 , 5 ]
} ,
2018-03-19 23:39:42 +01:00
"./test/first_heading_bad_atx.md" : {
2015-03-16 23:25:06 -07:00
"MD002" : [ 1 ]
}
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-16 23:25:06 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-16 23:25:06 -07:00
2020-01-08 22:13:51 -08:00
tape ( "enableRulesMixedCase" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-09-21 23:21:17 -07:00
"files" : [
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" ,
"./test/first_heading_bad_atx.md"
2015-09-21 23:21:17 -07:00
] ,
"config" : {
"Md002" : true ,
"DeFaUlT" : false ,
2016-01-12 21:29:17 -08:00
"nO-mUlTiPlE-sPaCe-AtX" : true
2017-07-05 21:53:21 -07:00
} ,
"resultVersion" : 0
2015-09-21 23:21:17 -07:00
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" : {
2015-09-21 23:21:17 -07:00
"MD002" : [ 3 ] ,
"MD019" : [ 3 , 5 ]
} ,
2018-03-19 23:39:42 +01:00
"./test/first_heading_bad_atx.md" : {
2015-09-21 23:21:17 -07:00
"MD002" : [ 1 ]
}
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-09-21 23:21:17 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-09-21 23:21:17 -07:00
2020-01-08 22:13:51 -08:00
tape ( "disableTag" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-03-16 23:25:06 -07:00
"files" : [
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" ,
"./test/first_heading_bad_atx.md"
2015-03-16 23:25:06 -07:00
] ,
"config" : {
"default" : true ,
"spaces" : false
2017-07-05 21:53:21 -07:00
} ,
"resultVersion" : 0
2015-03-16 23:25:06 -07:00
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" : {
2015-07-20 22:06:48 -07:00
"MD041" : [ 1 ]
2015-03-16 23:25:06 -07:00
} ,
2018-03-19 23:39:42 +01:00
"./test/first_heading_bad_atx.md" : {
2015-07-20 22:06:48 -07:00
"MD041" : [ 1 ]
2015-03-16 23:25:06 -07:00
}
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-16 23:25:06 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-16 23:25:06 -07:00
2020-01-08 22:13:51 -08:00
tape ( "enableTag" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-03-16 23:25:06 -07:00
"files" : [
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" ,
"./test/first_heading_bad_atx.md"
2015-03-16 23:25:06 -07:00
] ,
"config" : {
"default" : false ,
2015-09-26 16:55:33 -07:00
"spaces" : true ,
"notatag" : true
2017-07-05 21:53:21 -07:00
} ,
"resultVersion" : 0
2015-03-16 23:25:06 -07:00
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" : {
2015-03-16 23:25:06 -07:00
"MD018" : [ 1 ] ,
"MD019" : [ 3 , 5 ]
} ,
2018-03-19 23:39:42 +01:00
"./test/first_heading_bad_atx.md" : { }
2015-03-16 23:25:06 -07:00
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-16 23:25:06 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-16 23:25:06 -07:00
2020-01-08 22:13:51 -08:00
tape ( "enableTagMixedCase" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-09-21 23:21:17 -07:00
"files" : [
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" ,
"./test/first_heading_bad_atx.md"
2015-09-21 23:21:17 -07:00
] ,
"config" : {
"DeFaUlT" : false ,
2015-09-26 16:55:33 -07:00
"SpAcEs" : true ,
"NoTaTaG" : true
2017-07-05 21:53:21 -07:00
} ,
"resultVersion" : 0
2015-09-21 23:21:17 -07:00
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" : {
2015-09-21 23:21:17 -07:00
"MD018" : [ 1 ] ,
"MD019" : [ 3 , 5 ]
} ,
2018-03-19 23:39:42 +01:00
"./test/first_heading_bad_atx.md" : { }
2015-09-21 23:21:17 -07:00
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-09-21 23:21:17 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-09-21 23:21:17 -07:00
2020-01-08 22:13:51 -08:00
tape ( "styleFiles" , ( test ) => {
test . plan ( 4 ) ;
2015-03-17 22:34:47 -07:00
fs . readdir ( "./style" , function readdir ( err , files ) {
test . ifError ( err ) ;
files . forEach ( function forFile ( file ) {
test . ok ( require ( path . join ( "../style" , file ) ) , "Unable to load/parse." ) ;
} ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-17 22:34:47 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-17 22:34:47 -07:00
2020-01-08 22:13:51 -08:00
tape ( "styleAll" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-03-17 18:02:05 -07:00
"files" : [ "./test/break-all-the-rules.md" ] ,
2017-07-05 21:53:21 -07:00
"config" : require ( "../style/all.json" ) ,
"resultVersion" : 0
2015-03-17 18:02:05 -07:00
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2015-03-17 18:02:05 -07:00
"./test/break-all-the-rules.md" : {
"MD001" : [ 3 ] ,
2019-09-08 16:51:00 -07:00
"MD003" : [ 5 , 31 ] ,
2015-03-17 18:02:05 -07:00
"MD004" : [ 8 ] ,
"MD005" : [ 12 ] ,
"MD007" : [ 8 , 11 ] ,
"MD009" : [ 14 ] ,
"MD010" : [ 14 ] ,
"MD011" : [ 16 ] ,
"MD012" : [ 18 ] ,
"MD013" : [ 21 ] ,
"MD014" : [ 23 ] ,
"MD018" : [ 25 ] ,
"MD019" : [ 27 ] ,
"MD020" : [ 29 ] ,
2019-09-08 16:51:00 -07:00
"MD021" : [ 31 ] ,
2019-10-08 21:10:02 -07:00
"MD022" : [ 86 ] ,
2019-09-08 16:51:00 -07:00
"MD023" : [ 40 ] ,
"MD024" : [ 35 ] ,
2015-03-17 18:02:05 -07:00
"MD026" : [ 40 ] ,
"MD027" : [ 42 ] ,
"MD028" : [ 43 ] ,
"MD029" : [ 47 ] ,
"MD030" : [ 8 ] ,
"MD031" : [ 50 ] ,
2019-01-21 18:21:36 -08:00
"MD032" : [ 7 , 8 , 51 ] ,
2015-04-16 09:39:04 -07:00
"MD033" : [ 55 ] ,
"MD034" : [ 57 ] ,
"MD035" : [ 61 ] ,
"MD036" : [ 65 ] ,
"MD037" : [ 67 ] ,
"MD038" : [ 69 ] ,
"MD039" : [ 71 ] ,
2015-07-20 22:06:48 -07:00
"MD040" : [ 73 ] ,
2016-06-27 22:19:02 -07:00
"MD041" : [ 1 ] ,
2019-10-08 21:10:02 -07:00
"MD042" : [ 81 ] ,
"MD045" : [ 85 ] ,
"MD046" : [ 49 , 73 , 77 ] ,
"MD047" : [ 88 ] ,
"MD048" : [ 77 ]
2015-03-17 18:02:05 -07:00
}
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-17 18:02:05 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-17 18:02:05 -07:00
2020-01-08 22:13:51 -08:00
tape ( "styleRelaxed" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const options = {
2015-03-17 18:02:05 -07:00
"files" : [ "./test/break-all-the-rules.md" ] ,
2017-07-05 21:53:21 -07:00
"config" : require ( "../style/relaxed.json" ) ,
"resultVersion" : 0
2015-03-17 18:02:05 -07:00
} ;
markdownlint ( options , function callback ( err , actualResult ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2015-03-17 18:02:05 -07:00
"./test/break-all-the-rules.md" : {
"MD001" : [ 3 ] ,
2019-09-08 16:51:00 -07:00
"MD003" : [ 5 , 31 ] ,
2015-03-17 18:02:05 -07:00
"MD004" : [ 8 ] ,
"MD005" : [ 12 ] ,
"MD011" : [ 16 ] ,
"MD014" : [ 23 ] ,
"MD018" : [ 25 ] ,
"MD019" : [ 27 ] ,
"MD020" : [ 29 ] ,
2019-09-08 16:51:00 -07:00
"MD021" : [ 31 ] ,
2019-10-08 21:10:02 -07:00
"MD022" : [ 86 ] ,
2019-09-08 16:51:00 -07:00
"MD023" : [ 40 ] ,
"MD024" : [ 35 ] ,
2015-03-17 18:02:05 -07:00
"MD026" : [ 40 ] ,
"MD029" : [ 47 ] ,
"MD031" : [ 50 ] ,
2019-01-21 18:21:36 -08:00
"MD032" : [ 7 , 8 , 51 ] ,
2015-04-16 09:39:04 -07:00
"MD035" : [ 61 ] ,
2016-06-27 22:19:02 -07:00
"MD036" : [ 65 ] ,
2019-10-08 21:10:02 -07:00
"MD042" : [ 81 ] ,
"MD045" : [ 85 ] ,
"MD046" : [ 49 , 73 , 77 ] ,
"MD047" : [ 88 ] ,
"MD048" : [ 77 ]
2015-03-17 18:02:05 -07:00
}
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actualResult , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-17 18:02:05 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-17 18:02:05 -07:00
2020-01-08 22:13:51 -08:00
tape ( "nullFrontMatter" , ( test ) => {
test . plan ( 2 ) ;
2015-07-25 22:18:30 -07:00
markdownlint ( {
"strings" : {
2018-03-19 23:39:42 +01:00
"content" : "---\n\t\n---\n# Heading\n"
2015-07-25 22:18:30 -07:00
} ,
"frontMatter" : null ,
"config" : {
"default" : false ,
"MD010" : true
2017-07-05 21:53:21 -07:00
} ,
"resultVersion" : 0
2015-07-25 22:18:30 -07:00
} , function callback ( err , result ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2015-07-25 22:18:30 -07:00
"content" : { "MD010" : [ 2 ] }
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( result , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-07-25 22:18:30 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-07-25 22:18:30 -07:00
2020-01-08 22:13:51 -08:00
tape ( "customFrontMatter" , ( test ) => {
test . plan ( 2 ) ;
2015-07-25 22:18:30 -07:00
markdownlint ( {
"strings" : {
2018-03-19 23:39:42 +01:00
"content" : "<head>\n\t\n</head>\n# Heading\n"
2015-07-25 22:18:30 -07:00
} ,
"frontMatter" : /<head>[^]*<\/head>/ ,
"config" : {
"default" : false ,
"MD010" : true
}
} , function callback ( err , result ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2017-07-05 21:53:21 -07:00
"content" : [ ]
2015-07-25 22:18:30 -07:00
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( result , expectedResult , "Did not get empty results." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-07-25 22:18:30 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-07-25 22:18:30 -07:00
2020-01-08 22:13:51 -08:00
tape ( "noInlineConfig" , ( test ) => {
test . plan ( 2 ) ;
2017-05-21 22:58:10 -07:00
markdownlint ( {
"strings" : {
"content" : [
"# Heading" ,
"" ,
"\tTab" ,
"" ,
"<!-- markdownlint-disable-->" ,
"" ,
"\tTab" ,
"" ,
"<!-- markdownlint-enable-->" ,
"" ,
2019-04-05 12:36:12 +02:00
"\tTab\n"
2017-05-21 22:58:10 -07:00
] . join ( "\n" )
} ,
2017-07-05 21:53:21 -07:00
"noInlineConfig" : true ,
"resultVersion" : 0
2017-05-21 22:58:10 -07:00
} , function callback ( err , result ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2017-05-21 22:58:10 -07:00
"content" : {
"MD010" : [ 3 , 7 , 11 ]
}
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( result , expectedResult , "Undetected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2017-05-21 22:58:10 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2017-05-21 22:58:10 -07:00
2020-01-08 22:13:51 -08:00
tape ( "readmeHeadings" , ( test ) => {
test . plan ( 2 ) ;
2016-07-02 22:37:52 -07:00
markdownlint ( {
"files" : "README.md" ,
2017-05-21 22:58:10 -07:00
"noInlineConfig" : true ,
2016-07-02 22:37:52 -07:00
"config" : {
"default" : false ,
2016-10-16 21:46:02 -07:00
"MD013" : {
"line_length" : 150
} ,
2016-07-02 22:37:52 -07:00
"MD043" : {
2018-03-19 23:39:42 +01:00
"headings" : [
2016-07-02 22:37:52 -07:00
"# markdownlint" ,
"## Install" ,
"## Overview" ,
"### Related" ,
"## Demonstration" ,
"## Rules / Aliases" ,
"## Tags" ,
"## Configuration" ,
"## API" ,
2017-05-19 22:36:46 -07:00
"### Linting" ,
"#### options" ,
2018-02-15 21:35:58 -08:00
"##### options.customRules" ,
2017-05-19 22:36:46 -07:00
"##### options.files" ,
"##### options.strings" ,
"##### options.config" ,
2017-05-21 22:58:10 -07:00
"##### options.frontMatter" ,
2019-05-18 12:32:52 -07:00
"##### options.handleRuleFailures" ,
2017-05-21 22:58:10 -07:00
"##### options.noInlineConfig" ,
2017-05-19 22:36:46 -07:00
"##### options.resultVersion" ,
2019-01-19 12:52:13 -08:00
"##### options.markdownItPlugins" ,
2017-05-19 22:36:46 -07:00
"#### callback" ,
"#### result" ,
"### Config" ,
"#### file" ,
2018-05-23 22:24:40 -07:00
"#### parsers" ,
2017-05-19 22:36:46 -07:00
"#### callback" ,
"#### result" ,
2016-07-02 22:37:52 -07:00
"## Usage" ,
"## Browser" ,
2017-11-21 21:58:42 -08:00
"## Examples" ,
2018-06-24 20:01:44 -07:00
"## Contributing" ,
2016-07-02 22:37:52 -07:00
"## History"
]
}
}
} , function callback ( err , result ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expected = { "README.md" : [ ] } ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( result , expected , "Unexpected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2016-07-02 22:37:52 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2016-07-02 22:37:52 -07:00
2020-01-08 22:13:51 -08:00
tape ( "filesArrayNotModified" , ( test ) => {
test . plan ( 2 ) ;
2018-04-27 22:05:34 -07:00
const files = [
2018-03-19 23:39:42 +01:00
"./test/atx_heading_spacing.md" ,
"./test/first_heading_bad_atx.md"
2015-03-13 18:20:56 -07:00
] ;
2018-04-27 22:05:34 -07:00
const expectedFiles = files . slice ( ) ;
2015-03-13 18:20:56 -07:00
markdownlint ( { "files" : files } , function callback ( err ) {
test . ifError ( err ) ;
test . deepEqual ( files , expectedFiles , "Files modified." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-13 18:20:56 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-13 18:20:56 -07:00
2020-01-08 22:13:51 -08:00
tape ( "filesArrayAsString" , ( test ) => {
test . plan ( 2 ) ;
2016-01-15 22:00:34 -08:00
markdownlint ( {
"files" : "README.md" ,
2017-05-21 22:58:10 -07:00
"noInlineConfig" : true ,
"config" : {
"MD013" : { "line_length" : 150 } ,
"MD024" : false
}
2016-01-15 22:00:34 -08:00
} , function callback ( err , actual ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expected = { "README.md" : [ ] } ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actual , expected , "Unexpected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2016-01-15 22:00:34 -08:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2016-01-15 22:00:34 -08:00
2020-01-08 22:13:51 -08:00
tape ( "missingOptions" , ( test ) => {
test . plan ( 2 ) ;
2015-03-11 21:13:21 -07:00
markdownlint ( null , function callback ( err , result ) {
test . ifError ( err ) ;
2020-09-07 20:05:36 -07:00
test . deepEqual (
2020-09-05 17:24:52 -07:00
result ,
{ } ,
"Did not get empty result for missing options."
) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-11 21:13:21 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-11 21:13:21 -07:00
2020-01-08 22:13:51 -08:00
tape ( "missingFilesAndStrings" , ( test ) => {
test . plan ( 2 ) ;
2015-03-11 21:13:21 -07:00
markdownlint ( { } , function callback ( err , result ) {
test . ifError ( err ) ;
2015-04-29 18:46:52 -07:00
test . ok ( result , "Did not get result for missing files/strings." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-11 21:13:21 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-11 21:13:21 -07:00
2020-01-08 22:13:51 -08:00
tape ( "missingCallback" , ( test ) => {
test . plan ( 0 ) ;
2019-10-30 20:37:06 -07:00
// @ts-ignore
2015-03-11 21:13:21 -07:00
markdownlint ( ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
} ) ;
2015-03-11 21:13:21 -07:00
2020-01-08 22:13:51 -08:00
tape ( "badFile" , ( test ) => {
test . plan ( 4 ) ;
2015-03-11 21:13:21 -07:00
markdownlint ( {
"files" : [ "./badFile" ]
} , function callback ( err , result ) {
test . ok ( err , "Did not get an error for bad file." ) ;
2015-03-20 00:09:55 -07:00
test . ok ( err instanceof Error , "Error not instance of Error." ) ;
2019-10-30 20:37:06 -07:00
// @ts-ignore
2015-03-11 21:13:21 -07:00
test . equal ( err . code , "ENOENT" , "Error code for bad file not ENOENT." ) ;
test . ok ( ! result , "Got result for bad file." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-11 21:13:21 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-17 22:34:47 -07:00
2020-01-08 22:13:51 -08:00
tape ( "badFileSync" , ( test ) => {
test . plan ( 1 ) ;
test . throws (
function badFileCall ( ) {
markdownlint . sync ( {
"files" : [ "./badFile" ]
} ) ;
} ,
/ENOENT/ ,
"Did not get correct exception for bad file."
) ;
test . end ( ) ;
} ) ;
2015-03-20 00:09:55 -07:00
2020-09-13 12:58:09 -07:00
tape ( "badFilePromise" , ( test ) => {
test . plan ( 3 ) ;
markdownlint . promises . markdownlint ( {
"files" : [ "./badFile" ]
} ) . then (
null ,
( error ) => {
test . ok ( error , "Did not get an error for bad file." ) ;
test . ok ( error instanceof Error , "Error not instance of Error." ) ;
test . equal ( error . code , "ENOENT" , "Error code for bad file not ENOENT." ) ;
test . end ( ) ;
}
) ;
} ) ;
2020-01-08 22:13:51 -08:00
tape ( "missingStringValue" , ( test ) => {
test . plan ( 2 ) ;
2015-04-29 18:46:52 -07:00
markdownlint ( {
"strings" : {
"undefined" : undefined ,
"null" : null ,
"empty" : ""
2015-07-20 22:06:48 -07:00
} ,
"config" : defaultConfig
2015-04-29 18:46:52 -07:00
} , function callback ( err , result ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const expectedResult = {
2017-07-05 21:53:21 -07:00
"undefined" : [ ] ,
"null" : [ ] ,
"empty" : [ ]
2015-04-29 18:46:52 -07:00
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( result , expectedResult , "Did not get empty results." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-04-29 18:46:52 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-04-29 18:46:52 -07:00
2020-01-08 22:13:51 -08:00
tape ( "readme" , ( test ) => {
test . plan ( 115 ) ;
2018-04-27 22:05:34 -07:00
const tagToRules = { } ;
2015-04-14 00:01:57 -07:00
rules . forEach ( function forRule ( rule ) {
rule . tags . forEach ( function forTag ( tag ) {
2018-04-27 22:05:34 -07:00
const tagRules = tagToRules [ tag ] || [ ] ;
2018-01-12 23:21:06 -08:00
tagRules . push ( rule . names [ 0 ] ) ;
2015-04-14 00:01:57 -07:00
tagToRules [ tag ] = tagRules ;
} ) ;
} ) ;
2020-09-12 12:42:46 -07:00
fs . readFile ( "README.md" , "utf8" ,
2015-03-17 22:34:47 -07:00
function readFile ( err , contents ) {
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const rulesLeft = rules . slice ( ) ;
let seenRelated = false ;
let seenRules = false ;
let inRules = false ;
let seenTags = false ;
let inTags = false ;
2015-03-17 22:34:47 -07:00
md . parse ( contents , { } ) . forEach ( function forToken ( token ) {
2020-06-22 20:59:13 -07:00
if (
( token . type === "bullet_list_open" ) &&
( token . level === 0 )
) {
2016-01-14 22:15:44 -08:00
if ( ! seenRelated ) {
seenRelated = true ;
2020-10-02 13:33:05 -07:00
} else if ( ! seenRules ) {
2019-03-30 14:36:04 -07:00
seenRules = true ;
inRules = true ;
2020-10-02 13:33:05 -07:00
} else if ( ! seenTags ) {
2019-03-30 14:36:04 -07:00
seenTags = true ;
inTags = true ;
2015-03-17 22:34:47 -07:00
}
2020-06-22 20:59:13 -07:00
} else if (
( token . type === "bullet_list_close" ) &&
( token . level === 0 )
) {
2019-03-30 14:36:04 -07:00
inRules = false ;
inTags = false ;
2015-03-17 22:34:47 -07:00
} else if ( token . type === "inline" ) {
if ( inRules ) {
2018-04-27 22:05:34 -07:00
const rule = rulesLeft . shift ( ) ;
2015-04-14 00:01:57 -07:00
test . ok ( rule ,
"Missing rule implementation for " + token . content + "." ) ;
if ( rule ) {
2018-04-27 22:05:34 -07:00
const ruleName = rule . names [ 0 ] ;
const ruleAliases = rule . names . slice ( 1 ) ;
2019-07-08 13:10:08 -05:00
let expected = "**[" + ruleName + "](doc/Rules.md#" +
2018-01-12 23:21:06 -08:00
ruleName . toLowerCase ( ) + ")** *" +
2018-04-18 22:25:45 -07:00
ruleAliases . join ( "/" ) + "* - " + rule . description ;
2020-09-06 20:34:10 -07:00
if ( deprecatedRuleNames . has ( ruleName ) ) {
2019-07-08 13:10:08 -05:00
expected = "~~" + expected + "~~" ;
}
2015-04-14 00:01:57 -07:00
test . equal ( token . content , expected , "Rule mismatch." ) ;
}
2015-03-17 22:34:47 -07:00
} else if ( inTags ) {
2018-04-27 22:05:34 -07:00
const parts =
token . content . replace ( /\*\*/g , "" ) . split ( / - |, |,\n/ ) ;
const tag = parts . shift ( ) ;
2015-04-14 00:01:57 -07:00
test . deepEqual ( parts , tagToRules [ tag ] || [ ] ,
"Rule mismatch for tag " + tag + "." ) ;
delete tagToRules [ tag ] ;
2015-03-17 22:34:47 -07:00
}
}
} ) ;
2018-04-27 22:05:34 -07:00
const ruleLeft = rulesLeft . shift ( ) ;
2015-04-14 00:01:57 -07:00
test . ok ( ! ruleLeft ,
2018-01-12 23:21:06 -08:00
"Missing rule documentation for " +
( ruleLeft || "[NO RULE]" ) . toString ( ) + "." ) ;
2018-04-27 22:05:34 -07:00
const tagLeft = Object . keys ( tagToRules ) . shift ( ) ;
2015-04-14 00:01:57 -07:00
test . ok ( ! tagLeft , "Undocumented tag " + tagLeft + "." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-17 22:34:47 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-03-17 22:34:47 -07:00
2020-09-06 16:31:26 -07:00
tape ( "rules" , ( test ) => {
2020-01-08 22:13:51 -08:00
test . plan ( 336 ) ;
2020-09-12 12:42:46 -07:00
fs . readFile ( "doc/Rules.md" , "utf8" ,
2020-01-23 19:42:46 -08:00
( err , contents ) => {
2015-03-17 22:34:47 -07:00
test . ifError ( err ) ;
2018-04-27 22:05:34 -07:00
const rulesLeft = rules . slice ( ) ;
let inHeading = false ;
let rule = null ;
let ruleHasTags = true ;
let ruleHasAliases = true ;
let ruleUsesParams = null ;
const tagAliasParameterRe = /, |: | / ;
2020-01-23 19:42:46 -08:00
// eslint-disable-next-line func-style
const testTagsAliasesParams = ( r ) => {
2018-01-12 23:21:06 -08:00
r = r || "[NO RULE]" ;
2015-12-13 21:42:51 -08:00
test . ok ( ruleHasTags ,
2018-07-19 21:49:30 -07:00
"Missing tags for rule " + r . names + "." ) ;
2016-01-12 21:29:17 -08:00
test . ok ( ruleHasAliases ,
2018-07-19 21:49:30 -07:00
"Missing aliases for rule " + r . names + "." ) ;
2015-12-13 21:42:51 -08:00
test . ok ( ! ruleUsesParams ,
2018-07-19 21:49:30 -07:00
"Missing parameters for rule " + r . names + "." ) ;
2020-01-23 19:42:46 -08:00
} ;
2015-03-17 22:34:47 -07:00
md . parse ( contents , { } ) . forEach ( function forToken ( token ) {
2015-03-18 23:14:44 -07:00
if ( ( token . type === "heading_open" ) && ( token . tag === "h2" ) ) {
2015-03-17 22:34:47 -07:00
inHeading = true ;
} else if ( token . type === "heading_close" ) {
inHeading = false ;
} else if ( token . type === "inline" ) {
if ( inHeading ) {
2018-01-12 23:21:06 -08:00
testTagsAliasesParams ( rule ) ;
2015-03-17 22:34:47 -07:00
rule = rulesLeft . shift ( ) ;
2019-03-30 14:36:04 -07:00
ruleHasTags = false ;
ruleHasAliases = false ;
2015-04-14 00:01:57 -07:00
test . ok ( rule ,
"Missing rule implementation for " + token . content + "." ) ;
2019-07-08 13:10:08 -05:00
const ruleName = rule . names [ 0 ] ;
let headingContent = ruleName + " - " + rule . description ;
2020-09-06 20:34:10 -07:00
if ( deprecatedRuleNames . has ( ruleName ) ) {
2019-07-08 13:10:08 -05:00
headingContent = "~~" + headingContent + "~~" ;
}
2018-02-05 21:26:07 -08:00
test . equal ( token . content ,
2019-07-08 13:10:08 -05:00
headingContent ,
2018-02-05 21:26:07 -08:00
"Rule mismatch." ) ;
ruleUsesParams = rule . function . toString ( )
. match ( /params\.config\.[_a-z]*/gi ) ;
if ( ruleUsesParams ) {
ruleUsesParams = ruleUsesParams . map ( function forUse ( use ) {
return use . split ( "." ) . pop ( ) ;
} ) ;
2019-12-09 22:05:57 -08:00
ruleUsesParams . sort ( ) ;
2015-04-14 00:01:57 -07:00
}
2020-09-06 20:34:10 -07:00
} else if ( token . content . startsWith ( "Tags: " ) && rule ) {
2016-01-12 21:29:17 -08:00
test . deepEqual ( token . content . split ( tagAliasParameterRe ) . slice ( 1 ) ,
2018-07-19 21:49:30 -07:00
rule . tags , "Tag mismatch for rule " + rule . names + "." ) ;
2015-12-13 21:42:51 -08:00
ruleHasTags = true ;
2020-09-06 20:34:10 -07:00
} else if ( token . content . startsWith ( "Aliases: " ) && rule ) {
2016-01-12 21:29:17 -08:00
test . deepEqual ( token . content . split ( tagAliasParameterRe ) . slice ( 1 ) ,
2018-01-12 23:21:06 -08:00
rule . names . slice ( 1 ) ,
2018-07-19 21:49:30 -07:00
"Alias mismatch for rule " + rule . names + "." ) ;
2016-01-12 21:29:17 -08:00
ruleHasAliases = true ;
2020-09-06 20:34:10 -07:00
} else if ( token . content . startsWith ( "Parameters: " ) && rule ) {
2018-04-27 22:05:34 -07:00
let inDetails = false ;
const parameters = token . content . split ( tagAliasParameterRe )
2015-12-13 21:42:51 -08:00
. slice ( 1 )
. filter ( function forPart ( part ) {
inDetails = inDetails || ( part [ 0 ] === "(" ) ;
return ! inDetails ;
} ) ;
2019-12-09 22:05:57 -08:00
parameters . sort ( ) ;
2015-12-13 21:42:51 -08:00
test . deepEqual ( parameters , ruleUsesParams ,
2018-07-19 21:49:30 -07:00
"Missing parameter for rule " + rule . names ) ;
2015-12-13 21:42:51 -08:00
ruleUsesParams = null ;
2015-03-17 22:34:47 -07:00
}
}
} ) ;
2018-04-27 22:05:34 -07:00
const ruleLeft = rulesLeft . shift ( ) ;
2015-04-14 00:01:57 -07:00
test . ok ( ! ruleLeft ,
2018-01-12 23:21:06 -08:00
"Missing rule documentation for " +
2018-07-19 21:49:30 -07:00
( ruleLeft || { "names" : "[NO RULE]" } ) . names + "." ) ;
2016-06-27 22:19:02 -07:00
if ( rule ) {
2018-01-12 23:21:06 -08:00
testTagsAliasesParams ( rule ) ;
2016-06-27 22:19:02 -07:00
}
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2015-03-17 22:34:47 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2015-05-07 17:42:13 -07:00
2020-09-15 21:48:00 -07:00
tape ( "validateJsonUsingConfigSchemaStrict" , ( test ) => {
2018-04-27 22:05:34 -07:00
const jsonFileRe = /\.json$/i ;
const resultsFileRe = /\.results\.json$/i ;
2019-10-30 20:37:06 -07:00
const jsConfigFileRe = /^jsconfig\.json$/i ;
2020-01-25 18:40:39 -08:00
const wrongTypesFileRe = /wrong-types-in-config-file.json$/i ;
2018-04-27 22:05:34 -07:00
const testDirectory = _ _dirname ;
const testFiles = fs . readdirSync ( testDirectory ) ;
2016-10-05 22:21:54 -07:00
testFiles . filter ( function filterFile ( file ) {
2019-10-30 20:37:06 -07:00
return jsonFileRe . test ( file ) &&
! resultsFileRe . test ( file ) &&
2020-01-25 18:40:39 -08:00
! jsConfigFileRe . test ( file ) &&
! wrongTypesFileRe . test ( file ) ;
2016-10-05 22:21:54 -07:00
} ) . forEach ( function forFile ( file ) {
2019-10-30 20:37:06 -07:00
const data = fs . readFileSync (
path . join ( testDirectory , file ) ,
2020-09-12 12:42:46 -07:00
"utf8"
2019-10-30 20:37:06 -07:00
) ;
2016-10-05 22:21:54 -07:00
test . ok (
2020-09-15 21:48:00 -07:00
// @ts-ignore
tv4 . validate ( JSON . parse ( data ) , configSchemaStrict ) ,
2016-10-05 22:21:54 -07:00
file + "\n" + JSON . stringify ( tv4 . error , null , 2 ) ) ;
} ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
} ) ;
2016-10-05 22:21:54 -07:00
2020-09-15 21:48:00 -07:00
tape ( "validateConfigSchemaAllowsUnknownProperties" , ( test ) => {
test . plan ( 4 ) ;
const testCases = [
{
"property" : true
} ,
{
"property" : {
"object" : 1
}
}
] ;
testCases . forEach ( ( testCase ) => {
test . ok (
// @ts-ignore
tv4 . validate ( testCase , configSchema ) ,
"Unknown property blocked by default: " + JSON . stringify ( testCase ) ) ;
test . notok (
// @ts-ignore
tv4 . validate ( testCase , configSchemaStrict ) ,
"Unknown property allowed when strict: " + JSON . stringify ( testCase ) ) ;
} ) ;
test . end ( ) ;
} ) ;
2020-09-12 12:42:46 -07:00
tape ( "configSingle" , ( test ) => {
test . plan ( 2 ) ;
markdownlint . readConfig ( "./test/config/config-child.json" ,
function callback ( err , actual ) {
test . ifError ( err ) ;
const expected = require ( "./config/config-child.json" ) ;
test . deepEqual ( actual , expected , "Config object not correct." ) ;
test . end ( ) ;
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2017-07-16 23:08:47 -07:00
2020-09-12 12:42:46 -07:00
tape ( "configAbsolute" , ( test ) => {
test . plan ( 2 ) ;
markdownlint . readConfig ( path . join ( _ _dirname , "config" , "config-child.json" ) ,
function callback ( err , actual ) {
test . ifError ( err ) ;
const expected = require ( "./config/config-child.json" ) ;
test . deepEqual ( actual , expected , "Config object not correct." ) ;
test . end ( ) ;
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2017-07-16 23:08:47 -07:00
2020-09-12 12:42:46 -07:00
tape ( "configMultiple" , ( test ) => {
test . plan ( 2 ) ;
markdownlint . readConfig ( "./test/config/config-grandparent.json" ,
function callback ( err , actual ) {
test . ifError ( err ) ;
const expected = {
... require ( "./config/config-child.json" ) ,
... require ( "./config/config-parent.json" ) ,
... require ( "./config/config-grandparent.json" )
} ;
delete expected . extends ;
test . deepEqual ( actual , expected , "Config object not correct." ) ;
test . end ( ) ;
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2017-05-19 22:36:46 -07:00
2020-10-22 04:40:54 +01:00
tape ( "configMultipleWithRequireResolve" , ( test ) => {
test . plan ( 2 ) ;
markdownlint . readConfig ( "./test/config/config-packageparent.json" ,
function callback ( err , actual ) {
test . ifError ( err ) ;
const expected = {
... require ( "./node_modules/pseudo-package/config-frompackage.json" ) ,
... require ( "./config/config-packageparent.json" )
} ;
delete expected . extends ;
test . deepEqual ( actual , expected , "Config object not correct." ) ;
test . end ( ) ;
} ) ;
} ) ;
2020-01-08 22:13:51 -08:00
tape ( "configBadFile" , ( test ) => {
test . plan ( 4 ) ;
2017-05-19 22:36:46 -07:00
markdownlint . readConfig ( "./test/config/config-badfile.json" ,
function callback ( err , result ) {
test . ok ( err , "Did not get an error for bad file." ) ;
test . ok ( err instanceof Error , "Error not instance of Error." ) ;
2020-01-11 20:48:00 -08:00
// @ts-ignore
2017-05-19 22:36:46 -07:00
test . equal ( err . code , "ENOENT" , "Error code for bad file not ENOENT." ) ;
test . ok ( ! result , "Got result for bad file." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2017-05-19 22:36:46 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2017-05-19 22:36:46 -07:00
2020-01-08 22:13:51 -08:00
tape ( "configBadChildFile" , ( test ) => {
test . plan ( 4 ) ;
2017-05-19 22:36:46 -07:00
markdownlint . readConfig ( "./test/config/config-badchildfile.json" ,
function callback ( err , result ) {
test . ok ( err , "Did not get an error for bad child file." ) ;
test . ok ( err instanceof Error , "Error not instance of Error." ) ;
2020-01-11 20:48:00 -08:00
// @ts-ignore
2017-05-19 22:36:46 -07:00
test . equal ( err . code , "ENOENT" ,
"Error code for bad child file not ENOENT." ) ;
test . ok ( ! result , "Got result for bad child file." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2017-05-19 22:36:46 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2017-05-19 22:36:46 -07:00
2020-10-22 04:40:54 +01:00
tape ( "configBadChildPackage" , ( test ) => {
test . plan ( 4 ) ;
markdownlint . readConfig ( "./test/config/config-badchildpackage.json" ,
function callback ( err , result ) {
2020-10-21 20:53:30 -07:00
test . ok ( err , "Did not get an error for bad child package." ) ;
2020-10-22 04:40:54 +01:00
test . ok ( err instanceof Error , "Error not instance of Error." ) ;
// @ts-ignore
test . equal ( err . code , "ENOENT" ,
2020-10-21 20:53:30 -07:00
"Error code for bad child package not ENOENT." ) ;
test . ok ( ! result , "Got result for bad child package." ) ;
2020-10-22 04:40:54 +01:00
test . end ( ) ;
} ) ;
} ) ;
2020-01-08 22:13:51 -08:00
tape ( "configBadJson" , ( test ) => {
test . plan ( 3 ) ;
2017-05-19 22:36:46 -07:00
markdownlint . readConfig ( "./test/config/config-badjson.json" ,
function callback ( err , result ) {
test . ok ( err , "Did not get an error for bad JSON." ) ;
test . ok ( err instanceof Error , "Error not instance of Error." ) ;
test . ok ( ! result , "Got result for bad JSON." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2017-05-19 22:36:46 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2017-05-19 22:36:46 -07:00
2020-01-08 22:13:51 -08:00
tape ( "configBadChildJson" , ( test ) => {
test . plan ( 3 ) ;
2017-05-19 22:36:46 -07:00
markdownlint . readConfig ( "./test/config/config-badchildjson.json" ,
function callback ( err , result ) {
test . ok ( err , "Did not get an error for bad child JSON." ) ;
test . ok ( err instanceof Error , "Error not instance of Error." ) ;
test . ok ( ! result , "Got result for bad child JSON." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2017-05-19 22:36:46 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2017-05-19 22:36:46 -07:00
2020-01-08 22:13:51 -08:00
tape ( "configSingleYaml" , ( test ) => {
test . plan ( 2 ) ;
2018-05-23 22:24:40 -07:00
markdownlint . readConfig (
"./test/config/config-child.yaml" ,
2020-09-12 12:42:46 -07:00
// @ts-ignore
2018-05-23 22:24:40 -07:00
[ require ( "js-yaml" ) . safeLoad ] ,
function callback ( err , actual ) {
test . ifError ( err ) ;
const expected = require ( "./config/config-child.json" ) ;
test . deepEqual ( actual , expected , "Config object not correct." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2018-05-23 22:24:40 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2018-05-23 22:24:40 -07:00
2020-01-08 22:13:51 -08:00
tape ( "configMultipleYaml" , ( test ) => {
test . plan ( 2 ) ;
2018-05-23 22:24:40 -07:00
markdownlint . readConfig (
"./test/config/config-grandparent.yaml" ,
2020-09-12 12:42:46 -07:00
// @ts-ignore
2018-05-23 22:24:40 -07:00
[ require ( "js-yaml" ) . safeLoad ] ,
function callback ( err , actual ) {
test . ifError ( err ) ;
2019-05-05 22:27:01 -07:00
const expected = {
... require ( "./config/config-child.json" ) ,
... require ( "./config/config-parent.json" ) ,
... require ( "./config/config-grandparent.json" )
} ;
2018-05-23 22:24:40 -07:00
delete expected . extends ;
test . deepEqual ( actual , expected , "Config object not correct." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2018-05-23 22:24:40 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2018-05-23 22:24:40 -07:00
2020-01-08 22:13:51 -08:00
tape ( "configMultipleHybrid" , ( test ) => {
test . plan ( 2 ) ;
2018-05-23 22:24:40 -07:00
markdownlint . readConfig (
"./test/config/config-grandparent-hybrid.yaml" ,
2020-09-12 12:42:46 -07:00
// @ts-ignore
2018-05-23 22:24:40 -07:00
[ JSON . parse , require ( "toml" ) . parse , require ( "js-yaml" ) . safeLoad ] ,
function callback ( err , actual ) {
test . ifError ( err ) ;
2019-05-05 22:27:01 -07:00
const expected = {
... require ( "./config/config-child.json" ) ,
... require ( "./config/config-parent.json" ) ,
... require ( "./config/config-grandparent.json" )
} ;
2018-05-23 22:24:40 -07:00
delete expected . extends ;
2020-09-05 17:24:52 -07:00
test . deepLooseEqual ( actual , expected , "Config object not correct." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2018-05-23 22:24:40 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2018-05-23 22:24:40 -07:00
2020-01-08 22:13:51 -08:00
tape ( "configBadHybrid" , ( test ) => {
test . plan ( 4 ) ;
2018-05-23 22:24:40 -07:00
markdownlint . readConfig (
"./test/config/config-badcontent.txt" ,
2020-09-12 12:42:46 -07:00
// @ts-ignore
2018-05-23 22:24:40 -07:00
[ JSON . parse , require ( "toml" ) . parse , require ( "js-yaml" ) . safeLoad ] ,
function callback ( err , result ) {
test . ok ( err , "Did not get an error for bad child JSON." ) ;
test . ok ( err instanceof Error , "Error not instance of Error." ) ;
test . ok ( err . message . match (
// eslint-disable-next-line max-len
/^Unable to parse '[^']*'; Unexpected token \S+ in JSON at position \d+; Expected [^;]+ or end of input but "\S+" found.; end of the stream or a document separator is expected at line \d+, column \d+:[^;]*$/
) , "Error message unexpected." ) ;
test . ok ( ! result , "Got result for bad child JSON." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
2018-05-23 22:24:40 -07:00
} ) ;
2020-01-08 22:13:51 -08:00
} ) ;
2018-05-23 22:24:40 -07:00
2020-01-08 22:13:51 -08:00
tape ( "configSingleSync" , ( test ) => {
test . plan ( 1 ) ;
2018-05-20 21:37:05 -07:00
const actual = markdownlint . readConfigSync ( "./test/config/config-child.json" ) ;
const expected = require ( "./config/config-child.json" ) ;
2017-05-19 22:36:46 -07:00
test . deepEqual ( actual , expected , "Config object not correct." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
} ) ;
2017-05-19 22:36:46 -07:00
2020-01-08 22:13:51 -08:00
tape ( "configAbsoluteSync" , ( test ) => {
test . plan ( 1 ) ;
2018-04-27 22:05:34 -07:00
const actual = markdownlint . readConfigSync (
2018-05-20 21:37:05 -07:00
path . join ( _ _dirname , "config" , "config-child.json" ) ) ;
const expected = require ( "./config/config-child.json" ) ;
2017-05-19 22:36:46 -07:00
test . deepEqual ( actual , expected , "Config object not correct." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
} ) ;
2017-05-19 22:36:46 -07:00
2020-01-08 22:13:51 -08:00
tape ( "configMultipleSync" , ( test ) => {
test . plan ( 1 ) ;
2018-05-20 21:37:05 -07:00
const actual =
markdownlint . readConfigSync ( "./test/config/config-grandparent.json" ) ;
2019-05-05 22:27:01 -07:00
const expected = {
... require ( "./config/config-child.json" ) ,
... require ( "./config/config-parent.json" ) ,
... require ( "./config/config-grandparent.json" )
} ;
2017-05-19 22:36:46 -07:00
delete expected . extends ;
test . deepEqual ( actual , expected , "Config object not correct." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
} ) ;
tape ( "configBadFileSync" , ( test ) => {
test . plan ( 1 ) ;
test . throws (
function badFileCall ( ) {
markdownlint . readConfigSync ( "./test/config/config-badfile.json" ) ;
} ,
/ENOENT/ ,
"Did not get correct exception for bad file."
) ;
test . end ( ) ;
} ) ;
tape ( "configBadChildFileSync" , ( test ) => {
test . plan ( 1 ) ;
test . throws (
function badChildFileCall ( ) {
markdownlint . readConfigSync ( "./test/config/config-badchildfile.json" ) ;
} ,
/ENOENT/ ,
"Did not get correct exception for bad child file."
) ;
test . end ( ) ;
} ) ;
tape ( "configBadJsonSync" , ( test ) => {
test . plan ( 1 ) ;
test . throws (
function badJsonCall ( ) {
markdownlint . readConfigSync ( "./test/config/config-badjson.json" ) ;
} ,
/Unable to parse '[^']*'; Unexpected token \S+ in JSON at position \d+/ ,
"Did not get correct exception for bad JSON."
) ;
test . end ( ) ;
} ) ;
tape ( "configBadChildJsonSync" , ( test ) => {
test . plan ( 1 ) ;
test . throws (
function badChildJsonCall ( ) {
markdownlint . readConfigSync ( "./test/config/config-badchildjson.json" ) ;
} ,
/Unable to parse '[^']*'; Unexpected token \S+ in JSON at position \d+/ ,
"Did not get correct exception for bad child JSON."
) ;
test . end ( ) ;
} ) ;
tape ( "configSingleYamlSync" , ( test ) => {
test . plan ( 1 ) ;
2018-05-23 22:24:40 -07:00
const actual = markdownlint . readConfigSync (
2020-09-12 12:42:46 -07:00
// @ts-ignore
2018-05-23 22:24:40 -07:00
"./test/config/config-child.yaml" , [ require ( "js-yaml" ) . safeLoad ] ) ;
const expected = require ( "./config/config-child.json" ) ;
test . deepEqual ( actual , expected , "Config object not correct." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
} ) ;
2018-05-23 22:24:40 -07:00
2020-01-08 22:13:51 -08:00
tape ( "configMultipleYamlSync" , ( test ) => {
test . plan ( 1 ) ;
2018-05-23 22:24:40 -07:00
const actual = markdownlint . readConfigSync (
2020-09-12 12:42:46 -07:00
// @ts-ignore
2018-05-23 22:24:40 -07:00
"./test/config/config-grandparent.yaml" , [ require ( "js-yaml" ) . safeLoad ] ) ;
2019-05-05 22:27:01 -07:00
const expected = {
... require ( "./config/config-child.json" ) ,
... require ( "./config/config-parent.json" ) ,
... require ( "./config/config-grandparent.json" )
} ;
2018-05-23 22:24:40 -07:00
delete expected . extends ;
test . deepEqual ( actual , expected , "Config object not correct." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
} ) ;
2018-05-23 22:24:40 -07:00
2020-01-08 22:13:51 -08:00
tape ( "configMultipleHybridSync" , ( test ) => {
test . plan ( 1 ) ;
2018-05-23 22:24:40 -07:00
const actual = markdownlint . readConfigSync (
"./test/config/config-grandparent-hybrid.yaml" ,
2020-09-12 12:42:46 -07:00
// @ts-ignore
2018-05-23 22:24:40 -07:00
[ JSON . parse , require ( "toml" ) . parse , require ( "js-yaml" ) . safeLoad ] ) ;
2019-05-05 22:27:01 -07:00
const expected = {
... require ( "./config/config-child.json" ) ,
... require ( "./config/config-parent.json" ) ,
... require ( "./config/config-grandparent.json" )
} ;
2018-05-23 22:24:40 -07:00
delete expected . extends ;
2020-09-05 17:24:52 -07:00
test . deepLooseEqual ( actual , expected , "Config object not correct." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
} ) ;
tape ( "configBadHybridSync" , ( test ) => {
test . plan ( 1 ) ;
test . throws (
function badHybridCall ( ) {
markdownlint . readConfigSync (
"./test/config/config-badcontent.txt" ,
2020-09-12 12:42:46 -07:00
// @ts-ignore
2020-01-08 22:13:51 -08:00
[ JSON . parse , require ( "toml" ) . parse , require ( "js-yaml" ) . safeLoad ] ) ;
} ,
// eslint-disable-next-line max-len
/Unable to parse '[^']*'; Unexpected token \S+ in JSON at position \d+; Expected [^;]+ or end of input but "\S+" found.; end of the stream or a document separator is expected at line \d+, column \d+:[^;]*/ ,
"Did not get correct exception for bad content."
) ;
test . end ( ) ;
} ) ;
2020-09-13 12:58:09 -07:00
tape ( "configSinglePromise" , ( test ) => {
test . plan ( 1 ) ;
markdownlint . promises . readConfig ( "./test/config/config-child.json" )
. then ( ( actual ) => {
const expected = require ( "./config/config-child.json" ) ;
test . deepEqual ( actual , expected , "Config object not correct." ) ;
test . end ( ) ;
} ) ;
} ) ;
tape ( "configBadFilePromise" , ( test ) => {
test . plan ( 2 ) ;
markdownlint . promises . readConfig ( "./test/config/config-badfile.json" )
. then (
null ,
( error ) => {
test . ok ( error , "Did not get an error for bad JSON." ) ;
test . ok ( error instanceof Error , "Error not instance of Error." ) ;
test . end ( ) ;
}
) ;
} ) ;
2020-01-08 22:13:51 -08:00
tape ( "allBuiltInRulesHaveValidUrl" , ( test ) => {
test . plan ( 132 ) ;
rules . forEach ( function forRule ( rule ) {
test . ok ( rule . information ) ;
test . ok ( Object . getPrototypeOf ( rule . information ) === URL . prototype ) ;
const name = rule . names [ 0 ] . toLowerCase ( ) ;
test . equal (
rule . information . href ,
` ${ homepage } /blob/v ${ version } /doc/Rules.md# ${ name } `
) ;
} ) ;
test . end ( ) ;
} ) ;
tape ( "someCustomRulesHaveValidUrl" , ( test ) => {
test . plan ( 7 ) ;
customRules . all . forEach ( function forRule ( rule ) {
test . ok ( ! rule . information ||
( Object . getPrototypeOf ( rule . information ) === URL . prototype ) ) ;
if ( rule === customRules . anyBlockquote ) {
2019-01-15 21:56:38 -08:00
test . equal (
rule . information . href ,
2020-08-11 22:52:29 -07:00
` ${ homepage } /blob/main/test/rules/any-blockquote.js `
2019-01-15 21:56:38 -08:00
) ;
2020-01-08 22:13:51 -08:00
} else if ( rule === customRules . lettersEX ) {
test . equal (
rule . information . href ,
2020-08-11 22:52:29 -07:00
` ${ homepage } /blob/main/test/rules/letters-E-X.js `
2020-01-08 22:13:51 -08:00
) ;
}
} ) ;
test . end ( ) ;
} ) ;
2019-01-15 21:56:38 -08:00
2020-01-08 22:13:51 -08:00
tape ( "markdownItPluginsSingle" , ( test ) => {
test . plan ( 2 ) ;
markdownlint ( {
"strings" : {
"string" : "# Heading\n\nText [ link ](https://example.com)\n"
} ,
"markdownItPlugins" : [
[
pluginInline ,
"trim_text_plugin" ,
"text" ,
function iterator ( tokens , index ) {
tokens [ index ] . content = tokens [ index ] . content . trim ( ) ;
}
2019-01-19 12:52:13 -08:00
]
2020-01-08 22:13:51 -08:00
]
} , function callback ( err , actual ) {
test . ifError ( err ) ;
const expected = { "string" : [ ] } ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actual , expected , "Unexpected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
} ) ;
} ) ;
2019-01-19 12:52:13 -08:00
2020-01-08 22:13:51 -08:00
tape ( "markdownItPluginsMultiple" , ( test ) => {
test . plan ( 4 ) ;
markdownlint ( {
"strings" : {
"string" : "# Heading\n\nText H~2~0 text 29^th^ text\n"
} ,
"markdownItPlugins" : [
[ pluginSub ] ,
[ pluginSup ] ,
[ pluginInline , "check_sub_plugin" , "sub_open" , test . ok ] ,
[ pluginInline , "check_sup_plugin" , "sup_open" , test . ok ]
]
} , function callback ( err , actual ) {
test . ifError ( err ) ;
const expected = { "string" : [ ] } ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actual , expected , "Unexpected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
} ) ;
} ) ;
tape ( "markdownItPluginsMathjax" , ( test ) => {
test . plan ( 2 ) ;
markdownlint ( {
"strings" : {
"string" :
"# Heading\n" +
"\n" +
"$1 *2* 3$\n" +
"\n" +
"$$1 *2* 3$$\n" +
"\n" +
"$$1\n" +
"+ 2\n" +
"+ 3$$\n"
} ,
2020-10-16 20:59:04 -07:00
"markdownItPlugins" : [ [ pluginTexMath , pluginTexMathOptions ] ]
2020-01-08 22:13:51 -08:00
} , function callback ( err , actual ) {
test . ifError ( err ) ;
const expected = { "string" : [ ] } ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actual , expected , "Unexpected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
} ) ;
} ) ;
2019-02-13 19:52:34 -08:00
2020-01-08 22:13:51 -08:00
tape ( "markdownItPluginsMathjaxIssue166" , ( test ) => {
test . plan ( 2 ) ;
markdownlint ( {
"strings" : {
"string" :
2019-02-13 19:52:34 -08:00
` ## Heading
$$
1
$$$$
2
2019-04-05 12:36:12 +02:00
$$ \ n `
2020-01-08 22:13:51 -08:00
} ,
2020-10-16 20:59:04 -07:00
"markdownItPlugins" : [ [ pluginTexMath , pluginTexMathOptions ] ] ,
2020-01-08 22:13:51 -08:00
"resultVersion" : 0
} , function callback ( err , actual ) {
test . ifError ( err ) ;
const expected = {
"string" : {
"MD041" : [ 1 ]
}
} ;
2020-09-07 20:05:36 -07:00
test . deepEqual ( actual , expected , "Unexpected issues." ) ;
2020-01-08 22:13:51 -08:00
test . end ( ) ;
} ) ;
} ) ;
2020-10-17 14:17:35 -07:00
tape ( "getVersion" , ( test ) => {
test . plan ( 1 ) ;
const actual = markdownlint . getVersion ( ) ;
const expected = packageJson . version ;
test . equal ( actual , expected , "Version string not correct." ) ;
test . end ( ) ;
} ) ;