Skip to content

Commit 31c9789

Browse files
committed
testing(check-examples): Add tests for indent (with asterisks)
1 parent a5e1b0e commit 31c9789

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,16 @@ function quux () {
10011001
}
10021002
// Options: [{"baseConfig":{"rules":{"semi":["warn","always"]}},"eslintrcForExamples":false,"exampleCodeRegex":"/\\/\\/ begin[\\s\\S]*?// end/g","noDefaultExampleRules":true}]
10031003
// Message: @example warning (semi): Missing semicolon.
1004+
1005+
/**
1006+
* @example
1007+
* quux();
1008+
*/
1009+
function quux () {
1010+
1011+
}
1012+
// Options: [{"baseConfig":{"rules":{"indent":["error"]}},"eslintrcForExamples":false,"noDefaultExampleRules":false}]
1013+
// Message: @example error (indent): Expected indentation of 0 spaces but found 2.
10041014
````
10051015

10061016
The following patterns are not considered problems:
@@ -1105,6 +1115,27 @@ function quux () {
11051115

11061116
}
11071117
// Options: [{"baseConfig":{"parser":"@typescript-eslint/parser","parserOptions":{"ecmaVersion":6},"rules":{"semi":["error","always"]}},"eslintrcForExamples":false}]
1118+
1119+
/**
1120+
* @example const ident = 5;
1121+
* quux2();
1122+
* bar();
1123+
*/
1124+
function quux2 () {
1125+
1126+
}
1127+
// Options: [{"paddedIndent":2}]
1128+
1129+
/**
1130+
* @example
1131+
* function quux() {
1132+
* bar();
1133+
* }
1134+
*/
1135+
function quux () {
1136+
1137+
}
1138+
// Options: [{"baseConfig":{"rules":{"indent":["error"]}},"eslintrcForExamples":false,"noDefaultExampleRules":false}]
11081139
````
11091140

11101141

test/rules/assertions/checkExamples.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,32 @@ export default {
639639
noDefaultExampleRules: true,
640640
}],
641641
},
642+
{
643+
code: `
644+
/**
645+
* @example
646+
* quux();
647+
*/
648+
function quux () {
649+
650+
}
651+
`,
652+
errors: [
653+
{
654+
line: 4,
655+
message: '@example error (indent): Expected indentation of 0 spaces but found 2.',
656+
},
657+
],
658+
options: [{
659+
baseConfig: {
660+
rules: {
661+
indent: ['error'],
662+
},
663+
},
664+
eslintrcForExamples: false,
665+
noDefaultExampleRules: false,
666+
}],
667+
},
642668
],
643669
valid: [
644670
{
@@ -868,5 +894,27 @@ export default {
868894
},
869895
],
870896
},
897+
{
898+
code: `
899+
/**
900+
* @example
901+
* function quux() {
902+
* bar();
903+
* }
904+
*/
905+
function quux () {
906+
907+
}
908+
`,
909+
options: [{
910+
baseConfig: {
911+
rules: {
912+
indent: ['error'],
913+
},
914+
},
915+
eslintrcForExamples: false,
916+
noDefaultExampleRules: false,
917+
}],
918+
},
871919
],
872920
};

0 commit comments

Comments
 (0)