@@ -11,9 +11,10 @@ import { toFileUrl } from "@std/path/to-file-url";
1111import { resolve } from "@std/path/resolve" ;
1212
1313const PASCAL_CASE_REGEXP = / ^ _ ? (?: [ A - Z ] [ a - z 0 - 9 ] * ) * _ ? $ / ;
14- const UPPER_CASE_ONLY = / ^ _ ? [ A - Z ] { 2 , } $ / ;
14+ const UPPER_CASE_ONLY_REGEXP = / ^ _ ? [ A - Z ] { 2 , } $ / ;
1515function isPascalCase ( string : string ) : boolean {
16- return PASCAL_CASE_REGEXP . test ( string ) && ! UPPER_CASE_ONLY . test ( string ) ;
16+ return PASCAL_CASE_REGEXP . test ( string ) &&
17+ ! UPPER_CASE_ONLY_REGEXP . test ( string ) ;
1718}
1819
1920const CAMEL_CASE_REGEXP = / ^ [ _ a - z ] [ a - z 0 - 9 ] * (?: [ A - Z ] [ a - z 0 - 9 ] * ) * _ ? $ / ;
@@ -233,6 +234,38 @@ export default {
233234 if ( id . type !== "Identifier" ) return ;
234235 const name = id . name ;
235236 if ( ! name ) return ;
237+ if ( isConstantCase ( name ) ) {
238+ if (
239+ declaration . init ?. type === "NewExpression" &&
240+ declaration . init . callee . type === "Identifier"
241+ ) {
242+ switch ( declaration . init . callee . name ) {
243+ case "RegExp" : {
244+ if ( name !== "REGEXP" && ! name . endsWith ( "_REGEXP" ) ) {
245+ context . report ( {
246+ node : id ,
247+ message :
248+ `RegExp variable name '${ name } ' must end with _REGEXP.` ,
249+ fix : ( fixer ) =>
250+ fixer . replaceText ( id , `${ name } _REGEXP` ) ,
251+ } ) ;
252+ }
253+ break ;
254+ }
255+ }
256+ } else if (
257+ declaration . init ?. type === "Literal" &&
258+ declaration . init . value instanceof RegExp &&
259+ name !== "REGEXP" && ! name . endsWith ( "_REGEXP" )
260+ ) {
261+ context . report ( {
262+ node : id ,
263+ message :
264+ `RegExp variable name '${ name } ' must end with _REGEXP.` ,
265+ fix : ( fixer ) => fixer . replaceText ( id , `${ name } _REGEXP` ) ,
266+ } ) ;
267+ }
268+ }
236269 if (
237270 ! isConstantCase ( name ) && ! isCamelCase ( name ) &&
238271 ! isPascalCase ( name )
0 commit comments