Socket
Socket
Sign inDemoInstall

@stylistic/eslint-plugin-ts

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stylistic/eslint-plugin-ts - npm Package Compare versions

Comparing version 2.6.4 to 2.6.5

42

dist/type-annotation-spacing.js
'use strict';
var astUtils = require('@typescript-eslint/utils/ast-utils');
var utils$1 = require('@typescript-eslint/utils');
var utils = require('./utils.js');

@@ -23,2 +24,7 @@ require('@stylistic/eslint-plugin-js');

};
const operator = {
...{ before: true, after: true },
...globals,
...override?.operator
};
return {

@@ -30,3 +36,4 @@ colon,

parameter: { ...colon, ...override?.parameter },
returnType: { ...colon, ...override?.returnType }
returnType: { ...colon, ...override?.returnType },
operator
};

@@ -43,2 +50,4 @@ }

function getRules(rules, node) {
if ([utils$1.AST_NODE_TYPES.TSAsExpression, utils$1.AST_NODE_TYPES.TSSatisfiesExpression].includes(node?.parent?.type))
return rules.operator;
const scope = node?.parent?.parent;

@@ -95,3 +104,4 @@ if (astUtils.isTSFunctionType(scope) || astUtils.isTSConstructorType(scope))

property: { $ref: "#/items/0/$defs/spacingConfig" },
returnType: { $ref: "#/items/0/$defs/spacingConfig" }
returnType: { $ref: "#/items/0/$defs/spacingConfig" },
operator: { $ref: "#/items/0/$defs/spacingConfig" }
},

@@ -112,11 +122,13 @@ additionalProperties: false

const punctuators = [":", "=>"];
const operator = ["as", "satisfies"];
const sourceCode = context.sourceCode;
const ruleSet = createRules(options);
function checkTypeAnnotationSpacing(typeAnnotation) {
const nextToken = typeAnnotation;
const punctuatorTokenEnd = sourceCode.getTokenBefore(nextToken);
const nextNode = typeAnnotation;
const punctuatorTokenEnd = sourceCode.getTokenBefore(nextNode);
let punctuatorTokenStart = punctuatorTokenEnd;
let previousToken = sourceCode.getTokenBefore(punctuatorTokenEnd);
let type = punctuatorTokenEnd.value;
if (!punctuators.includes(type))
const isOperator = operator.includes(type);
if (!punctuators.includes(type) && !isOperator)
return;

@@ -154,4 +166,6 @@ const { before, after } = getRules(ruleSet, typeAnnotation);

const previousDelta = punctuatorTokenStart.range[0] - previousToken.range[1];
const nextDelta = nextToken.range[0] - punctuatorTokenEnd.range[1];
if (after && nextDelta === 0) {
const nextDelta = nextNode.range[0] - punctuatorTokenEnd.range[1];
const ignoreBefore = isOperator && ![utils$1.AST_TOKEN_TYPES.String, utils$1.AST_TOKEN_TYPES.Template, utils$1.AST_TOKEN_TYPES.Punctuator].includes(previousToken.type);
const ignoreAfter = isOperator && nextNode.type !== utils$1.AST_NODE_TYPES.TSTypeLiteral;
if (after && nextDelta === 0 && !ignoreAfter) {
context.report({

@@ -167,3 +181,3 @@ node: punctuatorTokenEnd,

});
} else if (!after && nextDelta > 0) {
} else if (!after && nextDelta > 0 && !ignoreAfter) {
context.report({

@@ -178,3 +192,3 @@ node: punctuatorTokenEnd,

punctuatorTokenEnd.range[1],
nextToken.range[0]
nextNode.range[0]
]);

@@ -184,3 +198,3 @@ }

}
if (before && previousDelta === 0) {
if (before && previousDelta === 0 && !ignoreBefore) {
context.report({

@@ -196,3 +210,3 @@ node: punctuatorTokenStart,

});
} else if (!before && previousDelta > 0) {
} else if (!before && previousDelta > 0 && !ignoreBefore) {
context.report({

@@ -220,2 +234,8 @@ node: punctuatorTokenStart,

checkTypeAnnotationSpacing(node.typeAnnotation);
},
TSAsExpression(node) {
checkTypeAnnotationSpacing(node.typeAnnotation);
},
TSSatisfiesExpression(node) {
checkTypeAnnotationSpacing(node.typeAnnotation);
}

@@ -222,0 +242,0 @@ };

{
"name": "@stylistic/eslint-plugin-ts",
"type": "commonjs",
"version": "2.6.4",
"version": "2.6.5",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",

@@ -69,4 +69,4 @@ "license": "MIT",

"@types/eslint": "^9.6.0",
"@typescript-eslint/utils": "^8.1.0",
"@stylistic/eslint-plugin-js": "2.6.4"
"@typescript-eslint/utils": "^8.3.0",
"@stylistic/eslint-plugin-js": "2.6.5"
},

@@ -73,0 +73,0 @@ "scripts": {

/* GENERATED, DO NOT EDIT DIRECTLY */
/* @checksum: xBBXh1Kir2 */
/* @checksum: 4pLfcIWfUw */

@@ -15,2 +15,3 @@ export interface Schema0 {

returnType?: SpacingConfig
operator?: SpacingConfig
}

@@ -17,0 +18,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