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 89
89
"minimatch" : " ^3.1.2" ,
90
90
"object.entries" : " ^1.1.7" ,
91
91
"object.fromentries" : " ^2.0.7" ,
92
+ "safe-regex-test" : " ^1.0.1" ,
92
93
"string.prototype.includes" : " ^2.0.0"
93
94
},
94
95
"peerDependencies" : {
Original file line number Diff line number Diff line change 9
9
10
10
import emojiRegex from 'emoji-regex' ;
11
11
import { getProp , getLiteralPropValue } from 'jsx-ast-utils' ;
12
+ import safeRegexTest from 'safe-regex-test' ;
12
13
import { generateObjSchema } from '../util/schemas' ;
13
14
import getElementType from '../util/getElementType' ;
14
15
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader' ;
@@ -29,11 +30,13 @@ export default {
29
30
30
31
create : ( context ) => {
31
32
const elementType = getElementType ( context ) ;
33
+
34
+ const testEmoji = safeRegexTest ( emojiRegex ( ) ) ;
32
35
return {
33
36
JSXOpeningElement : ( node ) => {
34
37
const literalChildValue = node . parent . children . find ( ( child ) => child . type === 'Literal' || child . type === 'JSXText' ) ;
35
38
36
- if ( literalChildValue && emojiRegex ( ) . test ( literalChildValue . value ) ) {
39
+ if ( literalChildValue && testEmoji ( literalChildValue . value ) ) {
37
40
const elementIsHidden = isHiddenFromScreenReader ( elementType ( node ) , node . attributes ) ;
38
41
if ( elementIsHidden ) {
39
42
return ; // emoji is decorative
Original file line number Diff line number Diff line change 10
10
11
11
import { getProp , getPropValue } from 'jsx-ast-utils' ;
12
12
import type { JSXOpeningElement } from 'ast-types-flow' ;
13
+ import safeRegexTest from 'safe-regex-test' ;
13
14
import type { ESLintConfig , ESLintContext , ESLintVisitorSelectorConfig } from '../../flow/eslint' ;
14
15
import { generateObjSchema , arraySchema , enumArraySchema } from '../util/schemas' ;
15
16
import getElementType from '../util/getElementType' ;
@@ -39,6 +40,8 @@ export default ({
39
40
40
41
create : ( context : ESLintContext ) : ESLintVisitorSelectorConfig => {
41
42
const elementType = getElementType ( context ) ;
43
+ const testJShref = safeRegexTest ( / ^ \W * ?j a v a s c r i p t : / ) ;
44
+
42
45
return {
43
46
JSXOpeningElement : ( node : JSXOpeningElement ) : void => {
44
47
const { attributes } = node ;
@@ -98,7 +101,7 @@ export default ({
98
101
. filter ( ( value ) => (
99
102
value != null
100
103
&& ( 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 )
102
105
) )
103
106
) ) ;
104
107
if ( invalidHrefValues . length !== 0 ) {
Original file line number Diff line number Diff line change 10
10
import { getProp , getLiteralPropValue } from 'jsx-ast-utils' ;
11
11
import includes from 'array-includes' ;
12
12
import stringIncludes from 'string.prototype.includes' ;
13
+ import safeRegexTest from 'safe-regex-test' ;
13
14
import { generateObjSchema , arraySchema } from '../util/schemas' ;
14
15
import getElementType from '../util/getElementType' ;
15
16
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader' ;
@@ -27,11 +28,12 @@ const schema = generateObjSchema({
27
28
words : arraySchema ,
28
29
} ) ;
29
30
31
+ const isASCII = safeRegexTest ( / [ \x20 - \x7F ] + / ) ;
32
+
30
33
function containsRedundantWord ( value , redundantWords ) {
31
34
const lowercaseRedundantWords = redundantWords . map ( ( redundantWord ) => redundantWord . toLowerCase ( ) ) ;
32
- const isASCII = / [ \x20 - \x7F ] + / . test ( value ) ;
33
35
34
- if ( isASCII ) {
36
+ if ( isASCII ( value ) ) {
35
37
return value . split ( / \s + / ) . some ( ( valueWord ) => includes ( lowercaseRedundantWords , valueWord . toLowerCase ( ) ) ) ;
36
38
}
37
39
return lowercaseRedundantWords . some ( ( redundantWord ) => stringIncludes ( value . toLowerCase ( ) , redundantWord ) ) ;
You can’t perform that action at this time.
0 commit comments