File tree Expand file tree Collapse file tree 4 files changed +13
-4
lines changed Expand file tree Collapse file tree 4 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 8989 "minimatch" : " ^3.1.2" ,
9090 "object.entries" : " ^1.1.7" ,
9191 "object.fromentries" : " ^2.0.7" ,
92+ "safe-regex-test" : " ^1.0.1" ,
9293 "string.prototype.includes" : " ^2.0.0"
9394 },
9495 "peerDependencies" : {
Original file line number Diff line number Diff line change 99
1010import emojiRegex from 'emoji-regex' ;
1111import { getProp , getLiteralPropValue } from 'jsx-ast-utils' ;
12+ import safeRegexTest from 'safe-regex-test' ;
1213import { generateObjSchema } from '../util/schemas' ;
1314import getElementType from '../util/getElementType' ;
1415import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader' ;
@@ -29,11 +30,13 @@ export default {
2930
3031 create : ( context ) => {
3132 const elementType = getElementType ( context ) ;
33+
34+ const testEmoji = safeRegexTest ( emojiRegex ( ) ) ;
3235 return {
3336 JSXOpeningElement : ( node ) => {
3437 const literalChildValue = node . parent . children . find ( ( child ) => child . type === 'Literal' || child . type === 'JSXText' ) ;
3538
36- if ( literalChildValue && emojiRegex ( ) . test ( literalChildValue . value ) ) {
39+ if ( literalChildValue && testEmoji ( literalChildValue . value ) ) {
3740 const elementIsHidden = isHiddenFromScreenReader ( elementType ( node ) , node . attributes ) ;
3841 if ( elementIsHidden ) {
3942 return ; // emoji is decorative
Original file line number Diff line number Diff line change 1010
1111import { getProp , getPropValue } from 'jsx-ast-utils' ;
1212import type { JSXOpeningElement } from 'ast-types-flow' ;
13+ import safeRegexTest from 'safe-regex-test' ;
1314import type { ESLintConfig , ESLintContext , ESLintVisitorSelectorConfig } from '../../flow/eslint' ;
1415import { generateObjSchema , arraySchema , enumArraySchema } from '../util/schemas' ;
1516import getElementType from '../util/getElementType' ;
@@ -39,6 +40,8 @@ export default ({
3940
4041 create : ( context : ESLintContext ) : ESLintVisitorSelectorConfig => {
4142 const elementType = getElementType ( context ) ;
43+ const testJShref = safeRegexTest ( / ^ \W * ?j a v a s c r i p t : / ) ;
44+
4245 return {
4346 JSXOpeningElement : ( node : JSXOpeningElement ) : void => {
4447 const { attributes } = node ;
@@ -98,7 +101,7 @@ export default ({
98101 . filter ( ( value ) => (
99102 value != null
100103 && ( typeof value === 'string' && (
101- ! value . length || value === '#' || / ^ \W * ? j a v a s c r i p t : / . test ( value )
104+ ! value . length || value === '#' || testJShref ( value )
102105 ) )
103106 ) ) ;
104107 if ( invalidHrefValues . length !== 0 ) {
Original file line number Diff line number Diff line change 1010import { getProp , getLiteralPropValue } from 'jsx-ast-utils' ;
1111import includes from 'array-includes' ;
1212import stringIncludes from 'string.prototype.includes' ;
13+ import safeRegexTest from 'safe-regex-test' ;
1314import { generateObjSchema , arraySchema } from '../util/schemas' ;
1415import getElementType from '../util/getElementType' ;
1516import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader' ;
@@ -27,11 +28,12 @@ const schema = generateObjSchema({
2728 words : arraySchema ,
2829} ) ;
2930
31+ const isASCII = safeRegexTest ( / [ \x20 - \x7F ] + / ) ;
32+
3033function containsRedundantWord ( value , redundantWords ) {
3134 const lowercaseRedundantWords = redundantWords . map ( ( redundantWord ) => redundantWord . toLowerCase ( ) ) ;
32- const isASCII = / [ \x20 - \x7F ] + / . test ( value ) ;
3335
34- if ( isASCII ) {
36+ if ( isASCII ( value ) ) {
3537 return value . split ( / \s + / ) . some ( ( valueWord ) => includes ( lowercaseRedundantWords , valueWord . toLowerCase ( ) ) ) ;
3638 }
3739 return lowercaseRedundantWords . some ( ( redundantWord ) => stringIncludes ( value . toLowerCase ( ) , redundantWord ) ) ;
You can’t perform that action at this time.
0 commit comments