Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-formatjs

Package Overview
Dependencies
Maintainers
3
Versions
236
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-formatjs - npm Package Compare versions

Comparing version 4.5.0 to 4.6.0

4

index.js

@@ -37,5 +37,5 @@ "use strict";

'no-offset': no_offset_1.default,
'no-useless-message': no_useless_message_1.default
}
'no-useless-message': no_useless_message_1.default,
},
};
module.exports = plugin;
{
"name": "eslint-plugin-formatjs",
"version": "4.5.0",
"version": "4.6.0",
"description": "ESLint plugin for formatjs",

@@ -23,11 +23,12 @@ "main": "index.js",

"dependencies": {
"@formatjs/icu-messageformat-parser": "2.1.14",
"@formatjs/ts-transformer": "3.11.5",
"@formatjs/icu-messageformat-parser": "2.2.0",
"@formatjs/ts-transformer": "3.11.6",
"@types/eslint": "7 || 8",
"@types/picomatch": "^2.3.0",
"@typescript-eslint/typescript-estree": "^5.9.1",
"emoji-regex": "^10.0.0",
"@typescript-eslint/typescript-estree": "5.45.0",
"emoji-regex": "^10.2.1",
"picomatch": "^2.3.1",
"tslib": "^2.4.0",
"typescript": "^4.7"
"tslib": "2.4.0",
"typescript": "^4.7",
"unicode-emoji-utils": "^1.1.1"
},

@@ -34,0 +35,0 @@ "peerDependencies": {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const util_1 = require("../util");
const emoji_regex_1 = tslib_1.__importDefault(require("emoji-regex"));
const EMOJI_REGEX = emoji_regex_1.default();
const unicode_emoji_utils_1 = require("unicode-emoji-utils");
function checkNode(context, node) {
const msgs = (0, util_1.extractMessages)(node, (0, util_1.getSettings)(context));
let allowedEmojis = [];
let versionAbove;
const [emojiConfig] = context.options;
if (emojiConfig?.versionAbove &&
(0, unicode_emoji_utils_1.isValidEmojiVersion)(emojiConfig.versionAbove) &&
!versionAbove &&
allowedEmojis.length === 0) {
versionAbove = emojiConfig.versionAbove;
allowedEmojis = (0, unicode_emoji_utils_1.getAllEmojis)((0, unicode_emoji_utils_1.filterEmojis)(versionAbove));
}
for (const [{ message: { defaultMessage }, messageNode, },] of msgs) {

@@ -13,10 +21,42 @@ if (!defaultMessage || !messageNode) {

}
if (EMOJI_REGEX.test(defaultMessage)) {
context.report({
node: messageNode,
message: 'Emojis are not allowed',
});
if ((0, unicode_emoji_utils_1.hasEmoji)(defaultMessage)) {
if (versionAbove) {
for (const emoji of (0, unicode_emoji_utils_1.extractEmojis)(defaultMessage)) {
if (!allowedEmojis.includes(emoji)) {
context.report({
node: messageNode,
messageId: 'notAllowedAboveVersion',
data: {
versionAbove,
emoji,
},
});
}
}
}
else {
context.report({
node: messageNode,
messageId: 'notAllowed',
});
}
}
}
}
const versionAboveEnums = [
'0.6',
'0.7',
'1.0',
'2.0',
'3.0',
'4.0',
'5.0',
'11.0',
'12.0',
'12.1',
'13.0',
'13.1',
'14.0',
'15.0',
];
const rule = {

@@ -32,2 +72,13 @@ meta: {

fixable: 'code',
schema: [
{
type: 'object',
properties: { versionAbove: { type: 'string', enum: versionAboveEnums } },
additionalProperties: false,
},
],
messages: {
notAllowed: 'Emojis are not allowed',
notAllowedAboveVersion: 'Emojis above version {{versionAbove}} are not allowed - Emoji: {{emoji}}',
},
},

@@ -34,0 +85,0 @@ create(context) {

@@ -53,3 +53,3 @@ "use strict";

verifyAst((0, icu_messageformat_parser_1.parse)(defaultMessage, {
ignoreTag: settings.ignoreTag
ignoreTag: settings.ignoreTag,
}));

@@ -60,3 +60,3 @@ }

node: messageNode,
message: e instanceof Error ? e.message : String(e)
message: e instanceof Error ? e.message : String(e),
});

@@ -72,5 +72,5 @@ }

recommended: true,
url: 'https://formatjs.io/docs/tooling/linter#no-useless-message'
url: 'https://formatjs.io/docs/tooling/linter#no-useless-message',
},
fixable: 'code'
fixable: 'code',
},

@@ -81,5 +81,5 @@ create(context) {

return context.parserServices.defineTemplateBodyVisitor({
CallExpression: callExpressionVisitor
CallExpression: callExpressionVisitor,
}, {
CallExpression: callExpressionVisitor
CallExpression: callExpressionVisitor,
});

@@ -89,6 +89,6 @@ }

JSXOpeningElement: (node) => checkNode(context, node),
CallExpression: callExpressionVisitor
CallExpression: callExpressionVisitor,
};
}
},
};
exports.default = rule;

Sorry, the diff of this file is not supported yet

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