@@ -4,10 +4,12 @@ import {
44 merge ,
55} from 'object-deep-merge' ;
66
7+ import {
8+ buildForbidRuleDefinition ,
9+ } from './buildForbidRuleDefinition.js' ;
710import {
811 getJsdocProcessorPlugin ,
912} from './getJsdocProcessorPlugin.js' ;
10- import iterateJsdoc from './iterateJsdoc.js' ;
1113import checkAccess from './rules/checkAccess.js' ;
1214import checkAlignment from './rules/checkAlignment.js' ;
1315import checkExamples from './rules/checkExamples.js' ;
@@ -67,91 +69,6 @@ import textEscaping from './rules/textEscaping.js';
6769import typeFormatting from './rules/typeFormatting.js' ;
6870import validTypes from './rules/validTypes.js' ;
6971
70- /**
71- * @param {{
72- * contexts: (string|{
73- * comment: string,
74- * context: string,
75- * message: string
76- * })[],
77- * description?: string,
78- * contextName?: string
79- * url?: string,
80- * }} cfg
81- * @returns {import('@eslint/core').RuleDefinition<
82- * import('@eslint/core').RuleDefinitionTypeOptions
83- * >}
84- */
85- export const buildForbidRuleDefinition = ( {
86- contextName,
87- contexts,
88- description,
89- url,
90- } ) => {
91- return iterateJsdoc ( ( {
92- // context,
93- info : {
94- comment,
95- } ,
96- report,
97- utils,
98- } ) => {
99- const {
100- contextStr,
101- foundContext,
102- } = utils . findContext ( contexts , comment ) ;
103-
104- // We are not on the *particular* matching context/comment, so don't assume
105- // we need reporting
106- if ( ! foundContext ) {
107- return ;
108- }
109-
110- const message = /** @type {import('./iterateJsdoc.js').ContextObject } */ (
111- foundContext
112- ) ?. message ??
113- 'Syntax is restricted: {{context}}' +
114- ( comment ? ' with {{comment}}' : '' ) ;
115-
116- report ( message , null , null , comment ? {
117- comment,
118- context : contextStr ,
119- } : {
120- context : contextStr ,
121- } ) ;
122- } , {
123- contextSelected : true ,
124- meta : {
125- docs : {
126- description : description ?? contextName ?? 'Reports when certain comment structures are present.' ,
127- url : url ?? 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/advanced.md#user-content-advanced-creating-your-own-rules' ,
128- } ,
129- fixable : 'code' ,
130- schema : [ ] ,
131- type : 'suggestion' ,
132- } ,
133- modifyContext : ( context ) => {
134- // Reproduce context object with our own `contexts`
135- const propertyDescriptors = Object . getOwnPropertyDescriptors ( context ) ;
136- return Object . create (
137- Object . getPrototypeOf ( context ) ,
138- {
139- ...propertyDescriptors ,
140- options : {
141- ...propertyDescriptors . options ,
142- value : [
143- {
144- contexts,
145- } ,
146- ] ,
147- } ,
148- } ,
149- ) ;
150- } ,
151- nonGlobalSettings : true ,
152- } ) ;
153- } ;
154-
15572/* eslint-disable jsdoc/valid-types -- Bug */
15673/**
15774 * @typedef {"recommended" | "stylistic" | "contents" | "logical" | "requirements" } ConfigGroups
0 commit comments