eslint-plugin-format-message
Advanced tools
Comparing version 5.1.1 to 5.1.2
@@ -12,2 +12,3 @@ 'use strict' | ||
'no-missing-translation': require('./lib/rules/no-missing-translation'), | ||
'no-top-scope': require('./lib/rules/no-top-scope'), | ||
'translation-match-params': require('./lib/rules/translation-match-params'), | ||
@@ -28,2 +29,3 @@ 'no-empty-jsx-message': require('./lib/rules/no-empty-jsx-message'), | ||
'format-message/no-missing-translation': 1, | ||
'format-message/no-top-scope': 0, | ||
'format-message/translation-match-params': 2, | ||
@@ -43,2 +45,3 @@ 'format-message/no-empty-jsx-message': 1, | ||
'format-message/no-missing-translation': 0, | ||
'format-message/no-top-scope': 0, | ||
'format-message/translation-match-params': 2, | ||
@@ -45,0 +48,0 @@ 'format-message/no-empty-jsx-message': 2, |
@@ -13,11 +13,13 @@ 'use strict' | ||
return ( | ||
typeof element === 'string' || | ||
element[TYPE] === 'select' && | ||
Object.keys(element[SELECT_OPTIONS]).some(function (key) { | ||
return element[SELECT_OPTIONS][key].some(hasTextPart) | ||
}) || | ||
(element[TYPE] === 'plural' || element[TYPE] === 'selectordinal') && | ||
Object.keys(element[PLURAL_OPTIONS]).some(function (key) { | ||
return element[PLURAL_OPTIONS][key].some(hasTextPart) | ||
}) | ||
typeof element === 'string' || ( | ||
element[TYPE] === 'select' && | ||
Object.keys(element[SELECT_OPTIONS]).some(function (key) { | ||
return element[SELECT_OPTIONS][key].some(hasTextPart) | ||
}) | ||
) || ( | ||
(element[TYPE] === 'plural' || element[TYPE] === 'selectordinal') && | ||
Object.keys(element[PLURAL_OPTIONS]).some(function (key) { | ||
return element[PLURAL_OPTIONS][key].some(hasTextPart) | ||
}) | ||
) | ||
) | ||
@@ -24,0 +26,0 @@ } |
@@ -20,3 +20,3 @@ 'use strict' | ||
if (translate && translate.type !== 'Literal') return | ||
if (!translate || translate.value !== 'yes' && translate.value !== 'no') { | ||
if (!translate || (translate.value !== 'yes' && translate.value !== 'no')) { | ||
context.report(attribute, 'Attribute translate should be "yes" or "no"') | ||
@@ -23,0 +23,0 @@ } |
@@ -6,2 +6,27 @@ 'use strict' | ||
var validatePath = function (object, path) { | ||
var pathSegments = path.split('.') || path | ||
var isValid = false | ||
var lookFurther = function (object, segment) { | ||
if (object.properties[0].value.type === 'Literal') { | ||
return object.properties[0].value.value === segment | ||
} else { | ||
return lookFurther(object.properties[0].value, segment) | ||
} | ||
} | ||
pathSegments.forEach(function (segment, i) { | ||
if (i === 0) { | ||
isValid = object.key.value === segment | ||
} else if (object.value.properties[0].value.type === 'ObjectExpression') { | ||
isValid = object.value.properties[0].key.value === segment | ||
if (!isValid) { | ||
isValid = lookFurther(object.value.properties[0].value, segment) | ||
} | ||
} else if (object.value.properties[0].value.type === 'Literal') { | ||
isValid = object.value.properties[0].value.value === segment | ||
} | ||
}) | ||
return isValid | ||
} | ||
module.exports = { | ||
@@ -37,3 +62,9 @@ meta: { | ||
var isFound = params.properties.some(function (prop) { | ||
return prop.key.type === 'Identifier' && prop.key.name === paramName | ||
if (prop.value.type === 'ObjectExpression') { | ||
return validatePath(prop, paramName) | ||
} | ||
return ( | ||
(prop.key.type === 'Identifier' && prop.key.name === paramName) || | ||
(prop.key.type === 'Literal' && prop.key.value === paramName) | ||
) | ||
}) | ||
@@ -40,0 +71,0 @@ if (!isFound) { |
@@ -30,3 +30,3 @@ 'use strict' | ||
context.report( | ||
node.arguments && node.arguments[0] || node, | ||
(node.arguments && node.arguments[0]) || node, | ||
'Translation for "' + id + '" in "' + locale + '" is missing "' + | ||
@@ -40,3 +40,3 @@ paramName + '" placeholder' | ||
context.report( | ||
node.arguments && node.arguments[0] || node, | ||
(node.arguments && node.arguments[0]) || node, | ||
'Translation for "' + id + '" in "' + locale + '" has extra "' + | ||
@@ -43,0 +43,0 @@ paramName + '" placeholder' |
{ | ||
"name": "eslint-plugin-format-message", | ||
"version": "5.1.1", | ||
"version": "5.1.2", | ||
"description": "format-message i18n specific rules for ESLint", | ||
@@ -26,6 +26,6 @@ "author": "Andy VanWagoner <thetalecrafter@gmail.com> (https://thetalecrafter.com/)", | ||
"dependencies": { | ||
"format-message": "^5.1.1", | ||
"format-message-estree-util": "^5.1.0", | ||
"format-message-generate-id": "^5.1.0", | ||
"format-message-parse": "^5.1.0" | ||
"format-message": "^5.1.2", | ||
"format-message-estree-util": "^5.1.2", | ||
"format-message-generate-id": "^5.1.2", | ||
"format-message-parse": "^5.1.2" | ||
}, | ||
@@ -32,0 +32,0 @@ "peerDependencies": { |
@@ -116,2 +116,4 @@ # eslint-plugin-format-message | ||
Parameters support nested data objects. To prevent any issues, it's recommended that you avoid using object keys with `.` if you're using nested data. | ||
#### no-missing-translation | ||
@@ -118,0 +120,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28325
22
558
165