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

tslint-immutable

Package Overview
Dependencies
Maintainers
2
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 5.4.0 to 5.5.0

4

CHANGELOG.md

@@ -10,2 +10,6 @@ # Change Log

## [v5.5.0] - 2019-03-21
* readonly-array rule now allows for the readonly keyword to specify an array as readonly. This is a new feature supported in TypeScript 3.4. See [#129](https://github.com/jonaskello/tslint-immutable/issues/129). See PR [#130](https://github.com/jonaskello/tslint-immutable/pull/130)
## [v5.4.0] - 2019-03-14

@@ -12,0 +16,0 @@

37

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

@@ -26,2 +26,11 @@ "main": "tslint-immutable.json",

"homepage": "https://github.com/jonaskello/tslint-immutable#readme",
"files": [
"/rules",
"tslint-immutable.json",
"all.json",
"package.json",
"CHANGELOG.md",
"LICENSE",
"README.md"
],
"dependencies": {

@@ -31,13 +40,17 @@ "tsutils": "^2.28.0 || ^3.0.0"

"devDependencies": {
"@types/glob": "^7.1.1",
"@types/node": "^8.0.53",
"codecov": "^3.1.0",
"husky": "^0.14.3",
"lint-staged": "^5.0.0",
"nyc": "^11.2.1",
"prettier": "^1.12.1",
"rimraf": "^2.6.2",
"shelljs": "^0.7.5",
"tslint": "^5.8.0",
"tslint-plugin-prettier": "^1.3.0",
"typescript": "^3.0.0"
"codecov": "^3.2.0",
"compare-versions": "^3.4.0",
"glob": "^7.1.3",
"husky": "^1.3.1",
"lint-staged": "^8.1.5",
"nyc": "^13.3.0",
"object.entries": "^1.1.0",
"prettier": "^1.16.4",
"rimraf": "^2.6.3",
"shelljs": "^0.8.3",
"tslint": "^5.14.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.4.0-rc"
},

@@ -51,3 +64,3 @@ "peerDependencies": {

"build": "rimraf rules && yarn compile",
"lint": "tslint './src/**/*.ts{,x}'",
"lint": "tslint './{src,scripts}/**/*.ts{,x}'",
"test": "tslint --test test/rules/**/*",

@@ -54,0 +67,0 @@ "test:work": "yarn build && tslint --test test/rules/readonly-array/work",

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

This rule enforces use of `ReadonlyArray<T>` instead of `Array<T>` or `T[]`.
This rule enforces use of `ReadonlyArray<T>` or `readonly T[]` instead of `Array<T>` or `T[]`.

@@ -155,3 +155,3 @@ Below is some information about the `ReadonlyArray<T>` type and the benefits of using it:

Using the `ReadonlyArray<T>` type will stop this mutation:
Using the `ReadonlyArray<T>` type or `readonly T[]` will stop this mutation:

@@ -163,3 +163,6 @@ ```typescript

}
const points: ReadonlyArray<Point> = [{ x: 23, y: 44 }];
// const points: readonly Point[] = [{ x: 23, y: 44 }]; // This is the alternative syntax for the line above
points.push({ x: 1, y: 2 }); // Unresolved method push()

@@ -166,0 +169,0 @@ ```

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ts = require("typescript");
var Lint = require("tslint");

@@ -12,3 +13,3 @@ var utils = require("tsutils/typeguard/2.8");

return {
invalidNodes: checkArrayType(node, ctx).concat(checkTypeReference(node, ctx), checkImplicitType(node, ctx))
invalidNodes: checkArrayType(node, ctx).concat(checkTypeReference(node, ctx), checkImplicitType(node, ctx), checkTupleType(node, ctx))
};

@@ -19,3 +20,9 @@ }

if (utils.isArrayTypeNode(node)) {
// Ignore arrays decleared with readonly keyword.
if (node.parent &&
utils.isTypeOperatorNode(node.parent) &&
node.parent.operator === ts.SyntaxKind.ReadonlyKeyword) {
return [];
}
if (node.parent &&
Ignore.shouldIgnorePrefix(node.parent, ctx.options, ctx.sourceFile)) {

@@ -33,7 +40,9 @@ return [];

}
var _a = ts.version
.split(".")
.map(function (n) { return Number.parseInt(n, 10); }), major = _a[0], minor = _a[1];
return [
check_node_1.createInvalidNode(node, [
new Lint.Replacement(node.getStart(ctx.sourceFile), 0, "ReadonlyArray<"),
new Lint.Replacement(node.end - 2, 2, ">")
])
check_node_1.createInvalidNode(node, major > 3 || (major === 3 && minor >= 4)
? getReadonlyKeywordFix(node, ctx)
: getReadonlyArrayFix(node, ctx))
];

@@ -92,2 +101,34 @@ }

}
function checkTupleType(node, ctx) {
var _a = ts.version.split(".").map(function (n) { return Number.parseInt(n, 10); }), major = _a[0], minor = _a[1];
// Only applies to ts 3.4 and newer.
if (major > 3 || (major === 3 && minor >= 4)) {
if (utils.isTupleTypeNode(node)) {
// Ignore arrays decleared with readonly keyword.
if (node.parent &&
utils.isTypeOperatorNode(node.parent) &&
node.parent.operator === ts.SyntaxKind.ReadonlyKeyword) {
return [];
}
return [check_node_1.createInvalidNode(node, getReadonlyKeywordFix(node, ctx))];
}
}
return [];
}
function getReadonlyKeywordFix(node, ctx) {
// Nested shorthand syntax array?
if (utils.isArrayTypeNode(node.parent)) {
return [
new Lint.Replacement(node.getStart(ctx.sourceFile), 0, "(readonly "),
new Lint.Replacement(node.end, 0, ")")
];
}
return [new Lint.Replacement(node.getStart(ctx.sourceFile), 0, "readonly ")];
}
function getReadonlyArrayFix(node, ctx) {
return [
new Lint.Replacement(node.getStart(ctx.sourceFile), 0, "ReadonlyArray<"),
new Lint.Replacement(node.end - 2, 2, ">")
];
}
//# sourceMappingURL=readonlyArrayRule.js.map

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

return extendStatics(d, b);
}
};
return function (d, b) {

@@ -17,0 +17,0 @@ extendStatics(d, b);

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