Skip to content

Commit d5b94ec

Browse files
authored
Merge branch 'main' into ci/perms
2 parents 338ffce + ed62262 commit d5b94ec

12 files changed

+115
-3
lines changed

.README/rules/text-escaping.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Markdown and you therefore do not wish for it to be accidentally interpreted
1010
as such by the likes of Visual Studio Code or if you wish to view it escaped
1111
within it or your documentation.
1212

13+
`@example` tag content will not be checked.
14+
1315
## Fixer
1416

1517
(TODO)

docs/rules/empty-tags.md

+5
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,10 @@ function quux () {
216216
* @returns {string[]} The array of nodes.
217217
*/
218218
function quux () {}
219+
220+
/** Application boot function.
221+
@async
222+
@private **/
223+
function quux () {}
219224
````
220225

docs/rules/no-undefined-types.md

+9
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,15 @@ function quux(foo) {
807807

808808
quux(0);
809809

810+
function quux() {
811+
const foo = 1;
812+
/** {@link foo} */
813+
const bar = foo;
814+
console.log(bar);
815+
}
816+
817+
quux();
818+
810819
/**
811820
* @import BadImportIgnoredByThisRule
812821
*/

docs/rules/text-escaping.md

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Markdown and you therefore do not wish for it to be accidentally interpreted
1919
as such by the likes of Visual Studio Code or if you wish to view it escaped
2020
within it or your documentation.
2121

22+
`@example` tag content will not be checked.
23+
2224
<a name="user-content-text-escaping-fixer"></a>
2325
<a name="text-escaping-fixer"></a>
2426
## Fixer
@@ -175,5 +177,21 @@ The following patterns are not considered problems:
175177
* to escape
176178
*/
177179
// "jsdoc/text-escaping": ["error"|"warn", {"escapeHTML":true}]
180+
181+
/**
182+
* @example
183+
* ```
184+
* Some things to escape: <a> and &gt; and &#xabc; and `test`
185+
* ```
186+
*/
187+
// "jsdoc/text-escaping": ["error"|"warn", {"escapeHTML":true}]
188+
189+
/**
190+
* @example
191+
* ```
192+
* Some things to escape: <a> and &gt; and &#xabc; and `test`
193+
* ```
194+
*/
195+
// "jsdoc/text-escaping": ["error"|"warn", {"escapeMarkdown":true}]
178196
````
179197

src/bin/generateDocs.js

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ const getDocPaths = () => {
202202
// Will get path separately below
203203
return null;
204204
}
205+
if (docFile === '.DS_Store') {
206+
return null;
207+
}
205208

206209
const innerBasePath = path.join(basePath, docFile);
207210
const writeInnerBasePath = path.join(writeBasePath, docFile);

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import validTypes from './rules/validTypes.js';
5959
import { getJsdocProcessorPlugin } from './getJsdocProcessorPlugin.js';
6060

6161
/**
62-
* @typedef {"recommended" | "stylistic" | "contents" | "logical"} ConfigGroups
62+
* @typedef {"recommended" | "stylistic" | "contents" | "logical" | "requirements"} ConfigGroups
6363
* @typedef {"" | "-typescript" | "-typescript-flavor"} ConfigVariants
6464
* @typedef {"" | "-error"} ErrorLevelVariants
6565
* @type {import('eslint').ESLint.Plugin & {

src/rules/emptyTags.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ export default iterateJsdoc(({
4242
settings.mode !== 'closure' && emptyIfNotClosure.has(tagName);
4343
});
4444

45-
for (const tag of emptyTags) {
45+
for (const [key, tag] of emptyTags.entries()) {
4646
const content = tag.name || tag.description || tag.type;
47-
if (content.trim()) {
47+
if (content.trim() && (
48+
// Allow for JSDoc-block final asterisks
49+
key !== emptyTags.length - 1 || !(/^\s*\*+$/u).test(content)
50+
)) {
4851
const fix = () => {
4952
// By time of call in fixer, `tag` will have `line` added
5053
utils.setTag(

src/rules/noUndefinedTypes.js

+16
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,21 @@ export default iterateJsdoc(({
222222
// Program scope inside
223223
const cjsOrESMScope = globalScope.childScopes[0]?.block?.type === 'Program';
224224

225+
/**
226+
* @param {import("eslint").Scope.Scope | null} scope
227+
* @returns {Set<string>}
228+
*/
229+
const getValidRuntimeIdentifiers = (scope) => {
230+
const result = new Set()
231+
while (scope) {
232+
for (const {name} of scope.variables) {
233+
result.add(name)
234+
}
235+
scope = scope.upper
236+
}
237+
return result
238+
};
239+
225240
const allDefinedTypes = new Set(globalScope.variables.map(({
226241
name,
227242
}) => {
@@ -247,6 +262,7 @@ export default iterateJsdoc(({
247262
.concat(importTags)
248263
.concat(definedTypes)
249264
.concat(/** @type {string[]} */ (definedPreferredTypes))
265+
.concat(...getValidRuntimeIdentifiers(node && sourceCode.getScope(node)))
250266
.concat(
251267
settings.mode === 'jsdoc' ?
252268
[] :

src/rules/textEscaping.js

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export default iterateJsdoc(({
7373
}
7474

7575
for (const tag of jsdoc.tags) {
76+
if (tag.tag === 'example') {
77+
continue;
78+
}
7679
if (/** @type {string[]} */ (
7780
utils.getTagDescription(tag, true)
7881
).some((desc) => {
@@ -100,6 +103,9 @@ export default iterateJsdoc(({
100103
}
101104

102105
for (const tag of jsdoc.tags) {
106+
if (tag.tag === 'example') {
107+
continue;
108+
}
103109
if (/** @type {string[]} */ (
104110
utils.getTagDescription(tag, true)
105111
).some((desc) => {

test/rules/assertions/emptyTags.js

+8
Original file line numberDiff line numberDiff line change
@@ -308,5 +308,13 @@ export default /** @type {import('../index.js').TestCases} */ ({
308308
function quux () {}
309309
`,
310310
},
311+
{
312+
code: `
313+
/** Application boot function.
314+
@async
315+
@private **/
316+
function quux () {}
317+
`,
318+
},
311319
],
312320
});

test/rules/assertions/noUndefinedTypes.js

+12
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,18 @@ export default /** @type {import('../index.js').TestCases} */ ({
14821482
'no-unused-vars': 'error',
14831483
},
14841484
},
1485+
{
1486+
code: `
1487+
function quux() {
1488+
const foo = 1;
1489+
/** {@link foo} */
1490+
const bar = foo;
1491+
console.log(bar);
1492+
}
1493+
1494+
quux();
1495+
`,
1496+
},
14851497
{
14861498
code: `
14871499
/**

test/rules/assertions/textEscaping.js

+30
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,35 @@ export default /** @type {import('../index.js').TestCases} */ ({
316316
},
317317
],
318318
},
319+
{
320+
code: `
321+
/**
322+
* @example
323+
* \`\`\`
324+
* Some things to escape: <a> and &gt; and &#xabc; and \`test\`
325+
* \`\`\`
326+
*/
327+
`,
328+
options: [
329+
{
330+
escapeHTML: true,
331+
},
332+
]
333+
},
334+
{
335+
code: `
336+
/**
337+
* @example
338+
* \`\`\`
339+
* Some things to escape: <a> and &gt; and &#xabc; and \`test\`
340+
* \`\`\`
341+
*/
342+
`,
343+
options: [
344+
{
345+
escapeMarkdown: true,
346+
},
347+
]
348+
},
319349
],
320350
});

0 commit comments

Comments
 (0)