Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tslint-immutable

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tslint-immutable - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

CHANGELOG.md

2

package.json
{
"name": "tslint-immutable",
"version": "2.0.0",
"version": "2.1.0",
"description": "TSLint rules to disable mutation in TypeScript.",

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

@@ -31,3 +31,3 @@ # tslint-immutable

You might think that prohibiting the use of `let` and `var` would eliminate mutation from your TypeScript code. **Wrong.** Turns out that there's a pretty big loophole in `const`.
You might think that using `const` would eliminate mutation from your TypeScript code. **Wrong.** Turns out that there's a pretty big loophole in `const`.

@@ -48,3 +48,3 @@ ```TypeScript

This rule is just as effective as using Object.freeze() to prevent mutations in your Redux reducers. However this rule has **no run-time cost**, and is enforced at **compile time**. A good alternative to object mutation is to use the object spread [syntax](https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#object-spread-and-rest) that was added in typescript 2.1.
This rule is just as effective as using Object.freeze() to prevent mutations in your Redux reducers. However this rule has **no run-time cost**, and is enforced at **compile time**. A good alternative to object mutation is to use the ES2016 object spread [syntax](https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#object-spread-and-rest) that was added in typescript 2.1:

@@ -57,2 +57,13 @@ ```TypeScript

#### readonly-indexer
This rule enforces all indexers to have the readonly modifier.
```TypeScript
// NOT OK
let foo: { [key:string]: number };
// OK
let foo: { readonly [key:string]: number };
```
#### readonly-array

@@ -59,0 +70,0 @@

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -15,3 +15,3 @@ "use strict";

Rule.prototype.apply = function (sourceFile) {
var walker = new ReadonlyArrayInterfaceWalker(sourceFile, this.getOptions());
var walker = new ReadonlyArrayWalker(sourceFile, this.getOptions());
return this.applyWithWalker(walker);

@@ -23,8 +23,8 @@ };

exports.Rule = Rule;
var ReadonlyArrayInterfaceWalker = (function (_super) {
__extends(ReadonlyArrayInterfaceWalker, _super);
function ReadonlyArrayInterfaceWalker() {
var ReadonlyArrayWalker = (function (_super) {
__extends(ReadonlyArrayWalker, _super);
function ReadonlyArrayWalker() {
return _super.apply(this, arguments) || this;
}
ReadonlyArrayInterfaceWalker.prototype.visitTypeReference = function (node) {
ReadonlyArrayWalker.prototype.visitTypeReference = function (node) {
_super.prototype.visitTypeReference.call(this, node);

@@ -35,3 +35,3 @@ if (node.typeName.getText() === "Array") {

};
ReadonlyArrayInterfaceWalker.prototype.visitTypeLiteral = function (node) {
ReadonlyArrayWalker.prototype.visitTypeLiteral = function (node) {
_super.prototype.visitTypeLiteral.call(this, node);

@@ -43,3 +43,3 @@ // if (node.kind === ts.SyntaxKind.ArrayType) {

};
return ReadonlyArrayInterfaceWalker;
return ReadonlyArrayWalker;
}(Lint.RuleWalker));

@@ -20,3 +20,4 @@ "use strict";

}(Lint.Rules.AbstractRule));
Rule.FAILURE_STRING = "Only readonly members allowed in interfaces.";
Rule.FAILURE_STRING = "Interface members must have readonly modifier.";
Rule.FAILURE_STRING_ARRAY = "Interface members of array type must be ReadonlyArray.";
exports.Rule = Rule;

@@ -31,4 +32,2 @@ var ReadonlyInterfaceWalker = (function (_super) {

var member = _a[_i];
// if (!(member.flags & ts.NodeFlags.Readonly)) {
// console.log("member", member);
if (!(member.modifiers && member.modifiers.filter(function (m) { return m.kind === ts.SyntaxKind.ReadonlyKeyword; }).length > 0)) {

@@ -40,10 +39,3 @@ this.addFailure(this.createFailure(member.getStart(), member.getWidth(), Rule.FAILURE_STRING));

};
ReadonlyInterfaceWalker.prototype.visitIndexSignatureDeclaration = function (node) {
// if (!(node.flags & ts.NodeFlags.Readonly)) {
if (!(node.modifiers && node.modifiers.filter(function (m) { return m.kind & ts.ModifierFlags.Readonly; }).length > 0)) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
}
_super.prototype.visitIndexSignatureDeclaration.call(this, node);
};
return ReadonlyInterfaceWalker;
}(Lint.RuleWalker));

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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