diff --git a/__tests__/src/rules/img-redundant-alt-test.js b/__tests__/src/rules/img-redundant-alt-test.js
index ccacb210..3bd5fcbb 100644
--- a/__tests__/src/rules/img-redundant-alt-test.js
+++ b/__tests__/src/rules/img-redundant-alt-test.js
@@ -74,6 +74,7 @@ ruleTester.run('img-redundant-alt', rule, {
{ code: ';' },
{ code: '' },
{ code: '', settings: componentsSettings },
+ { code: '', options: [{ words: ['イメージ'] }] },
)).map(parserOptionsMapper),
invalid: parsers.all([].concat(
{ code: ';', errors: [expectedError] },
@@ -129,5 +130,8 @@ ruleTester.run('img-redundant-alt', rule, {
{ code: ';', options: array, errors: [expectedError] },
{ code: ';', options: array, errors: [expectedError] },
{ code: ';', options: array, errors: [expectedError] },
+
+ { code: '', options: [{ words: ['イメージ'] }], errors: [expectedError] },
+ { code: '', options: [{ words: ['イメージ'] }], errors: [expectedError] },
)).map(parserOptionsMapper),
});
diff --git a/src/rules/img-redundant-alt.js b/src/rules/img-redundant-alt.js
index 6e2ba640..b90eda7b 100644
--- a/src/rules/img-redundant-alt.js
+++ b/src/rules/img-redundant-alt.js
@@ -8,6 +8,7 @@
// ----------------------------------------------------------------------------
import { getProp, getLiteralPropValue } from 'jsx-ast-utils';
+import includes from 'array-includes';
import { generateObjSchema, arraySchema } from '../util/schemas';
import getElementType from '../util/getElementType';
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
@@ -25,6 +26,16 @@ const schema = generateObjSchema({
words: arraySchema,
});
+function containsRedundantWord(value, redundantWords) {
+ const lowercaseRedundantWords = redundantWords.map((redundantWord) => redundantWord.toLowerCase());
+ const isASCII = /[\x20-\x7F]+/.test(value);
+
+ if (isASCII) {
+ return value.split(/\s+/).some((valueWord) => includes(lowercaseRedundantWords, valueWord.toLowerCase()));
+ }
+ return lowercaseRedundantWords.some((redundantWord) => value.toLowerCase().includes(redundantWord));
+}
+
export default {
meta: {
docs: {
@@ -63,7 +74,7 @@ export default {
const redundantWords = REDUNDANT_WORDS.concat(words);
if (typeof value === 'string' && isVisible) {
- const hasRedundancy = new RegExp(`(?!{)\\b(${redundantWords.join('|')})\\b(?!})`, 'i').test(value);
+ const hasRedundancy = containsRedundantWord(value, redundantWords);
if (hasRedundancy === true) {
context.report({