New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-early-return

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-early-return - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

8

dist/index.js
import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils';
var version = "0.0.4";
var version = "0.0.5";

@@ -8,2 +8,5 @@ const createRule = ESLintUtils.RuleCreator((name)=>`https://github.com/hyoban/eslint-plugin-early-return/blob/main/src/rules/${name}.`);

// eslint-disable-next-line unused-imports/no-unused-imports
function isConditionRevertNeedBracket(node) {
return !(node.type === AST_NODE_TYPES.Identifier);
}
function getIndentation(node) {

@@ -41,2 +44,3 @@ return ' '.repeat(node.loc.start.column);

const condition = context.sourceCode.getText(node.test);
const revertCondition = isConditionRevertNeedBracket(node.test) ? `!(${condition})` : `!${condition}`;
let ifText = context.sourceCode.getText(node.consequent);

@@ -46,3 +50,3 @@ ifText = ifText.startsWith('{') && ifText.endsWith('}') ? ifText.replace(/^{/, '').replace(/}$/, '').replaceAll('\n ', '\n').slice(1, -1) : `${getIndentation(node)}${ifText}`;

return [
fixer.replaceText(node, `if (!(${condition})) ${elseText}\n${ifText}`)
fixer.replaceText(node, `if (${revertCondition}) ${elseText}\n${ifText}`)
];

@@ -49,0 +53,0 @@ }

{
"name": "eslint-plugin-early-return",
"type": "module",
"version": "0.0.4",
"version": "0.0.5",
"packageManager": "pnpm@8.15.3",

@@ -6,0 +6,0 @@ "description": "Prefer early return pattern to clean if else statement",

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