Socket
Socket
Sign inDemoInstall

eslint-plugin-functional

Package Overview
Dependencies
Maintainers
2
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-functional - npm Package Compare versions

Comparing version 3.2.2 to 3.3.0

8

CHANGELOG.md

@@ -10,6 +10,12 @@ # Changelog

## [v3.2.2](https://github.com/jonaskello/eslint-plugin-functional/compare/v3.2.1...v3.2.2)
## [v3.3.0](https://github.com/jonaskello/eslint-plugin-functional/compare/v3.2.2...v3.3.0)
### Fixed
- feat(no-conditional-statement): support never-returning functions for option allowReturningBranches [`#99`](https://github.com/jonaskello/eslint-plugin-functional/issues/99)
## [v3.2.2](https://github.com/jonaskello/eslint-plugin-functional/compare/v3.2.1...v3.2.2) - 2021-07-23
### Fixed
- fix(prefer-type-literal): deprecated rule [`#170`](https://github.com/jonaskello/eslint-plugin-functional/issues/170)

@@ -16,0 +22,0 @@

@@ -138,2 +138,3 @@ 'use strict';

rules: {
"functional/immutable-data": ["error", { ignoreClass: "fieldsOnly" }],
"functional/no-conditional-statement": "off",

@@ -189,2 +190,5 @@ "functional/no-expression-statement": "off",

}
function isClassProperty(node) {
return node.type === experimentalUtils.AST_NODE_TYPES.ClassProperty;
}
function isClassLike(node) {

@@ -234,2 +238,5 @@ return (node.type === experimentalUtils.AST_NODE_TYPES.ClassDeclaration ||

}
function isThrowStatement(node) {
return node.type === experimentalUtils.AST_NODE_TYPES.ThrowStatement;
}
function isTSArrayType(node) {

@@ -316,2 +323,5 @@ return node.type === experimentalUtils.AST_NODE_TYPES.TSArrayType;

}
function isNeverType(type) {
return ts !== undefined && type.flags === ts.TypeFlags.Never;
}

@@ -399,3 +409,11 @@ function getAncestorOfType(checker, node, child = null) {

ignoreClass: {
type: "boolean",
oneOf: [
{
type: "boolean",
},
{
type: "string",
enum: ["fieldsOnly"],
},
],
},

@@ -480,2 +498,8 @@ },

(options.ignoreClass === true && inClass(node)) ||
(options.ignoreClass === "fieldsOnly" &&
(isClassProperty(node) ||
(isAssignmentExpression(node) &&
inClass(node) &&
isMemberExpression(node.left) &&
isThisExpression(node.left.object)))) ||
(options.ignoreInterface === true && inInterface(node)) ||

@@ -491,3 +515,3 @@ ((texts) => texts.length > 0

const version = "3.2.1";
const version = "3.2.2";

@@ -691,2 +715,3 @@ function checkNode(check, context, options) {

ignoreAccessorPatternOptionSchema,
ignoreClassOptionSchema,
{

@@ -723,2 +748,3 @@ type: "object",

const defaultOptions$f = {
ignoreClass: false,
ignoreImmediateMutation: true,

@@ -905,10 +931,43 @@ assumeTypes: {

};
function getIfBranchViolations(node) {
function getIfBranchViolations(node, context) {
const branches = [node.consequent, node.alternate];
const violations = branches.filter((branch) => branch !== null &&
!isReturnStatement(branch) &&
!(isBlockStatement(branch) &&
branch.body.some((statement) => isReturnStatement(statement) ||
isIfStatement(statement))) &&
!isIfStatement(branch));
const violations = branches.filter((branch) => {
if (branch === null) {
return false;
}
if (isIfStatement(branch)) {
return false;
}
if (isReturnStatement(branch)) {
return false;
}
if (isThrowStatement(branch)) {
return false;
}
if (isExpressionStatement(branch)) {
const expressionStatementType = getTypeOfNode(branch.expression, context);
if (expressionStatementType !== null &&
isNeverType(expressionStatementType)) {
return false;
}
}
if (isBlockStatement(branch)) {
if (branch.body.some((statement) => isIfStatement(statement) ||
isReturnStatement(statement) ||
isThrowStatement(statement))) {
return false;
}
if (branch.body.some((statement) => {
if (isExpressionStatement(statement)) {
const expressionStatementType = getTypeOfNode(statement.expression, context);
return (expressionStatementType !== null &&
isNeverType(expressionStatementType));
}
return false;
})) {
return false;
}
}
return true;
});
return violations.flatMap((node) => [

@@ -918,7 +977,38 @@ { node, messageId: "incompleteBranch" },

}
function getSwitchViolations(node) {
const violations = node.cases.filter((branch) => branch.consequent.length !== 0 &&
!branch.consequent.some(isReturnStatement) &&
!(branch.consequent.every(isBlockStatement) &&
branch.consequent[branch.consequent.length - 1].body.some(isReturnStatement)));
function getSwitchViolations(node, context) {
const violations = node.cases.filter((branch) => {
if (branch.consequent.length === 0) {
return false;
}
if (branch.consequent.some((statement) => isReturnStatement(statement) || isThrowStatement(statement))) {
return false;
}
if (branch.consequent.every(isBlockStatement)) {
const lastBlock = branch.consequent[branch.consequent.length - 1];
if (lastBlock.body.some((statement) => isReturnStatement(statement) || isThrowStatement(statement))) {
return false;
}
if (lastBlock.body.some((statement) => {
if (isExpressionStatement(statement)) {
const expressionStatementType = getTypeOfNode(statement.expression, context);
return (expressionStatementType !== null &&
isNeverType(expressionStatementType));
}
return false;
})) {
return false;
}
}
if (branch.consequent.some((statement) => {
if (isExpressionStatement(statement)) {
const expressionStatementType = getTypeOfNode(statement.expression, context);
return (expressionStatementType !== null &&
isNeverType(expressionStatementType));
}
return false;
})) {
return false;
}
return true;
});
return violations.flatMap((node) => [

@@ -942,4 +1032,4 @@ { node, messageId: "incompleteBranch" },

? [{ node, messageId: "incompleteIf" }]
: getIfBranchViolations(node)
: getIfBranchViolations(node)
: getIfBranchViolations(node, context)
: getIfBranchViolations(node, context)
: [{ node, messageId: "unexpectedIf" }],

@@ -955,4 +1045,4 @@ };

? [{ node, messageId: "incompleteSwitch" }]
: getSwitchViolations(node)
: getSwitchViolations(node)
: getSwitchViolations(node, context)
: getSwitchViolations(node, context)
: [{ node, messageId: "unexpectedSwitch" }],

@@ -959,0 +1049,0 @@ };

2

package.json
{
"name": "eslint-plugin-functional",
"version": "3.2.2",
"version": "3.3.0",
"description": "ESLint rules to disable mutation and promote fp in TypeScript.",

@@ -5,0 +5,0 @@ "keywords": [

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