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.8.0 to 4.9.0

2

package.json
{
"name": "eslint-plugin-formatjs",
"version": "4.8.0",
"version": "4.9.0",
"description": "ESLint plugin for formatjs",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,13 +5,41 @@ "use strict";

const icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
const manipulator_1 = require("@formatjs/icu-messageformat-parser/manipulator");
function calculateComplexity(ast) {
if (ast.length === 1) {
const el = ast[0];
if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
return Object.keys(el.options).reduce((complexity, k) => {
return complexity + calculateComplexity(el.options[k].value);
}, 0);
// Dynamic programming: define a complexity function f, where:
// f(plural | select) = sum(f(option) for each option) * f(next element),
// f(tag) = f(first element of children) * f(next element),
// f(other) = f(next element),
// f(out of bound) = 1.
const complexityByNode = new Map();
return _calculate(ast, 0);
function _calculate(ast, index) {
const element = ast[index];
if (!element) {
return 1;
}
const cachedComplexity = complexityByNode.get(element);
if (cachedComplexity !== undefined) {
return cachedComplexity;
}
let complexity;
switch (element.type) {
case icu_messageformat_parser_1.TYPE.plural:
case icu_messageformat_parser_1.TYPE.select: {
let sumOfOptions = 0;
for (const { value } of Object.values(element.options)) {
sumOfOptions += _calculate(value, 0);
}
complexity = sumOfOptions * _calculate(ast, index + 1);
break;
}
case icu_messageformat_parser_1.TYPE.tag:
complexity =
_calculate(element.children, 0) * _calculate(ast, index + 1);
break;
default:
complexity = _calculate(ast, index + 1);
break;
}
complexityByNode.set(element, complexity);
return complexity;
}
return 1;
}

@@ -47,4 +75,3 @@ function checkNode(context, node) {

try {
const hoistedAst = (0, manipulator_1.hoistSelectors)(ast);
complexity = calculateComplexity(hoistedAst);
complexity = calculateComplexity(ast);
}

@@ -51,0 +78,0 @@ catch (e) {

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