1+ import { ConfigCommentParser } from '@eslint/plugin-kit' ;
12import path from 'node:path' ;
23import { isRegExp } from 'node:util/types' ;
34import semver from 'semver' ;
@@ -267,6 +268,8 @@ const DEFAULT_OPTIONS = {
267268 allowWarningComments : true ,
268269} ;
269270
271+ let configCommentParser ;
272+
270273/** @param {import('eslint').Rule.RuleContext } context */
271274const create = context => {
272275 const options = {
@@ -284,13 +287,6 @@ const create = context => {
284287
285288 const { sourceCode} = context ;
286289 const comments = sourceCode . getAllComments ( ) ;
287-
288- const isEslintDirectiveComment = comment => {
289- // Strip leading whitespace and optional `*` from block comments
290- const normalizedComment = comment . value . trimStart ( ) . replace ( / ^ \* \s * / , '' ) ;
291- return / ^ e s l i n t (?: - (?: e n | d i s ) a b l e ) ? (?: - (?: n e x t - ) ? l i n e ) ? \b / . test ( normalizedComment ) ;
292- } ;
293-
294290 const unusedComments = comments
295291 . filter ( token => token . type !== 'Shebang' )
296292 // Block comments come as one.
@@ -326,7 +322,10 @@ const create = context => {
326322
327323 // eslint-disable-next-line complexity
328324 function processComment ( comment ) {
329- if ( isEslintDirectiveComment ( comment ) ) {
325+ configCommentParser ??= new ConfigCommentParser ( ) ;
326+
327+ const directive = configCommentParser . parseDirective ( comment . value ) ;
328+ if ( directive ?. label ?. startsWith ( 'eslint' ) ) {
330329 return ;
331330 }
332331
0 commit comments