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

@typescript-eslint/eslint-plugin

Package Overview
Dependencies
Maintainers
2
Versions
3980
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typescript-eslint/eslint-plugin - npm Package Compare versions

Comparing version 8.21.1-alpha.8 to 8.21.1-alpha.9

59

dist/rules/prefer-readonly.js

@@ -141,2 +141,22 @@ "use strict";

}
function getTypeAnnotationForViolatingNode(node, type, initializerType) {
const annotation = checker.typeToString(type);
// verify the about-to-be-added type annotation is in-scope
if (tsutils.isTypeFlagSet(initializerType, ts.TypeFlags.EnumLiteral)) {
const scope = context.sourceCode.getScope(node);
const variable = utils_1.ASTUtils.findVariable(scope, annotation);
if (variable == null) {
return null;
}
const definition = variable.defs.find(def => def.isTypeDefinition);
if (definition == null) {
return null;
}
const definitionType = services.getTypeAtLocation(definition.node);
if (definitionType !== type) {
return null;
}
}
return annotation;
}
return {

@@ -172,2 +192,29 @@ [`${functionScopeBoundaries}:exit`](node) {

})();
const typeAnnotation = (() => {
if (esNode.type !== utils_1.AST_NODE_TYPES.PropertyDefinition) {
return null;
}
if (esNode.typeAnnotation || !esNode.value) {
return null;
}
if (nameNode.type !== utils_1.AST_NODE_TYPES.Identifier) {
return null;
}
const hasConstructorModifications = finalizedClassScope.memberHasConstructorModifications(nameNode.name);
if (!hasConstructorModifications) {
return null;
}
const violatingType = services.getTypeAtLocation(esNode);
const initializerType = services.getTypeAtLocation(esNode.value);
// if the RHS is a literal, its type would be narrowed, while the
// type of the initializer (which isn't `readonly`) would be the
// widened type
if (initializerType === violatingType) {
return null;
}
if (!tsutils.isLiteralType(initializerType)) {
return null;
}
return getTypeAnnotationForViolatingNode(esNode, violatingType, initializerType);
})();
context.report({

@@ -179,3 +226,8 @@ ...reportNodeOrLoc,

},
fix: fixer => fixer.insertTextBefore(nameNode, 'readonly '),
*fix(fixer) {
yield fixer.insertTextBefore(nameNode, 'readonly ');
if (typeAnnotation) {
yield fixer.insertTextAfter(nameNode, `: ${typeAnnotation}`);
}
},
});

@@ -216,2 +268,3 @@ }

memberVariableModifications = new Set();
memberVariableWithConstructorModifications = new Set();
privateModifiableMembers = new Map();

@@ -257,2 +310,3 @@ privateModifiableStatics = new Map();

this.constructorScopeDepth === DIRECTLY_INSIDE_CONSTRUCTOR) {
this.memberVariableWithConstructorModifications.add(node.name.text);
return;

@@ -340,3 +394,6 @@ }

}
memberHasConstructorModifications(name) {
return this.memberVariableWithConstructorModifications.has(name);
}
}
//# sourceMappingURL=prefer-readonly.js.map

14

package.json
{
"name": "@typescript-eslint/eslint-plugin",
"version": "8.21.1-alpha.8",
"version": "8.21.1-alpha.9",
"description": "TypeScript plugin for ESLint",

@@ -64,6 +64,6 @@ "files": [

"@eslint-community/regexpp": "^4.10.0",
"@typescript-eslint/scope-manager": "8.21.1-alpha.8",
"@typescript-eslint/type-utils": "8.21.1-alpha.8",
"@typescript-eslint/utils": "8.21.1-alpha.8",
"@typescript-eslint/visitor-keys": "8.21.1-alpha.8",
"@typescript-eslint/scope-manager": "8.21.1-alpha.9",
"@typescript-eslint/type-utils": "8.21.1-alpha.9",
"@typescript-eslint/utils": "8.21.1-alpha.9",
"@typescript-eslint/visitor-keys": "8.21.1-alpha.9",
"graphemer": "^1.4.0",

@@ -79,4 +79,4 @@ "ignore": "^5.3.1",

"@types/natural-compare": "*",
"@typescript-eslint/rule-schema-to-typescript-types": "8.21.1-alpha.8",
"@typescript-eslint/rule-tester": "8.21.1-alpha.8",
"@typescript-eslint/rule-schema-to-typescript-types": "8.21.1-alpha.9",
"@typescript-eslint/rule-tester": "8.21.1-alpha.9",
"ajv": "^6.12.6",

@@ -83,0 +83,0 @@ "cross-env": "^7.0.3",

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