eslint-plugin-jsdoc 59.0.1 → 59.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,59 +1,26 @@
1
- import iterateJsdoc from '../iterateJsdoc.js';
1
+ import {
2
+ buildForbidRuleDefinition,
3
+ } from '../buildForbidRuleDefinition.js';
2
4
 
3
- export default iterateJsdoc(({
4
- context,
5
- info: {
6
- comment,
7
- },
8
- report,
9
- utils,
10
- }) => {
11
- if (!context.options.length) {
12
- report('Rule `no-restricted-syntax` is missing a `contexts` option.');
13
-
14
- return;
15
- }
16
-
17
- const {
18
- contexts,
19
- } = context.options[0];
5
+ export default buildForbidRuleDefinition({
6
+ getContexts (context, report) {
7
+ if (!context.options.length) {
8
+ report('Rule `no-restricted-syntax` is missing a `contexts` option.');
9
+ return false;
10
+ }
20
11
 
21
- const {
22
- contextStr,
23
- foundContext,
24
- } = utils.findContext(contexts, comment);
12
+ const {
13
+ contexts,
14
+ } = context.options[0];
25
15
 
26
- // We are not on the *particular* matching context/comment, so don't assume
27
- // we need reporting
28
- if (!foundContext) {
29
- return;
30
- }
31
-
32
- const message = /** @type {import('../iterateJsdoc.js').ContextObject} */ (
33
- foundContext
34
- )?.message ??
35
- 'Syntax is restricted: {{context}}' +
36
- (comment ? ' with {{comment}}' : '');
37
-
38
- report(message, null, null, comment ? {
39
- comment,
40
- context: contextStr,
41
- } : {
42
- context: contextStr,
43
- });
44
- }, {
45
- contextSelected: true,
46
- meta: {
47
- docs: {
48
- description: 'Reports when certain comment structures are present.',
49
- url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-restricted-syntax.md#repos-sticky-header',
50
- },
51
- schema: [
52
- {
53
- additionalProperties: false,
54
- properties: {
55
- contexts: {
56
- description: `Set this to an array of strings representing the AST context (or an object with
16
+ return contexts;
17
+ },
18
+ schema: [
19
+ {
20
+ additionalProperties: false,
21
+ properties: {
22
+ contexts: {
23
+ description: `Set this to an array of strings representing the AST context (or an object with
57
24
  \`context\` and \`comment\` properties) where you wish the rule to be applied.
58
25
 
59
26
  \`context\` defaults to \`any\` and \`comment\` defaults to no specific comment context.
@@ -70,38 +37,36 @@ aliases \`@func\` or \`@method\`) (including those associated with an \`@interfa
70
37
 
71
38
  See the ["AST and Selectors"](../#advanced-ast-and-selectors)
72
39
  section of our Advanced docs for more on the expected format.`,
73
- items: {
74
- anyOf: [
75
- {
76
- type: 'string',
77
- },
78
- {
79
- additionalProperties: false,
80
- properties: {
81
- comment: {
82
- type: 'string',
83
- },
84
- context: {
85
- type: 'string',
86
- },
87
- message: {
88
- type: 'string',
89
- },
40
+ items: {
41
+ anyOf: [
42
+ {
43
+ type: 'string',
44
+ },
45
+ {
46
+ additionalProperties: false,
47
+ properties: {
48
+ comment: {
49
+ type: 'string',
50
+ },
51
+ context: {
52
+ type: 'string',
53
+ },
54
+ message: {
55
+ type: 'string',
90
56
  },
91
- type: 'object',
92
57
  },
93
- ],
94
- },
95
- type: 'array',
58
+ type: 'object',
59
+ },
60
+ ],
96
61
  },
62
+ type: 'array',
97
63
  },
98
- required: [
99
- 'contexts',
100
- ],
101
- type: 'object',
102
64
  },
103
- ],
104
- type: 'suggestion',
105
- },
106
- nonGlobalSettings: true,
65
+ required: [
66
+ 'contexts',
67
+ ],
68
+ type: 'object',
69
+ },
70
+ ],
71
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-restricted-syntax.md#repos-sticky-header',
107
72
  });
@@ -115,7 +115,7 @@ export default iterateJsdoc(({
115
115
  const allComments = sourceCode.getAllComments();
116
116
  const comments = allComments
117
117
  .filter((comment) => {
118
- return (/^\*\s/v).test(comment.value);
118
+ return (/^\*(?!\*)/v).test(comment.value);
119
119
  })
120
120
  .map((commentNode) => {
121
121
  return parseComment(commentNode, '');
@@ -0,0 +1,85 @@
1
+ import {
2
+ buildForbidRuleDefinition,
3
+ } from '../buildForbidRuleDefinition.js';
4
+
5
+ export default buildForbidRuleDefinition({
6
+ description: 'Requires tags be present, optionally for specific contexts',
7
+ getContexts (context, report) {
8
+ // Transformed options to this option in `modifyContext`:
9
+ if (!context.options[0].contexts) {
10
+ report('Rule `required-tags` is missing a `tags` option.');
11
+ return false;
12
+ }
13
+
14
+ const {
15
+ contexts,
16
+ } = context.options[0];
17
+
18
+ return contexts;
19
+ },
20
+ modifyContext (context) {
21
+ const tags = /** @type {(string|{tag: string, context: string})[]} */ (
22
+ context.options?.[0]?.tags
23
+ );
24
+
25
+ const cntxts = tags?.map((tag) => {
26
+ const tagName = typeof tag === 'string' ? tag : tag.tag;
27
+ return {
28
+ comment: `JsdocBlock:not(*:has(JsdocTag[tag=${
29
+ tagName
30
+ }]))`,
31
+ context: typeof tag === 'string' ? 'any' : tag.context,
32
+ message: `Missing required tag "${tagName}"`,
33
+ };
34
+ });
35
+
36
+ // Reproduce context object with our own `contexts`
37
+ const propertyDescriptors = Object.getOwnPropertyDescriptors(context);
38
+ return Object.create(
39
+ Object.getPrototypeOf(context),
40
+ {
41
+ ...propertyDescriptors,
42
+ options: {
43
+ ...propertyDescriptors.options,
44
+ value: [
45
+ {
46
+ contexts: cntxts,
47
+ },
48
+ ],
49
+ },
50
+ },
51
+ );
52
+ },
53
+ schema: [
54
+ {
55
+ additionalProperties: false,
56
+ properties: {
57
+ tags: {
58
+ description: `May be an array of either strings or objects with
59
+ a string \`tag\` property and \`context\` string property.`,
60
+ items: {
61
+ anyOf: [
62
+ {
63
+ type: 'string',
64
+ },
65
+ {
66
+ properties: {
67
+ context: {
68
+ type: 'string',
69
+ },
70
+ tag: {
71
+ type: 'string',
72
+ },
73
+ },
74
+ type: 'object',
75
+ },
76
+ ],
77
+ },
78
+ type: 'array',
79
+ },
80
+ },
81
+ type: 'object',
82
+ },
83
+ ],
84
+ url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/required-tags.md#repos-sticky-header',
85
+ });
package/src/rules.d.ts CHANGED
@@ -2580,6 +2580,26 @@ export interface Rules {
2580
2580
  /** Requires a type for `@yields` tags */
2581
2581
  "jsdoc/require-yields-type": [];
2582
2582
 
2583
+ /** Requires tags be present, optionally for specific contexts */
2584
+ "jsdoc/required-tags":
2585
+ | []
2586
+ | [
2587
+ {
2588
+ /**
2589
+ * May be an array of either strings or objects with
2590
+ * a string `tag` property and `context` string property.
2591
+ */
2592
+ tags?: (
2593
+ | string
2594
+ | {
2595
+ context?: string;
2596
+ tag?: string;
2597
+ [k: string]: unknown;
2598
+ }
2599
+ )[];
2600
+ }
2601
+ ];
2602
+
2583
2603
  /** Sorts tags by a specified sequence according to tag name, optionally adding line breaks between tag groups. */
2584
2604
  "jsdoc/sort-tags":
2585
2605
  | []