Socket
Socket
Sign inDemoInstall

eslint-plugin-format-message

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-format-message - npm Package Compare versions

Comparing version 4.0.1 to 4.1.0

5

CHANGELOG.md
# Changelog
## 4.1.0
* **Bug Fix**
* fixed compatibility with ESLint 3.0
## 4.0.1

@@ -4,0 +9,0 @@

21

lib/rules/literal-locale.js

@@ -6,11 +6,14 @@ 'use strict'

module.exports = function (context) {
return visitFormatCall(context, function (node) {
var locale = node.arguments[2]
if (locale && !astUtil.isStringish(locale)) {
context.report(locale, 'Locale is not a string literal')
}
})
module.exports = {
meta: {
schema: []
},
create: function (context) {
return visitFormatCall(context, function (node) {
var locale = node.arguments[2]
if (locale && !astUtil.isStringish(locale)) {
context.report(locale, 'Locale is not a string literal')
}
})
}
}
module.exports.schema = []

@@ -6,11 +6,14 @@ 'use strict'

module.exports = function (context) {
return visitFormatCall(context, function (node) {
var message = astUtil.getMessageDetails(node.arguments)
if (!message.default) {
context.report(node.arguments[0] || node, 'Pattern is not a string literal')
}
})
module.exports = {
meta: {
schema: []
},
create: function (context) {
return visitFormatCall(context, function (node) {
var message = astUtil.getMessageDetails(node.arguments)
if (!message.default) {
context.report(node.arguments[0] || node, 'Pattern is not a string literal')
}
})
}
}
module.exports.schema = []

@@ -6,18 +6,23 @@ 'use strict'

module.exports = function (context) {
var settings = getSettings(context)
var baseSourceLocale = (settings.sourceLocale || 'en').split('-')[0].toLowerCase()
module.exports = {
meta: {
schema: []
},
create: function (context) {
var settings = getSettings(context)
var baseSourceLocale = (settings.sourceLocale || 'en').split('-')[0].toLowerCase()
return visitEachTranslation(context, function (info) {
var id = info.id
var node = info.node
var locale = info.locale
var pattern = info.pattern
var translation = info.translation
return visitEachTranslation(context, function (info) {
var id = info.id
var node = info.node
var locale = info.locale
var pattern = info.pattern
var translation = info.translation
var baseLocale = locale.split('-')[0].toLowerCase()
if (translation === pattern && baseSourceLocale !== baseLocale) {
context.report(node, 'Translation for "' + id + '" in "' + locale + '" is identical to original')
}
})
var baseLocale = locale.split('-')[0].toLowerCase()
if (translation === pattern && baseSourceLocale !== baseLocale) {
context.report(node, 'Translation for "' + id + '" in "' + locale + '" is identical to original')
}
})
}
}

@@ -7,13 +7,18 @@ 'use strict'

module.exports = function (context) {
return visitFormatCall(context, function (node) {
var message = astUtil.getMessageDetails(node.arguments)
if (!message.default) return // not a literal, handled elsewhere
module.exports = {
meta: {
schema: []
},
create: function (context) {
return visitFormatCall(context, function (node) {
var message = astUtil.getMessageDetails(node.arguments)
if (!message.default) return // not a literal, handled elsewhere
try {
parse(message.default)
} catch (err) {
context.report(node.arguments[0] || node, 'Pattern is invalid: ' + err.message)
}
})
try {
parse(message.default)
} catch (err) {
context.report(node.arguments[0] || node, 'Pattern is invalid: ' + err.message)
}
})
}
}

@@ -6,18 +6,23 @@ 'use strict'

module.exports = function (context) {
return visitEachTranslation(context, function (info) {
var id = info.id
var node = info.node
var locale = info.locale
var translation = info.translation
if (translation == null) {
return // missing translation is handled in another rule
}
module.exports = {
meta: {
schema: []
},
create: function (context) {
return visitEachTranslation(context, function (info) {
var id = info.id
var node = info.node
var locale = info.locale
var translation = info.translation
if (translation == null) {
return // missing translation is handled in another rule
}
try {
parse(translation)
} catch (err) {
context.report(node, 'Translation for "' + id + '" in "' + locale + '" is invalid: ' + err.message)
}
})
try {
parse(translation)
} catch (err) {
context.report(node, 'Translation for "' + id + '" in "' + locale + '" is invalid: ' + err.message)
}
})
}
}

@@ -6,38 +6,41 @@ 'use strict'

module.exports = function (context) {
var allowNonLiteral = (context.options[0] || {}).allowNonLiteral
module.exports = {
meta: {
schema: [ {
type: 'object',
properties: {
allowNonLiteral: {
type: 'boolean'
}
}
} ]
},
create: function (context) {
var allowNonLiteral = (context.options[0] || {}).allowNonLiteral
return visitFormatCall(context, function (node) {
var info = getCommonTranslationInfo(node)
if (!info.patternAst) return // error in pattern, can't validate
if (!info.patternParams.length) return // pattern does not require parameters
return visitFormatCall(context, function (node) {
var info = getCommonTranslationInfo(node)
if (!info.patternAst) return // error in pattern, can't validate
if (!info.patternParams.length) return // pattern does not require parameters
var params = node.arguments[1]
var isLiteral = params && params.type === 'ObjectExpression'
if (params && !isLiteral && allowNonLiteral) return
var params = node.arguments[1]
var isLiteral = params && params.type === 'ObjectExpression'
if (params && !isLiteral && allowNonLiteral) return
if (!params) {
context.report(node.arguments[0], 'Pattern requires missing parameters')
} else if (!isLiteral) {
context.report(node.arguments[1], 'Parameters is not an object literal')
} else {
info.patternParams.forEach(function (paramName) {
var isFound = params.properties.some(function (prop) {
return prop.key.type === 'Identifier' && prop.key.name === paramName
if (!params) {
context.report(node.arguments[0], 'Pattern requires missing parameters')
} else if (!isLiteral) {
context.report(node.arguments[1], 'Parameters is not an object literal')
} else {
info.patternParams.forEach(function (paramName) {
var isFound = params.properties.some(function (prop) {
return prop.key.type === 'Identifier' && prop.key.name === paramName
})
if (!isFound) {
context.report(node.arguments[1], 'Pattern requires missing "' + paramName + '" parameter')
}
})
if (!isFound) {
context.report(node.arguments[1], 'Pattern requires missing "' + paramName + '" parameter')
}
})
}
})
}
})
}
}
module.exports.schema = [ {
type: 'object',
properties: {
allowNonLiteral: {
type: 'boolean'
}
}
} ]

@@ -5,13 +5,18 @@ 'use strict'

module.exports = function (context) {
return visitEachTranslation(context, function (info) {
var id = info.id
var node = info.node
var locale = info.locale
var translation = info.translation
module.exports = {
meta: {
schema: []
},
create: function (context) {
return visitEachTranslation(context, function (info) {
var id = info.id
var node = info.node
var locale = info.locale
var translation = info.translation
if (translation == null) {
context.report(node, 'Translation for "' + id + '" in "' + locale + '" is missing')
}
})
if (translation == null) {
context.report(node, 'Translation for "' + id + '" in "' + locale + '" is missing')
}
})
}
}

@@ -7,37 +7,42 @@ 'use strict'

module.exports = function (context) {
return visitEachTranslation(context, function (info) {
var id = info.id
var node = info.node
var locale = info.locale
var patternParams = info.patternParams
var translation = info.translation
module.exports = {
meta: {
schema: []
},
create: function (context) {
return visitEachTranslation(context, function (info) {
var id = info.id
var node = info.node
var locale = info.locale
var patternParams = info.patternParams
var translation = info.translation
var translationAst
try {
translationAst = parse(translation)
} catch (err) {
return // error handled elsewhere
}
var translationAst
try {
translationAst = parse(translation)
} catch (err) {
return // error handled elsewhere
}
var translationParams = astUtil.getParamsFromPatternAst(translationAst)
patternParams.forEach(function (paramName) {
if (translationParams.indexOf(paramName) < 0) {
context.report(
node.arguments[0] || node,
'Translation for "' + id + '" in "' + locale + '" is missing "' +
paramName + '" placeholder'
)
}
var translationParams = astUtil.getParamsFromPatternAst(translationAst)
patternParams.forEach(function (paramName) {
if (translationParams.indexOf(paramName) < 0) {
context.report(
node.arguments[0] || node,
'Translation for "' + id + '" in "' + locale + '" is missing "' +
paramName + '" placeholder'
)
}
})
translationParams.forEach(function (paramName) {
if (patternParams.indexOf(paramName) < 0) {
context.report(
node.arguments[0] || node,
'Translation for "' + id + '" in "' + locale + '" has extra "' +
paramName + '" placeholder'
)
}
})
})
translationParams.forEach(function (paramName) {
if (patternParams.indexOf(paramName) < 0) {
context.report(
node.arguments[0] || node,
'Translation for "' + id + '" in "' + locale + '" has extra "' +
paramName + '" placeholder'
)
}
})
})
}
}
{
"name": "eslint-plugin-format-message",
"version": "4.0.1",
"version": "4.1.0",
"description": "format-message i18n specific rules for ESLint",

@@ -30,4 +30,4 @@ "author": "Andy VanWagoner <thetalecrafter@gmail.com> (https://thetalecrafter.com/)",

"peerDependencies": {
"eslint": ">=0.8.0"
"eslint": ">=2.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc